Installing DaemonTools in Amazon Linux (or CentOS like OS).
TweetStarting and supervising your services in Linux with Daemontools
DaemonTools is an excellent piece of software created by Daniel J. Bernstein, and composed of several tools used to launch and monitor processes in a unix environment. They are fast, reliable, and are my favourites whenever I get to wear the devops hat to setup a new server. Sadly, there's no default package available for distros like Amazon Linux or CentOS, so here are the steps involved for setting them up manually.
Downloading daemontools
Patching for newest distributions
In modern operating distros, you will get the following error if you try to compile it right away:
/usr/bin/ld: errno: TLS definition in /lib64/libc.so.6 section .tbss mismatches non-TLS reference in envdir.o
/lib64/libc.so.6: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
make: *** [envdir] Error 1
So if that's your case, apply the following patch like this:
Compiling and installing daemontools in your Centos or Amazon Linux
After uncompressing and patching, we can start compiling daemontools:
Setting it up
Once built and installed, we need to start the svscan process when the system starts so it can monitor and start our services. This is a simple way to make UpStart start svscan on boot:
That's it! You can start writing your service scripts in /etc/service.
Service Example: Using daemontools to start and monitor a Jenkins server in Linux
Let's say we want Jenkins to be started and monitored by daemontools. We would create a the following files and directories in a temporary directory (let's say /tmp):
- /tmp/jenkins/log/run (mode 0700)
- /tmp/jenkins/env/JAVA_HOME (mode 0600)
- /tmp/jenkins/run (mode 0700)
The env/JAVA_HOME file would contain the path to where the JVM is installed:
/usr/java
The log/run file could look like:
And the run file would look like:
Once we create all the files, we can just mv /tmp/jenkins /etc/service and Jenkins will be started instantaneously by daemontools without further delay.
Enjoy!