#!/bin/sh
#
# rights:
#   Copyright 1999 Jean Pierre LeJacq <jplejacq@quoininc.com>.
#
#   Distributed under the GNU GENERAL PUBLIC LICENSE.
#
# source:
#   /var/cvs/projects/org/wnserver/wn/debian/src/wn/DM_FS_PKG_ETC_INITD.in,v
#
# revision:
#   1.1
#
# state:
#   Exp
#
# author:
#   jplejacq@quoininc.com
#
# last-modified:
#   2000/01/29 04:17:53
#
# last-editor:
#   jplejacq@quoininc.com
#
# description:
#   Host configuration of init program for wn.
#
#   Script run by init to start and stop this package's service.
#
#   wn has two daemons: wnd which is invoked by inetd; and wnsd
#   which is a standalong daemon started from this program.  The
#   package uses a configuration file, /etc/wn/wn.conf, to select
#   the daemon.  This program checks the configuration file and only
#   starts the daemon if wnsd is selected.


# global:
  readonly initd_pkg='wn'

  readonly initd_wn_daemon='/usr/sbin/wnsd'
  readonly initd_wn_daemon_wrapper='/etc/wn/wn.rc'
  readonly initd_wn_run_pid='/var/run/wn.pid'
  readonly initd_wn_conf='/etc/wn/wn.conf'


# main:
  set -e


  test -f "${initd_wn_conf}" || exit 0
  test -f "${initd_wn_daemon}" || exit 0
  test -f "${initd_wn_daemon_wrapper}" || exit 0

  . "${initd_wn_conf}"

  case "${1}" in
    start)
      if [ "${initd_wn_daemon}" = "${wn_daemon}" ]
      then
        echo -n "Starting http server: ${initd_pkg}"
        start-stop-daemon --start --quiet --exec "${initd_wn_daemon_wrapper}"
        echo '.'
      fi
      ;;
    stop)
      echo -n "Stopping http server: ${initd_pkg}"
      start-stop-daemon --stop --oknodo --quiet --pidfile "${initd_wn_run_pid}"
      rm -f "${initd_wn_run_pid}"
      echo '.'
      ;;
    restart|reload|force-reload)
      echo -n "Reloading ${initd_pkg} configuration..."

      start-stop-daemon --stop --oknodo --quiet --pidfile "${initd_wn_run_pid}"
      rm -f "${initd_wn_run_pid}"

      sleep 5

      if [ "${initd_wn_daemon}" = "${wn_daemon}" ]
      then
        start-stop-daemon --start --quiet --exec "${initd_wn_daemon_wrapper}"
      fi

      echo 'done.'
      ;;
    *)
      echo -n "Usage: /etc/init.d/${initd_pkg} "
      echo ' {start|stop|restart|reload|force-reload}'
      exit 1
      ;;
  esac


  exit 0
