#!/bin/sh
# --------------------------------------------------------------------------
#
#              //===//   //=====   //===//   //       //   //===//
#             //    //  //        //    //  //       //   //    //
#            //===//   //=====   //===//   //       //   //===<<
#           //   \\         //  //        //       //   //    //
#          //     \\  =====//  //        //=====  //   //===//   Version III
#
# ------------- An Efficient RSerPool Prototype Implementation -------------
#
# Copyright (C) 2002-2023 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: thomas.dreibholz@gmail.com
#

### BEGIN INIT INFO
# Provides:          rsplib-registrar
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 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=rspregistrar
DESC="RSerPool Registrar"
PIDFILE=/var/run/$NAME.pid
DAEMON=/usr/bin/rspregistrar
DAEMON_ARGS="-quiet -daemonpidfile=$PIDFILE -logfile=/var/log/$NAME.log -loglevel=3 -logcolor=off"

test -x $DAEMON || exit 0


# Make sure that SCTP is available
modprobe sctp > /dev/null 2>&1
# sysctl net.sctp.addip_enable=1
# sysctl net.sctp.auth_enable=1


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

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions


set -e

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

exit 0
