Daemontools runs and manages persistent processes.
Debian changes several of the default daemontools directory locations in order to adhere to the filesystem heirarchy.
# aptitude install daemontools daemontools-run
Daemontools-run installs daemontools so that it runs at boot and is kept alive. Since daemontools must be running in order to manage other daemons, this is necessary.
The service directory is
Daemontools is not installed in
Ubuntu will start daemontools using upstart rather than init. Daemontools-run should install an upstart script, which can be started with:
# start svscan
It seems easiest to compile daemontools from scratch according to djb's install instructions.
You'll first need to patch daemontools with the errno patch.
Daemontools is generally managed using the commands
svc -u /service/mydaemon– Bring the daemon UP
svc -d /service/mydaemon– Bring the daemon DOWN
svc -t /service/mydaemon– TERM the daemon and restart it
svstat /service/mydaemon– Check the STATUS of the daemon
svc command reference for details.
svscan, especially with a service directory as its argument. This command causes a new instance of daemontools to treat the provided directory as a daemontools
/service directory that is monitored for daemons. This will cause chaos and prevent your daemons from running.
Symlink the daemon's "service" directory (which contains its deamontools
run script) into
# ln -s /etc/mydaemon /service/ # svstat /service/mydaemon /service/mydaemon: up (pid 1234) 2 seconds
To create a daemon:
- Create a service directory for your daemon
- Within this directory, create a root owned executable script named
execyour program, which must not detach from the terminal
- To execute as a non-root user, use setuidgid exec setuidgid appuser myscript
See djb's daemontools faq for details. Logging uses a similar
run script in the 'log' subdirectory.
#!/bin/bash exec 2>&1 # redirect STDERR to STDOUT for logging exec setuidgid app \ /home/app/.virtualenvs/bin/mydaemon \ --config /etc/mydaemon.conf \ --port 8080 \ --log stderr
#!/bin/bash # log to syslog exec logger -p user.notice