keepup

Documentation
Login

Utility to start daemons, and track whether they run or not. Meant to be used by non-root users.

usage: keepup [-u socketname] [-l logfile] [-sSKrR] <program> [args]
options:
  -l   Store program and keepup output in the file (/dev/null otherwise)
  -u   Unix socket for communication. Otherwise, guessed using <program>
  -s   Ask for status (running/dead)
  -S   Stop the program
  -r   Restart the program
  -R   Start the program only if not started
  -K   Kill keepup for this program
  -f   Daemon that forks

Examples

In my crontab, this line ensures the forking daemon dictd is up, and mlnet too:

* * * * * keepup -l ~/keepup.dictd-log -R -f dictd --locale ca_ES.UTF-8 -L ~/dict/dictd.log -c ~/dict/dictd.conf
* * * * * keepup -l ~/mlnet.log -R mlnet

I can check the status of them running, stop them or restart them:

$ keepup -s mlnet     # check status
running
$ keepup -S mlnet     # stop it, unblocks once stopped (or 3 sec timeout)
$ keepup -s mlnet
dead
$ keepup -r mlnet     # restart it, unblocks once it runs again (or 3 sec timeout)
$ keepup -s mlnet
running

Ptrace

Only the 'init' process can trace any daemon that forks or double forks, because as the parent dies, init gets it as a child. In linux terms, init is the global child reaper. But the 'init' process is root-owned, and this means the user can touch little of it.

I achieve similar capabilities with 'keepup' using ptrace() on linux. The procees, though, gets under ptrace during all its life, and this does not allow stracing it for example.

Poettering sent a patch for linux to allow changing the child reaper, but as of linux 3.2.7, it is not upstream still.

Similar work

I think systemd has per-user kind of init scripts, I don't know if only under a kernel with the patch from Poettering above.