monit
is great in this case - it runs on localhost, so you don't need a network connection to restart your daemon (in case it fails, or daemon is responsible for networking). It also has small footprint on the system, and you can use it to monitor your other daemons/disk space/etc. as well.
Create a start/stop script (similar to those in /etc/init.d/
and create symlinks for it in runlevels that your system uses for normal operation, ensuring that your daemon will start at reboot and stop at shutdown properly. If your daemon doesn't have pidfile, create one using start-stop-daemon
script.
After that, install monit
and create configuration for your daemon, something like this:
check process daemond with pidfile /var/run/daemond.pid
start program "/etc/init.d/daemond start"
stop program "/etc/init.d/daemond stop"
if failed port 1234 type TCP for 5 times within 10 cycles then restart
if 3 restarts within 5 cycles then alert
This configuration will ensure that if daemon stops responding on tcp port 1234, or will stop running, it will be restarted using the init script. monit
will also send you an alert through email, or do other things, depending on how you configure it. Just check out monit(1)
manpage.
Running under the local system account, the script will be connecting to the network using the AD computer account (i.e. COMPUTERNAME$).
However, the %logonserver% variable might not be valid in the context of the system account - after all the local system account authenticates with the local machine, not the domain. The %logonserver% variable may either be blank, or equal to the local machine name.
try using \\domain.name\NETLOGON
instead. This will connnect to a domain controller (and since the NETLOGON share contains the same files on all DCs because it uses FRS, it doesn't matter which DC you're talking to.
Best Answer
If your service already has an init script, you can add it to the
default
runlevel by running:If not, depends on which services system you're using, add your scripts to the
/etc/conf.d/local.start
or/etc/local.d/baselayout1.start
, something like this: