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?
earwig75Asked:
Who is Participating?
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.

dgrafxCommented:
<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.
0
earwig75Author Commented:
I'm confused. I can't put this on a normal cfm page?
0
dgrafxCommented:
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 ...
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

dgrafxCommented:
>>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()
</cffunction>

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

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 ...
0

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?
0
dgrafxCommented:
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.
0
earwig75Author Commented:
What code would I put into the Function to restart the application?
0
dgrafxCommented:
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.
0
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.
0
dgrafxCommented:
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 />
</cffunction>

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()>                  
      </cfif>            
            
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.
      --->
      
</cffunction>

How are you setting your Application vars now?
An example would help me advise ...
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.