i have a webserver that has been crashing a bunch lately… while i’m working with my unix techie friends trying to figure it out, it would be really helpful for me to have a script that could monitor the services on my remote server (apache, mysql and spamassassin in particular) and to restart them when they crash.
does anyone have an existing script that does this or could anyone give me some directions for creating one?
i’ve never written an applescript before but i can hack my way through this sort of stuff decently…
Something like this, perhaps. First it checks to see if the machine is answering pings, and then if the server is up, displays a message that dismisses itself in 10 seconds. It’s set up as an “on idle” handler - this has to be saved as a stay-open application and it will run every 5 minutes as set up. It’s not optimized in any way - I just cobbled it together, but I did test it.
on idle
-- check if the machine is running and answering pings
set msg to ""
set Png to ""
set add to "192.168.1.101"
try
-- this takes a while if the machine is down
set Png to do shell script "ping -c 1 " & add
on error
set p to number of paragraphs in Png
if p < 5 then set msg to "Not answering pings" & return
end try
-- check if the server is running
try
set S to do shell script "curl http://" & add
on error
set msg to msg & "Host down"
end try
display dialog msg giving up after 10
return 5 * minutes
end idle
you don’t mention the webserver’s OS, but if it is also OS X (or really, just about any UNIX-like OS) then you might try Nagios. here is a link on how to set up Nagios on OS X:
If you don’t mind buying something I’d consider Kick-Off. There are versions for Mac and Windows and Red Hat Linux, provided the machine has a USB port. Detects crashes and will monitor an application. Not a casual purchase at $179, but I used its predecessor (the ADB bus Rebound!) reliably for many years to monitor a pre-X server running Quid Pro Quo.