#!/bin/sh
# $Id: rsplib-registrar.init 2082 2008-12-28 20:54:01Z dreibh $
# --------------------------------------------------------------------------
#
#              //===//   //=====   //===//   //       //   //===//
#             //    //  //        //    //  //       //   //    //
#            //===//   //=====   //===//   //       //   //===<<
#           //   \\         //  //        //       //   //    //
#          //     \\  =====//  //        //=====  //   //===//    Version II
#
# ------------- An Efficient RSerPool Prototype Implementation -------------
#
# Copyright (C) 2002-2008 by Thomas Dreibholz
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Contact: dreibh@iem.uni-due.de
#

### BEGIN INIT INFO
# Provides:          rsplib-registrar
# Required-Start:    networking
# Required-Stop:
# Default-Start:     3 4 5
# Default-Stop:      0 1 2 6
# Short-Description: RSerPool Registrar
# Description:       This service provides a RSerPool Registrar.
### END INIT INFO


PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=registrar
DESC="RSerPool Registrar"
DAEMON=/usr/bin/registrar
DAEMON_OPTS="-quiet -daemonpidfile=/var/run/$NAME.pid -disable-ipv6"

test -x $DAEMON || exit 0

# make sure SCTP module is loaded.
modprobe sctp > /dev/null 2>&1

# Include rsplib defaults if available
if [ -f /etc/default/rsplib-registrar ] ; then
   . /etc/default/rsplib-registrar
fi

set -e

case "$1" in
  start)
   echo -n "Starting $DESC: "
   start-stop-daemon --start  --pidfile /var/run/$NAME.pid \
      --exec $DAEMON -- $DAEMON_OPTS
   echo "$NAME."
   ;;
  stop)
   echo -n "Stopping $DESC: "
   start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
      --exec $DAEMON
   echo "$NAME."
   ;;
  force-reload)
   start-stop-daemon --stop --test --quiet --pidfile \
      /var/run/$NAME.pid --exec $DAEMON \
   && $0 restart \
   || exit 0
   ;;
  restart)
    echo -n "Restarting $DESC: "
   start-stop-daemon --stop --quiet --pidfile \
      /var/run/$NAME.pid --exec $DAEMON
   sleep 1
   start-stop-daemon --start --quiet --pidfile \
      /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
   echo "$NAME."
   ;;
  *)
   N=/etc/init.d/$NAME
   echo "Usage: $N {start|stop|restart|force-reload}" >&2
   exit 1
   ;;
esac

exit 0
