I spoke with Hemant at CFUNITED about onServerStart and what should happen if something goes wrong in the method. Currently if an error occurs, it gets logged, but the server just carries on. I made the argument that the server should stop loading as something has gone wrong. I also made the argument that it should act like onApplicationStart - where if you intentionally return false, the application will not load.
After speaking with Adam Lehman though, I think he had a good counterpoint. (Oh, and my idea was shut down, so it's not changing in the final release. ;) First, Adam made the point that ColdFusion should always try to start. Fair point. He then made another suggestion which I thought was good. If we check something, like a datasource, and are unable to connect, then it may make more sense to simply use a server variable as a flag. Our applications could then check that flag in onApplicationStart and react accordingly.
I have to say - I didn't really think I'd make much use of onServerStart, but I think I came up with a pretty good use case. If you host your ColdFusion site on a VPS and want to get a notice when the service restarts (in case you aren't the one doing it!) then this simple example will handle that:
component {
public function onServerStart() {
writeLog(file="myserver",text="Server starting up.");
myMail = new mail(to="ray@camdenfamily.com", from="ray@camdenfamily.com", subject="Server started", body="The server has started. Woot");
myMail.send();
}
}
Normally I check the server.log file when I'm worried about my ColdFusion service restarting, but this would be a more in your face type approach.
Does anyone else have any plans for this feature?
Archived Comments
yeah - I gotta agree with adam/adobe on that one - the server should always start.
one use case - adding the server dynamically to load balancer pools when it starts.
Is this a cf9 function?
@MikeP: Yes.
We have other servers which may need to know if the CF server has started back up. For instance, we have an external credit card system that lets people pay their insurance bills online, that system can really only work if the coldfusion server for the insurance system is up and running. Currently we poll a heart beat service, but I suppose we could use the startup feature to send notice to the payment system that it is back in business.
We use this feature to define several server variables (datasource names, address of other systems to link to, etc), so we can move our apps between production, test, and development regions seemlessly. It has been very useful.
I always thought it was interesting, but never something that would solve a problem that I am currently experiencing.
Hi Ray
I think you're probably aware of my thoughts on this (via another channel), but I think there's use-cases for both notions that either the onServerStart handler is "fire and forget" (as it is) or "halt if it doesn't run". However the way it currently is allows one to emulate the latter easily enough by setting SERVER.bStartedOk as the last step of the handler. Slightly hokey, but enables both approaches.
My only use-case (so far) for onServerStart is to email me when it runs. Purely because of the implication that if the server has just started... it must have stopped recently. That's actually very important info to know, so just that by itself is enough validation for the functionality in my view.
--
Adam
Yeah - you know, the more I think of it, the more I think I'll definitely put an email me cfc on this server itself (I'm running 9 here).