Copy link to clipboard
Copied
We have application on our server that we are unable to reload or restart when we make changes to the code. We use the URL parameter which does not work with all applications, we try to flush the cache (templates and CFC) in CF administrator page wihc does not quite works. The only thing that works is to restart the actual coldfusion OS service. Is there any tricks that will force the application to restart or reload?
CF2021/Linux Centos 7.8
Copy link to clipboard
Copied
Dejank, there can be several things at issue here. But since you say you've used the admin to clear the template and component caches, we'll assume we need not speak of things like the "trusted cache" option (on that same page in the CF Admin). Otherwise, I wonder if you are storing CFCs in a shared scope, like application, session, or server. If so, that takes special handling.
First we should ask what "url parameter" you were trying to use that "does not work with all applications"? I ask because there is no such url parameter that works for "all cf apps" that I know of.
Instead, some people write code (such as in their application.cfc or cfm) which WATCHES for some sort of such "init" or "reset" sort of url variable and that they have that code trigger whatever they think will "reload" the app. Even that can mean different things to different people/apps.
One option is to call the built-in CFML function, applicationStop(). What that does is "stop" the app, such that then the next request which comes in will inherently trigger a reload of the "application" before that request, to include CF re-running the onapplicationstart method of an Application.cfc. Such a new request would reset the application scope, though not the session scope (so it WOULD clear any CFCs stored in the application scope, and any next instantion of that CFC would detect changes to that CFC).
Others have such "reset" code call the onapplicationstart method of their application.cfc, which is not only not needed (if you do the above) but it's unwise: again, CF WILL call that on the next request that happens...and CF will also implicitly single-thread calls to that method, which does NOT happen if your code calls the method directly.
But again even that call to applicationstop() function will only cause removal of the application scope (and CFC instances stored there), but it would not affect the session (or server) scope. If you have stored CFC instances in those, then to get them to reload, you'd need to either clear the scope entirely (using structclear, which will clear the ENTIRE scope) or you could remove JUST the CFC from the scope--if you knew the name of the var/s holding the instance (using structdelete, naming the scope and the variable). Any next request which would call code to re-instantiate the CFC WOULD then pick up any changes made to the CFC. And this is sometimes the kind of code people put into suh "init" code as discussed above.
But beware of a couple things: first, there could be an issue if between the time of clearing a scope and next loading a CFC into it, some other request which only tries to USE the CFC instance but not RELOAD it would fail now that it's gone. And note also that there's no way (I know of) to clear/modify the session scopes for ALL users of an app, so you can't in any single step force reloading of such a changed CFC across all sessions, like you can with app or server scope.
If these things don't work for you, please do share more detail about what kind of code you're changing (cfc or cfm files), and whether any aspect of it is in any way connected to the startup of the application, and perhaps whether you know that the CFCs are (or are not) being loaded into any shared scope. Or maybe others will have better questions for you, if not solutions.
Copy link to clipboard
Copied
Trusted check box is unchecked.
I'm changing/updating the CFC files and changes to those file do not seems to apply. Changes to CFM files do get reloaded.
We pass in URL parameters within the application, ex. httpd://....index.cfm?rebootme=yes. The OnRequestStart() method checks for those params and if they are present it calls the method OnApplicationStart(). I inherited this setup so I assumed that is how its done.
I did not realize applicationStop() is prefered, I will definitelly try this.
I'll follow up if I encounter issues.
Thank you so much!
Copy link to clipboard
Copied
Thanks for the update, Dejank. You've not yet clearified whether you are storing these CFC instances in a shared scope (like application, server, or session). My guess is that you'd find you are. That would explain why the changes were not picked up (given what else you shared). And yep, that call to onapplicationstart won't necessarily help. It depends on what you do in there, as I discussed above.
Also, I have tweaked my previous reply to add a bit more about trying to handle if the CFC instances are saved in the server or session scope instead. See especially the 2 paragraph before the last one.
Copy link to clipboard
Copied
I usually restart a ColdFusion application by changing the value of this.name in the Application.cfc file.
For me, that is usually as simple as adding one character. For example, by changing
<cfset this.name = "MyApp">
to
<cfset this.name = "MyApp2">
After you do that, the next request will restart the application, under the new name, MyApp2.
Copy link to clipboard
Copied
Yep, picking a new name for an app will indeed create a new app, which 8s another option.
We should not say that will RESTART the app, though: if you pick a name that matches a name you'd used previously (and it's not timed out, for the default of 2 days), then that previous app's state would just be loaded instead.
Still, your suggestion could be used to EFFECT the equivalent of a restart, sure, as long as one aware of this. 🙂 Just sharing for the sake of completeness, for Dejank and others following along.