Daemontools for Init
by Scott, Revised on November 7, 2010 (Linux, Web Serving)
Daemontools is a collection of tools for managing UNIX services. It can be used to create an init process for a service. My interest is to use it to start a standalone FastCGI process for a web application.
For Install on Debian:
apt-get install daemontools daemontools-run
This install provides a directory: /etc/service. To use the init services, create a directory under the service directory, then provide a executable script called "run." The install also places a statement in the /etc/inittab files that tells the svscanboot program to continue to scan the subdirectories for the run scripts. Once an executable run script is placed in a subdirectory, it is executed, thereby starting the daemon.
Commands (as root)
- Bring down the service svc -d /etc/service/myapp
- SIGTERM and restart svc -t /etc/service/myapp
- Start the service svc -u /etc/service/myapp
- Status of the daemons svstat /etc/service/*
The idea to use this tool is from: FastCGI Deployment with Bells On
Example Run Script
#!/bin/sh exec 2>&1 exec setuidgid myuser \ /usr/bin/plackup \ /home/myuser/myapp/script/myapp.fcgi \ --server FCGI \ --listen /tmp/myapp.sock \ --nproc 3
Notes: The setuidgid starts the daemon under the user specified. Do not use a daemonize flag, as that causes the process to run in the background. The svscanboot could not detect proper running of the daemon, so it continued to spawn more daemons, ate up more and more memory, and ground my computer into the ground.
Tags: Linux, Web Serving