making ejabberd log to (r)syslog w/ daemontools

ESL Developer Blog - - June 24, 2009

Having all logs in one place and a service which automatically is in charge of keeping a specific service running (e.g. ejabberd) is really nice to have. Forget about cronjobbed Scripts which check your service. daemontools is the one we use for this “always on” applications. You can download it here.

Installing daemontools is really simple on debian. You just create an Installation Script which sets up the files the supervise instance later uses to control your service. Save the following script to install_ejabberd_svc.sh and make it executable.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
# v2009-04-09 tp@turtle-entertainment.de
# ejabberd and daemontools
#
echo STARTING EJABBERD WITH DAEMONTOOLS
# see
# http://cr.yp.to/daemontools/svc.html
# http://cr.yp.to/daemontools/softlimit.html
# http://www.kdegraaf.net/supervise.html
#
SERVICEDIR="/etc/service"
SERVICE="ejabberd
# No svc should be running, but to make sure we let it die first
svc -d ${SERVICEDIR}/${SERVICE} &> /dev/null
test -d && rm -rf ${SERVICEDIR}/${SERVICE}
mkdir -p ${SERVICEDIR}/${SERVICE}
test -f && rm -f ${SERVICEDIR}/${SERVICE}/run
test -f && rm -f ${SERVICEDIR}/${SERVICE}/tmprun
cat > ${SERVICEDIR}/${SERVICE}/tmprun <<EOF
#!/bin/sh
exec 2>&1
sleep 3
exec /opt/ejabberd/server/sbin/ejabberdctl start
EOF
chmod 755 ${SERVICEDIR}/${SERVICE}/tmprun
mv -f ${SERVICEDIR}/${SERVICE}/tmprun ${SERVICEDIR}/${SERVICE}/run
# Create log Pipe
mkdir -p ${SERVICEDIR}/${SERVICE}/log
chmod 1755 ${SERVICEDIR}/${SERVICE}/log
test -f && rm -f ${SERVICEDIR}/${SERVICE}/log/run
test -f && rm -f ${SERVICEDIR}/${SERVICE}/log/tmprun
cat > ${SERVICEDIR}/${SERVICE}/log/tmprun <<EOF
#!/bin/sh
exec env - PATH="/usr/bin" logger -p local5.err -t EJABBERD
EOF
chmod 755 ${SERVICEDIR}/${SERVICE}/log/tmprun
mv -f ${SERVICEDIR}/${SERVICE}/log/tmprun ${SERVICEDIR}/${SERVICE}/log/run

Now you just need to run this script and install the daemontools-run package under debian. This automatically uses the just created structure and starts ejabberd with logging stdout to logger. Keep in mind that every programm you run under daemontools must run in foreground.

1
aptitude install daemontools-run

Thats it!

If you want to use rsyslog just setup your rsyslog.conf for redirecting local5.err to your rsyslogserver

1
local5.err @10.10.0.99:514



Categories: Blogs  ESL Developer Blog  

Comments

No comments so far, you could be the first.

Add comment

Name:

Email:

URL:

Smileys

Remember my personal information

Notify me of follow-up comments?