Standard or best way to keep alive process started by init.d

Solution 1:

Debian will eventually have systemd, so this is the way to do it on a Linux system which uses systemd (and many do already; you might consider switching distributions).

Systemd can handle keeping the service alive for you automatically; no other tools are required. Simply make sure that Restart=always is set in the service file's [Service] section.

# vi /etc/systemd/system/dtnd.service

[Service]
Restart=always
#...everything else...

Several other options are available as well, for more complex scenarios.

Solution 2:

You could add it to /etc/inittab with respawn:

d1:2345:respawn:/path/to/your/first_daemon arg1 arg2
d2:2345:respawn:/path/to/your/second_daemon arg1 arg2

It's a dirty hack, but I've used it succesfully in the past on older sysv-init systems.


Solution 3:

Well, that is one of the main reason, why debian is moving to systemd.

sysvinit (/etc/init.d) is not able to detect, if a service is down/not responding. This means you have to monitor these services and escalate if a service won’t do his job anymore.

probably the easiest thing to do would be to migrate to another daemonhandler like systemd (default in RHEL7, will be default in next debian and ubuntu lts), upstart (default in RHEL6, Ubuntu 12.04 and 14.04), daemontools (like mentioned, develloped by djb) or something else.

doing the job of keeping a service alive will be PITA in sysvinit.