How to reinit ColdFusion 10

I have found a couple different methods for restarting / "reinit" a coldfusion application but I am always worried about using them in a shared hosting environment. Does anyone have a reliable, easy to understand method for restarting all CF instances/reinitialization of an application?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

<cfset onApplicationStart()>
It's as simple as that!
This will restart this application - it will not affect any other application on the server.
This line of code might be placed on a page that is called when you click on a link titled "Reset this Application" for example.

Note though that any code that is used to reinit the application needs to be placed or called from within your onApplicationStart method - usually located in your Application.cfc file.
earwig75Author Commented:
I'm confused. I can't put this on a normal cfm page?
There are two different things that I spoke of.
the function can go on a CFM page but typically is in a CFC.
And yes the cfset onApplicionStart() code can certainly go on a cfm page.
I think you're imagining it being more difficult than it really is.
It is very very simple - dont over think it ...
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

>>Note though that any code that is used to reinit the application needs to be placed or called from within your onApplicationStart method - usually located in your Application.cfc file<<

Are you using an Application.cfc file?
If so you probably have an onApplicationStart function such as:
<cffunction name="onApplicationStart" output="false">
Whatever you have in here will run whenever your Application starts or you call onApplicationStart()

So you can try it out like so - this goes in Application.cfc - remove your existing onApplicationStart function:
<cffunction name="onApplicationStart">
<cfmail from="" to="" subject="Success">
Mail has been sent because Application reinit has been called ...

1. supply proper cfmail settings so it will send you an email
2. place the following on a cfm page named test.cfm: <cfset onApplicationStart()>
3. navigate to test.cfm and you will get the email

Note now that whatever you put inside your onApplicationStart function will run - resetting Application vars is the most common use.

good luck ...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
earwig75Author Commented:
Thank you, does this restart all coldfusion instances running on a server if there is more than one?
What do you mean by different ColdFusion Instances?
Do you mean different Applications or Websites?
<cfset onApplicationStart()> will call the function onApplicationStart in the application that it is called in only.
You of course wouldn't expect to receive the email (in the above example) if you copied the above test.cfm file to a different website on the same server - right?
This isn't a server function - it's an application function.
earwig75Author Commented:
What code would I put into the Function to restart the application?
ok - well what do you mean by restart the application?
i.e. what are you trying to achieve?
if you can tell me what you are wanting to achieve I can try to describe what I would do.
earwig75Author Commented:
I am new to this so I apologize if I am not explaining it well. Sometimes when I make changes to the application, even though the code has changed in "production", the old code still runs.
OK - you want to reset Application vars ...

If you don't already have one put this onRequestStart function in your Application.cfc
<cffunction name="onRequestStart">

      <cfreturn />

Then put this code within it:
      <cfparam name="Url.resetApp" default="">
      <cfif Url.resetApp is 453791> <!--- This is so that only those who know this "code" can reset the app --->
            <cfset ApplicationStop()>                  
Note that I'm using ApplicationStop() which destroys all your Application vars.
The onApplicationStart function will then be called.
If you don't want to destroy your existing Application variables then use <cfset onApplicationStart()> instead which will reload your vars but will not destroy the entire Application scope first. For example if you are setting any Application vars outside the onApplicationStart function might be a consideration for which you want to use.

So here is an example onApplicationStart function:
<cffunction name="onApplicationStart">            
      <cfset Application.myFavoriteColor="Blue" />
      <cfset Application.myFavoriteNumber=314 />
      <cfset Application.misc = New cfcs.misc() />
      note that this refers to a file named misc.cfc that is in a root folder named cfcs.
      that is off topic of this answer but just fyi as to how App vars can be set.
      <cfinclude template="/files/somefile.cfm">
      and also you will probably see code like this as well. In the file somefile.cfm will be code to set App vars.
      having said that make sure you don't choke your onApplicationStart function with crap that makes your Application take forever to load.

How are you setting your Application vars now?
An example would help me advise ...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.