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:
2
3 public function onServerStart() {
4
5 writeLog(file="myserver",text="Server starting up.");
6 myMail = new mail(to="ray@camdenfamily.com", from="ray@camdenfamily.com", subject="Server started", body="The server has started. Woot");
7 myMail.send();
8
9 }
10
11 }
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?


Comment 1 written by Scott P on 19 August 2009, at 3:48 PM
one use case - adding the server dynamically to load balancer pools when it starts.
Comment 2 written by Mike P on 19 August 2009, at 4:27 PM
Comment 3 written by Raymond Camden on 19 August 2009, at 4:29 PM
Comment 4 written by Tim Cunningham on 19 August 2009, at 4:33 PM
Comment 5 written by JV on 20 August 2009, at 7:22 AM
Comment 6 written by Ben Nadel on 20 August 2009, at 12:48 PM
Comment 7 written by Adam Cameron on 21 August 2009, at 12:21 PM
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
Comment 8 written by Raymond Camden on 21 August 2009, at 12:23 PM
[Add Comment] [Subscribe to Comments]