How does one check if a init.d script is working

init.d

I've had the displeasure of bitterly realizing that (after a few days) upon rebooting of my system, that init.d scripts written by myself were not executed. This caused a bit of problems, but I think I've fixed it.

So now, I would like write up a script in which I will install to the crontab that will check if the init.d scripts are working or not.

Q: How does one check if init.d scripts are working? Or see a list of the init.d scripts working?


The Idea: Check if the init.d scripts are running, if not, send out an email, to notify myself, that for some reason the init.d script has failed.


Best Answer

You can't generically tell whether an init script was executed from a cron job. You'd have to look for some side effect of the init script, and cron is pointless for that. Make your init script emit a log message.

If you want to make sure that a service is running, use a monitoring mechanism (possibly network-based if the service is offered over the network). This isn't about whether the init script ran, that's just one fairly unlikely failure mode. It's about making sure that the service is available when needed.

How to execute a script when the system starts depends on which init system is in use. Since there are many alternatives (even on Linux, and sometimes even on the same release of the same distribution), check the documentation of your operating system to see how to make an init script run. Note that with most of them, it isn't enough to drop a shell script in a directory somewhere, you also need to add some control information somewhere (in a configuration file, a symbolic link, as a comment in the script, …).

Related Question