23

Is there a way to restart a ColdFusion application without restarting the entire server?

There are two ColdFusion applications running on a server and I only want to restart one of them.

James Cushing
  • 718
  • 1
  • 9
  • 18
dmr
  • 21,811
  • 37
  • 100
  • 138

8 Answers8

21

If you are using Application.cfc, you can update it so that you can force a call to onApplicationStart() if something specific is passed in the url, or something similar. Simply place a check for that magic token in onRequestStart(), and call onApplicationStart() if it is.

If you are not, you can try @Marcos's suggestion. I'm not sure what ramifications that may have in your application. What I would suggest is actually renaming your application, so it starts as a new app.

Ben Doom
  • 7,865
  • 1
  • 27
  • 30
21

If you're on CF9, run ApplicationStop() https://cfdocs.org/applicationstop

Henry
  • 32,689
  • 19
  • 120
  • 221
  • 6
    This is the only 'correct' solution (and you have to be on CF9). Everything else is a dubious workaround with potential thread safety issues. – Sean Corfield Jun 25 '10 at 22:34
4

A less invasive way of ending your app is to temporarily set the ApplicationTimeout to something very short.

Here is an example from an application.cfc file where the app is set to timeout in 10 seconds, which is plenty short for making a change and then checking back:

<cfcomponent displayname="Application">
    <cfscript>
        this.name = "myAppName";
        this.setclientcookies="yes";
        this.sessionmanagement="yes";
        this.sessiontimeout= CreateTimeSpan(0,0,60,0);
        this.applicationTimeout= CreateTimeSpan(0,0,0,10);
    </cfscript>
    ...
</cfcomponent>

You might need to limit the session, too. See this article by Ben Nadel for an in-depth look at Application and Session timeouts.

Leigh
  • 28,765
  • 10
  • 55
  • 103
gkl
  • 199
  • 2
  • 11
4

If you are using application.cfc, stick this at the top of your onRequestStart function:

<!--- RESET APP? --->
<cfif isdefined("url.reinit")>
    <cfset OnApplicationStart()>
    <cfset OnSessionStart()>
</cfif>

Then you can pass a url var to any cfm and the app will reset.

Jules
  • 1,941
  • 15
  • 18
4

Here you go, my CF7/8 version of CF9's ApplicationStop. I believe this is thread safe, noting Sean's comment.

<cffunction name="ApplicationStop" returntype="boolean" output="false">
 <cfif IsDefined('application')>
   <cftry>
     <!--- This is just in case there's no app scope but variables.application --->
     <cfset CreateObject('java', 'coldfusion.runtime.ApplicationScopeTracker').cleanUp(application) />
     <cfreturn true />
     <cfcatch type="any"></cfcatch>
   </cftry>
 </cfif>
 <cfreturn false />
</cffunction>

As mentioned by Henry, he's my blog post on the subject: http://misterdai.wordpress.com/2010/06/14/cf-flag-application-to-run-onapplicationstart-part-2/

Mister Dai
  • 796
  • 1
  • 6
  • 19
2
<cfset structClear(application) /> 
Ben Doom
  • 7,865
  • 1
  • 27
  • 30
Minnoo
  • 85
  • 3
  • Made suggestion visible. :-\ Use the preview. Also, that suggestion had already been given. If you agree, vote that suggestion up. Don't re-submit it. – Ben Doom Jun 25 '10 at 20:54
0

I usually put a reference to each user's session into a struct in my Application scope to monitor what's going on in the app. Maybe doing something similar in the Server scope could help here. Try:

<cfset server.runningApplications["myApp"] = Application />

Then you'd have a reference to the actual Application object outside the scope of that application. You could try all manner of destructive things to get rid of it. Try this at your own risk!!! And do it on a dev server before you do it on your production box. ;)

bpanulla
  • 2,988
  • 1
  • 19
  • 23
0

Use cfinvoke.

<cfinvoke method="onApplicationEnd" component="Application">
    <cfinvokeargument name="ApplicationScope" value="#application#" />
</cfinvoke>
Henry
  • 32,689
  • 19
  • 120
  • 221
  • 2
    I don't think running onApplicationEnd() will do anything useful in terms of causing an application to restart. On CF8 / CFMX7, calling onApplicationStart() is the closest you'll get to the behavior you want - but beware that it won't be thread safe: CF automatically single threads calls to onApplicationStart() WHEN IT CALLS IT but you can't do that when you call it. On CF9, applicationStop() is the correct way to do this. – Sean Corfield Jun 25 '10 at 22:33