#!/bin/sh
### BEGIN INIT INFO
# Provides:          kannel-smsbox
# Required-Start:    $local_fs $remote_fs kannel-bearerbox
# Required-Stop:     $local_fs $remote_fs kannel-bearerbox
# Should-Start:      $network $named
# Should-Stop:       $network $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Kannel SMS box
# Description:       Kannel is a gateway for connecting WAP phones to the
#                    Internet. It also works as an SMS gateway.
### END INIT INFO

. /lib/lsb/init-functions

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=smsbox
DESC="Kannel Box"
DAEMON=/usr/sbin/$NAME
PIDDIR=/var/run/kannel
PIDFILE=$PIDDIR/kannel-$NAME.pid
CONF=/etc/kannel/kannel.conf

# On Debian, the most likely reason for the daemon not being available
# is that the package is in the "removed" or "unconfigured" state, and the
# init.d script is still around because it's a conffile. This is normal,
# so do not generate any output.
test -x $DAEMON || exit 0

test -r /etc/default/kannel && . /etc/default/kannel

case "$1" in
start)
  log_daemon_msg "Starting $DESC" "$NAME"
  if [ ! -d $PIDDIR ]; then
    mkdir $PIDDIR
    chown kannel:root $PIDDIR
  fi
  start-stop-daemon --start --quiet \
    --pidfile $PIDFILE \
    --chuid kannel \
    --exec $DAEMON \
    -- \
    -v 4 \
    --pidfile $PIDFILE \
    $CONF \
    # EOL
  log_end_msg 0
  ;;

stop)
  log_daemon_msg "Stopping $DESC" "$NAME"
  start-stop-daemon --stop --retry 5 --quiet \
    --pidfile $PIDFILE \
    --exec $DAEMON \
    # EOL
  log_end_msg 0
  ;;

reload)
  # We do not have support for this yet.
  exit 1
  ;;

restart|force-reload)
  $0 stop
  $0 start
  ;;

status)
  status_of_proc $DAEMON $NAME
  ;;

*)
  echo "Usage: $0 {start|stop|restart|reload|force-reload|status}" >&2
  exit 1
  ;;
esac

exit 0
