restart application without restarting server?
Asked Answered
F

8

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.

Ferri answered 25/6, 2010 at 15:10 Comment(0)
G
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.

Getter answered 25/6, 2010 at 15:37 Comment(0)
E
21

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

Eugine answered 25/6, 2010 at 17:1 Comment(1)
This is the only 'correct' solution (and you have to be on CF9). Everything else is a dubious workaround with potential thread safety issues.Flannelette
C
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/

Crammer answered 30/6, 2010 at 12:6 Comment(0)
U
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.

Unfurl answered 28/6, 2012 at 15:16 Comment(0)
A
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.

Amenity answered 16/1, 2013 at 15:33 Comment(0)
P
2
<cfset structClear(application) /> 
Poultice answered 25/6, 2010 at 17:31 Comment(1)
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.Getter
T
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. ;)

Thalweg answered 25/6, 2010 at 15:43 Comment(0)
T
0

Use cfinvoke.

<cfinvoke method="onApplicationEnd" component="Application">
    <cfinvokeargument name="ApplicationScope" value="#application#" />
</cfinvoke>
Thornberry answered 25/6, 2010 at 17:55 Comment(1)
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.Flannelette

© 2022 - 2024 — McMap. All rights reserved.