Glue Logic LLC logo

daemontools service examples


Another set of examples can be found in Gerritt Pape's runscripts

dnscache

http://cr.yp.to/djbdns.html

dnscache is a caching-only DNS resolver.
To set it up, we followed the official dnscache setup instructions. Since we run a very busy server, we modified /var/service/dnscache/run to discard all output (exec >/dev/null 2>&1) once we determined cache motion and adjusted dnscache cache size. Until then, we directed output to multilog with exec 2>&1, now commented out below.

/var/service/dnscache/run
#!/bin/sh
exec >/dev/null 2>&1
#exec 2>&1
exec <seed
exec envdir ./env sh -c '
  exec envuidgid dnscache softlimit -o250 -d "$DATALIMIT" /usr/local/sbin/dnscache
'
/var/service/dnscache/log/run
#!/bin/sh
exec setuidgid multilog sh -c 'exec -a multilog-dnscache multilog t ./main'

Clam AntiVirus

http://www.clamav.net/

clamd
The clamav stderr.patch is needed to keep clamd from redirecting its error output away from stderr. With this patch, and the clamav.conf below, clamd will send its error output to stderr where svscan can supervise the multilog or other log program which handles the output. First, set /usr/local/var/clamav up as a private directory for clamd socket and pidfile (use looser permissions (0755) to enable other users to run clamdscan).
mkdir --mode=0700 /usr/local/var/clamav
chown clamav.clamav /usr/local/var/clamav
/usr/local/etc/clamav.conf
[...snip...]
LogFile /dev/stderr
LogFileUnlock
LogFileMaxSize 0
PidFile /usr/local/var/clamav/clamd.pid
TemporaryDirectory /var/tmp
LocalSocket /usr/local/var/clamav/clamd.sock
User clamav
Foreground
[...snip...]
/service/clamd/run
#!/bin/sh
exec 2>&1
rm -f /usr/local/var/clamav/clamd.sock
exec setuidgid clamav /usr/local/clamav/sbin/clamd
/service/clamd/log/run
#!/bin/sh
exec setuidgid multilog sh -c 'exec -a multilog-clamd multilog t ./main'

clamav-milter
To plug ClamAV into Sendmail, add the following lines to /etc/mail/sendmail.mc
INPUT_MAIL_FILTER(`clmilter',`S=local:/usr/local/var/clamav/clmilter.sock,F=, T=S:4m;R:4m')dnl
define(`confINPUT_MAIL_FILTERS',`clmilter')dnl
and then rebuilt /etc/sendmail.cf with
m4 /etc/mail/sendmail.mc > /etc/sendmail.cf
/var/service/clamav-milter/run
#!/bin/sh
exec 2>&1
rm -f /usr/local/var/clamav/clmilter.sock
until svok /var/service/clamd && [ -e /usr/local/var/clamav/clamd.sock ]; do
  sleep 1
done
exec setuidgid clamav /usr/local/clamav/sbin/clamav-milter \
  -C -H -l -m 20 -n -o -q local:/usr/local/var/clamav/clmilter.sock

OpenSSH

http://www.openssh.com/

OpenSSH is the defacto Open Source sshd.

/var/service/openssh/run
#!/bin/sh
exec 2>&1
exec /usr/local/sbin/sshd -D

Dovecot

http://dovecot.org/

Dovecot is an IMAP and POP3 server supporting both mbox and Maildir mailbox formats.

/usr/local/etc/dovecot.conf
[...snip...]
imap_listen = mail.example.com
pop3_listen = mail.example.com
imaps_listen = mail.example.com
pop3s_listen = mail.example.com
[...snip...]
/var/service/dovecot/run
#!/bin/sh

exec 2>&1

# Wait for DNS to resolve (wait for dnscache to start)
# (only needed to bind to mail.example.com domain name instead of hard-coding IP address)
# (dnsip exits 0 on success, 111 on error)
until /usr/local/bin/dnsip mail.example.com >/dev/null 2>&1; do
  /bin/echo ...waiting for DNS resolver service > /dev/stderr
  /bin/sleep 1;
done

exec /usr/local/sbin/dovecot -F

Apache httpd

http://httpd.apache.org/

Apache httpd is the most popular web server on the internet today.
This example is for a special httpd instance run for the web interface to our email list server. We let Apache take care of its own logging with cronolog and set a few directives in our Apache conf file so that it would not interfere with other httpd instances:

ServerName lists.example.com
BindAddress lists.example.com
Port 80
PidFile /var/run/httpd-lists.pid
ScoreBoardFile /var/run/httpd-lists.scoreboard
LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" custom_combined
CustomLog "|/usr/local/sbin/cronolog /var/local/weblogs/%Y/%m/%d/lists.access" custom_combined
ErrorLog  "|/usr/local/sbin/cronolog /var/local/weblogs/%Y/%m/%d/lists.error"

/var/service/httpd-lists/run
#!/bin/sh
                                                                                
exec 2>&1
                                                                                
# Wait for DNS to resolve (wait for dnscache to start)
# (only needed for 'BindAddress lists.example.com' in lists.conf)
# (dnsip exits 0 on success, 111 on error)
until /usr/local/bin/dnsip lists.example.com >/dev/null 2>&1; do
  /bin/echo ...waiting for DNS resolver service > /dev/stderr
  /bin/sleep 1;
done
                                                                                
/bin/rm -f /var/run/httpd-lists.pid
exec /bin/nice -+15 \
     /usr/local/apache/bin/httpd -F -f /usr/local/apache/conf/lists.conf


Have other examples that you would like to contribute? Contact us!


Home    |    Projects    |    Contact Us
© 2004 Glue Logic LLC