Daemontools and upstart
Create a file under /etc/event.d# svscanboot start on runlevel 2 start on runlevel 3 start on runlevel 4 start on runlevel 5 stop on shutdown exec /usr/local/bin/svscanboot respawn
Then start this upstart service and check its status
initctl start svscanboot initctl status svscanboot
Installing daemontools
Download daemontools from http://cr.yp.to/daemontools/install.htmlInstall it and then reboot
cd admin/daemontools-0.76 package/install
If you run into error saying "cp: cannot stat `compile/svscan': No such file or directory", patch daemontools with the following
diff -ur daemontools-0.76.old/src/error.h daemontools-0.76/src/error.h --- daemontools-0.76.old/src/error.h 2001-07-12 11:49:49.000000000 -0500 +++ daemontools-0.76/src/error.h 2003-01-09 21:52:01.000000000 -0600 @@ -3,7 +3,7 @@ #ifndef ERROR_H #define ERROR_H -extern int errno; +#include <errno.h> extern int error_intr; extern int error_nomem;
Create run files for different services. For example, for apache:
#!/bin/sh # pick up any necessary environment variables if test -f /usr/local/sbin/envvars; then . /usr/local/sbin/envvars fi exec 2>&1 exec /usr/local/sbin/httpd -f /usr/local/etc/apache22/httpd.conf >> /var/log/httpd.log 2>&1
Even for mysql
#!/bin/sh exec /usr/local/mysql/bin/mysqld --user=mysql --datadir=/var/mysql/data
Check service status
svstat /service/mysql
Starting / stopping services
svc -h /service/yourdaemon: sends HUP
svc -t /service/yourdaemon: sends TERM, and automatically restarts the daemon after it dies
svc -d /service/yourdaemon: sends TERM, and leaves the service down
svc -u /service/yourdaemon: brings the service back up
svc -o /service/yourdaemon: runs the service once
svc -t /service/yourdaemon: sends TERM, and automatically restarts the daemon after it dies
svc -d /service/yourdaemon: sends TERM, and leaves the service down
svc -u /service/yourdaemon: brings the service back up
svc -o /service/yourdaemon: runs the service once