[olug] init.d scripts
William E. Kempf
wekempf at cox.net
Tue Apr 22 17:51:04 UTC 2003
I'm trying to get jabberd up and running on a Linux MDK 9.1 box. (This
question isn't really about jabberd, so don't stop reading yet.) The
configuration of jabber is best done with multiple servers to handle
various services, such as JUD (the user database) and gateways to other IM
servers, like MSN. The AIM gateway, when installed through urpmi, created
a file /etc/init.d/jabber-aim, which starts and stops the jabber AIM
gateway.
# ps aux | grep jabberd
root 14305 0.0 0.1 1724 604 pts/4 R 12:41 0:00 grep jabberd
# service jabber-aim start
Starting Jabber AIM Transport: [ OK ]
# ls /var/run/jabber/
jabber-aim.pid
So far, so good. The MSN gateway, when installed through urpmi, does not
add an init.d script, however. So, I copied the jabber-aim script to
jabber-msn and modified the pertinent lines of code. (See both files
below.)
# ps aux | grep jabberd
daemon 14337 0.0 0.2 4104 1116 pts/4 S 12:41 0:00
/usr/sbin/jabberd -h csdsvr10.fdcsg.1dc.com -c /etc/jabber/jabber-aim.xml
-B
root 14360 0.0 0.1 1724 604 pts/4 R 12:43 0:00 grep jabberd
# service jabber-msn start
Starting Jabber MSN Transport: [ OK ]
# ls /var/run/jabber/
jabber-aim.pid
No jabber-msn.pid would seem to indicate that the service didn't start, if
I understand the init.d script at all. However:
# ps aux | grep jabberd
daemon 14337 0.0 0.2 4104 1120 pts/4 S 12:41 0:00
/usr/sbin/jabberd -h csdsvr10.fdcsg.1dc.com -c /etc/jabber/jabber-aim.xml
-B
daemon 14400 0.0 0.2 4024 1116 pts/4 S 12:43 0:00
/usr/sbin/jabberd -h csdsvr10.fdcsg.1dc.com -c /etc/jabber/msntrans.xml -B
root 14416 0.0 0.1 1724 604 pts/4 R 12:44 0:00 grep jabberd
Clearly it was started, and is still running (and functions, I might add).
Is there something about the daemon() function in the init.d script I'm
not understanding, or have I done something else just as foolish? With
out the pid file I can't stop the process in the normal manner.
---------------------------------------------------------------------------
#!/bin/sh
#
# jserver This shell script takes care of starting and stopping
# jabber AIM transport.
#
# chkconfig: 2345 70 40
# description: JABBER is an instant messaging System. \
#
# processname: jabberd
# config: /etc/jabber/aimtrans.xml
# pidfile: /var/run/jabber/jabber-aim.pid
# Source function library.
.. /etc/rc.d/init.d/functions
# Source networking configuration.
.. /etc/sysconfig/network
CONF=/etc/jabber/jabber-aim.xml
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -f /usr/sbin/jabberd ] && [ -f $CONF ] || exit 0
if [ -x /etc/jabber/jabber.cfg ]; then
.. /etc/jabber/jabber.cfg
fi
CMDLINE="/usr/sbin/jabberd"
if [ x"$JABBER_HOSTNAME" != x"" ]; then
CMDLINE="$CMDLINE -h $JABBER_HOSTNAME"
fi
if [ x"$JABBER_SPOOL" != x"" ]; then
CMDLINE="$CMDLINE -s $JABBER_SPOOL"
fi
if [ x"$CONF" != x"" ]; then
CMDLINE="$CMDLINE -c $CONF"
fi
CMDLINE="$CMDLINE -B"
RETVAL=0
# See how we were called.
case "$1" in
start)
# Start daemons.
gprintf "Starting Jabber AIM Transport: "
cd /usr/lib/jabber
daemon --check jabber/jabber-aim --user daemon $CMDLINE
touch /var/lock/subsys/jabber-aim
echo
;;
stop)
# Stop daemons.
gprintf "Shutting down Jabber AIM Transport: "
RETVAL=1
[ -f /var/run/jabber/jabber-aim.pid ] && kill `cat
/var/run/jabber/jabber-aim.pid` &> /dev/null && RETVAL=$?
if [ $RETVAL -eq 0 ]; then
success " "
rm -f /var/lock/subsys/jabber-aim
else
failure " "
fi
echo
;;
condrestart)
if [ -f /var/lock/subsys/jabber-aim ] ; then
$0 stop
$0 start
RETVAL=$?
fi
;;
status)
status jabberd
RETVAL=$?
;;
restart)
$0 stop
$0 start
RETVAL=$?
;;
reload)
gprintf -n "Reload Jabber AIM Transport"
kill -HUP `cat /var/run/jabber/jabber-aim.pid`
RETVAL=$?
[ $RETVAL -eq 0 ] && success " "
[ $RETVAL -eq 0 ] || failure " "
echo
;;
*)
gprintf "Usage: $s start|stop|restart|status}\n" $0
exit 1
esac
exit $RETVAL
---------------------------------------------------------------------------
#!/bin/sh
#
# jserver This shell script takes care of starting and stopping
# jabber MSN transport.
#
# chkconfig: 2345 70 40
# description: JABBER is an instant messaging System. \
#
# processname: jabberd
# config: /etc/jabber/msntrans.xml
# pidfile: /var/run/jabber/jabber-msn.pid
# Source function library.
.. /etc/rc.d/init.d/functions
# Source networking configuration.
.. /etc/sysconfig/network
CONF=/etc/jabber/msntrans.xml
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -f /usr/sbin/jabberd ] && [ -f $CONF ] || exit 0
if [ -x /etc/jabber/jabber.cfg ]; then
.. /etc/jabber/jabber.cfg
fi
CMDLINE="/usr/sbin/jabberd"
if [ x"$JABBER_HOSTNAME" != x"" ]; then
CMDLINE="$CMDLINE -h $JABBER_HOSTNAME"
fi
if [ x"$JABBER_SPOOL" != x"" ]; then
CMDLINE="$CMDLINE -s $JABBER_SPOOL"
fi
if [ x"$CONF" != x"" ]; then
CMDLINE="$CMDLINE -c $CONF"
fi
CMDLINE="$CMDLINE -B"
RETVAL=0
# See how we were called.
case "$1" in
start)
# Start daemons.
gprintf "Starting Jabber MSN Transport: "
cd /usr/lib/jabber
daemon --check jabber/jabber-msn --user daemon $CMDLINE
touch /var/lock/subsys/jabber-msn
echo
;;
stop)
# Stop daemons.
gprintf "Shutting down Jabber MSN Transport: "
RETVAL=1
[ -f /var/run/jabber/jabber-msn.pid ] && kill `cat
/var/run/jabber/jabber-msn.pid` &> /dev/null && RETVAL=$?
if [ $RETVAL -eq 0 ]; then
success " "
rm -f /var/lock/subsys/jabber-msn
else
failure " "
fi
echo
;;
condrestart)
if [ -f /var/lock/subsys/jabber-msn ] ; then
$0 stop
$0 start
RETVAL=$?
fi
;;
status)
status jabberd
RETVAL=$?
;;
restart)
$0 stop
$0 start
RETVAL=$?
;;
reload)
gprintf -n "Reload Jabber MSN Transport"
kill -HUP `cat /var/run/jabber/jabber-msn.pid`
RETVAL=$?
[ $RETVAL -eq 0 ] && success " "
[ $RETVAL -eq 0 ] || failure " "
echo
;;
*)
gprintf "Usage: $s start|stop|restart|status}\n" $0
exit 1
esac
exit $RETVAL
--
William E. Kempf
More information about the OLUG
mailing list