#! /bin/sh
#
# /etc/init.d/lyskom-server: start and stop the LysKOM server
# See below for information on how to enable.
#
### BEGIN INIT INFO
# Provides:          lyskom-server
# Required-Start:    $syslog, $network, $time
# Required-Stop:     $syslog, $network, $time
# Should-Start:      $local_fs
# Should-Stop:       $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start and stop the LysKOM server
# Description:       Used to start and stop the LysKOM server.
#                    Automatic start is by default disabled, edit
#                    /etc/default/lyskom-server to enable automatic
#                    start through this script.
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin

if [ -f  /etc/default/lyskom-server ]; then
  . /etc/default/lyskom-server
fi

test -x /usr/sbin/komrunning || exit 0

case "$1" in
  start)
    if test "$startonboot" = "NO"; then
      echo "Automatic start of the LysKOM server from /etc/init.d is disabled."
    else
      sh $0 force-start
    fi
    ;;

  force-start)
    echo -n "Signalling start of LysKOM server"
    mkdir -p /var/run/lyskom-server
    /usr/sbin/komrunning start
    echo "."
    ;;

  stop)
    echo -n "Stopping LysKOM server"
    /usr/sbin/komrunning stop
    rm -f /var/run/lyskom-server/pid
    rm -f /var/run/lyskom-server/status
    echo "."
    ;;

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

  *)
    echo "Usage: /etc/init.d/lyskom-server {start|force-start|stop|restart}"
    ;;
esac

exit 0
