Orange is my favorite color

I was reading about reinit troubles on the Coldspring users mailing list today. It made me think this might be an interesting meme to see how many ways people restart their applications.

My Routine

I run a Model-Glue, Coldspring and Transfer application. Here’s how I restart my application:

<!-- see if we should restart the application? -->
<cfif structKeyExists(URL, "mySecretReinitFlag") AND URL.mySecretReinitFlag EQ "mySecretPassword">
<cfset msg = "Full init called" />
<!-- onError will catch the message and tell us -->
<cflock scope="session" type="exclusive" timeout="5">
<!-- clear out session -->
<cfset structDelete(session, "scope", false) />
<cfset msg = listAppend(msg, "Session scope cleared") />
</cflock>
<cflock scope="application" type="exclusive" timeout="25">
<!--- log into coldfusion admin --->
<cfinvoke component="cfide.adminapi.administrator" method="login">
<cfinvokeargument name="adminPassword" value="myAdminPassword" />
</cfinvoke>
<!--- clear template cache (BROKEN ON CF8 multi-server) --->
<cftry>
<cfinvoke component="cfide.adminapi.runtime" method="clearTrustedCache" />
<cfset msg = listAppend(msg, "Cleared Trusted Cache") />
<cfcatch type="any">
<cfset msg = listAppend(msg, "FAILED to clear Trusted Cache") />
</cfcatch>
</cftry>
<!--- flush transfer cache to catch any api changes --->
<cfif structKeyExists(application, "cs")>
<cfset tr = application.cs.getBean('ormService').getTransfer() />
<cfset tr.discardAll() />
<cfset msg = listAppend(msg, "Transfer cache cleared") />
<cfelse>
<cfset msg = listAppend(msg, "Coldspring NOT restarted (error!)") />
</cfif>
<!--- clear out coldspring --->
<cfset structDelete(application, "cs", false) />
<cfset msg = listAppend(msg, "Coldspring deleted") />
<!--- restart app as if it's first load --->
<cfset onApplicationStart() />
<cfset msg = listAppend(msg, "onApplicationStart fired") />
<!--- update all Model-Glue apps to use new reference to BeanFactory --->
<cfif structKeyExists(application, "mysite")>
<cfset msg = listAppend(msg, "Updated mysite") />
<cfset application.mysite.framework.setBeanFactory(application.cs) />
</cfif>
<cfif structKeyExists(application, "staff")>
<cfset msg = listAppend(msg, "Updated staff") />
<cfset application.staff.framework.setBeanFactory(application.cs) />
</cfif>
</cflock>
<cfif structKeyExists(application, "cs")>
<cfset ss = application.cs.getBean('sessionService') />
<cfset ss.getInstance(flush = true) />
<cfset msg = listAppend(msg, "Session flushed") />
<!--- display results of reinit to calling user thru messageService --->
<cfset ss.getMessaging().addWarning(msg) />
</cfif>
</cfif>

How do you restart your application? Got a trick or tip? Use <code> tags in the comments to share or link it up to your own blog!

3 Comments

  1. Andrew said:

    on October 15, 2008 at 12:59 pm

    I was under the impression the onApplicationStart() is only single-threaded when run from Application.cfc directly, and thus had to be locked when called from outside? If so, then you ought to lock it here, and if not – nice job!

  2. brian said:

    on October 15, 2008 at 1:56 pm

    @Andrew – you’re absolutely right, but it is already inside of a CFLOCK. :)

  3. Andrew said:

    on October 15, 2008 at 10:23 pm

    doh! sorry

{ RSS feed for comments on this post}