tags:

views:

188

answers:

8

Is there a way to restart a coldfusion application without starting the entire server?

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

+3  A: 

if you do:

<cfset structClear(application) />

From the application you want to restart, all variables will be reset, and re-created as soon as you hit the application again.

Let me know if that's what you need.

Cheers

Marcos Placona
wow, is this true? cool, I'll have to try this.
Henry
This can have unexpected side effects, it's not recommended if you have access to onApplicationStart/Stop. Same goes for clearing the session with structClear()
David Collie
+9  A: 

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
A: 

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
+7  A: 

If you're on CF9, run ApplicationStop() http://www.cfquickdocs.com/cf9/#applicationstop

Henry
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
Is this how you get so many points Henry? Post a question and answer it yourself? I'm on to you :)
Aaron Greenlee
LOL, I didn't ask this question. I just reworded it from 'start' to 'restart'.
Henry
A: 
<cfset structClear(application) /> 
Minnoo
where's the answer?
Henry
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
A: 

Use cfinvoke.

<cfinvoke method="onApplicationEnd" component="Application">
    <cfinvokeargument name="ApplicationScope" value="#application#" />
</cfinvoke>
Pedro Claudio
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
+2  A: 

RT @misterdai

I have a blog post about it, a CF7/8 version of ApplicationStop() and ApplicationRestart()

http://misterdai.wordpress.com/2010/06/14/cf-flag-application-to-run-onapplicationstart-part-2/

Henry
+2  A: 

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