Setting Up daemontools on CentOS 5

I recently had to setup daemontools on a CentOS system. I had set it up before but it had been a while. So I Google’d around and found very little and what little I did find wasn’t very helpful. So here is a quick and dirty on setting up daemontools. I even included the CentOS fix that I came across to make it compile. There is also a patch version (if you were building an RPM), but I prefer just making the change in this case; it’s much simpler.

1) Download daemontools from here (Pagetar.gz) Install daemontools using the following bash line:

# package/install

This part can be tricky on CentOS 5 systems now because of some errno.h issues. Credit where credit is due, I initially found my answer here: http://syslog.warten.de/2008/07/bernsteins-daemontools-install.html

In short, the trick is to change the first line in the packages/conf-cc file to read as follows:

gcc -include /usr/include/errno.h -O2 -Wimplicit -Wunused -Wcomment -Wchar-subscripts -Wuninitialized -Wshadow -Wcast-qual -Wcast-align -Wwrite-strings

2) Add these lines to your /etc/rc.local.

# Start daemontools
csh -cf  '/command/svscanboot &'

Also make sure that your /etc/rc.local is executable.

[root@server service]# chmod +x /etc/rc.local

3) Make sure the directories named /service and /var/service exist. Going with what I am setting up (Gearman) at the moment, let’s get a service setup.

[root@server service]# mkdir /var/service/gearman
[root@server service]# ln -s /var/service/gearman /service/gearman

4) Now we add the gearman/run file used for starting up the daemon.

[root@server service]# cat /var/service/gearman/run
#!/bin/bash

echo "Starting gearman"
# Note that --daemon isn't here because we want it running in the 'supervise' foreground
exec gearmand --user=gearman --queue-type=libmemcached

5) Finally make sure that your run file is executable.

[root@server service]# chmod +x /var/service/gearman/run

6) Right from here, we are all setup that the /service directory will be scanned on the next reboot and all of the /service/**/run files will be executed. This is the ideal way to If you want to start everything up from here. However, I know that restarting a machine isn’t always a possibility. Therefore you can start up all services in your /service/ directory like this:

[root@server service]# svscan /service/

Anything further, I strongly suggest you read the daemontools documentation here.