kannel/kannel-initscript

114 lines
3.0 KiB
Bash

#!/bin/sh
#
# kannel This script takes care of starting and stopping the kannel \
# WAP gateway services (bearer/wap/smsbox).
#
# chkconfig: - 97 03
# description: The Kannel WAP and SMS gateway services
# config: /etc/kannel.conf
#
# Modified by Stefano Cotta Ramusino <stefano.cotta@openmamba.org>
. /etc/sysconfig/rc
. $rc_functions
NAME=kannel
KANNEL=/usr/sbin/$NAME
KANNEL_CONFIG=/etc/$NAME.conf
LOCKFILE=/var/lock/subsys/$NAME
BEARERBOX=/usr/sbin/bearerbox
WAPBOX=/usr/sbin/wapbox
SMSBOX=/usr/sbin/smsbox
# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0
[ -x $KANNEL ] || exit 0
[ -r $KANNEL_CONFIG ] || exit 1
RETVAL=0
RETVAL_BEARERBOX=0
RETVAL_WAPBOX=0
RETVAL_SMSBOX=0
case "$1" in
start)
echo -n "Starting kannel bearer box: "
daemon $KANNEL --start --background --chuid kannel:kannel --exec $BEARERBOX $KANNEL_CONFIG
RETVAL_BEARERBOX=$?
echo
# It seems like the bearerbox may need to settle before accepting
# connections from wapbox and smsbox
sleep 3s
# Starting wap and sms only makes sense if bearerbox is running
if [ $RETVAL_BEARERBOX -eq 0 ]; then
if grep "^group = wapbox" $KANNEL_CONFIG &>/dev/null; then
echo -n "Starting kannel wap box: "
daemon $KANNEL --start --background --chuid kannel:kannel --exec $WAPBOX $KANNEL_CONFIG
RETVAL_WAPBOX=$?
echo
fi
if grep "^group = smsbox" $KANNEL_CONFIG &>/dev/null; then
echo -n "Starting kannel sms box: "
daemon $KANNEL --start --background --chuid kannel:kannel --exec $SMSBOX $KANNEL_CONFIG
RETVAL_SMSBOX=$?
echo
fi
fi
[ $RETVAL_BEARERBOX -eq 0 -a $RETVAL_WAPBOX -eq 0 -a $RETVAL_SMSBOX -eq 0 ] &&
touch $LOCKFILE || RETVAL=1
;;
stop)
if grep "^group = smsbox" $KANNEL_CONFIG &>/dev/null; then
echo -n "Shutting down kannel sms box: "
killproc $SMSBOX
RETVAL_SMSBOX=$?
echo
fi
if grep "^group = wapbox" $KANNEL_CONFIG &>/dev/null; then
echo -n "Shutting down kannel wap box: "
killproc $WAPBOX
RETVAL_WAPBOX=$?
echo
fi
echo -n "Shutting down kannel bearer box: "
killproc /usr/sbin/bearerbox
RETVAL_BEARERBOX=$?
echo
[ $RETVAL_BEARERBOX -eq 0 -a $RETVAL_WAPBOX -eq 0 -a $RETVAL_SMSBOX -eq 0 ] ||
RETVAL=1
rm -f $LOCKFILE
;;
status)
status $BEARERBOX
RETVAL_BEARERBOX=$?
if grep "^group = wapbox" $KANNEL_CONFIG &>/dev/null; then
status $WAPBOX
RETVAL_WAPBOX=$?
fi
if grep "^group = smsbox" $KANNEL_CONFIG &>/dev/null; then
status $SMSBOX
RETVAL_SMSBOX=$?
fi
[ $RETVAL_BEARERBOX -eq 0 -a $RETVAL_WAPBOX -eq 0 -a $RETVAL_SMSBOX -eq 0 ] ||
RETVAL=1
;;
restart)
$0 stop
sleep 1
$0 start
;;
condrestart)
[ -e $LOCKFILE ] && $0 restart || :
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
RETVAL=1
esac
exit $RETVAL