#!/bin/sh
#
# source:
#   $Source: /var/cvs/projects/debian/wn/debian/dpkg.src/wn.init.d.dpkg-default.in,v $
#
# revision:
#   @(#) $Id: wn.init.d.dpkg-default.in,v 1.3 1998/05/05 03:07:48 jplejacq Exp $
#
# copyright:
#   Copyright (C) 1997 Jean Pierre LeJacq <jplejacq@quoininc.com>
#
#   Distributed under the GNU GENERAL PUBLIC LICENSE.
#
# description:
#   Host configuration of init program for wn.
#
#   Script run by init to start and stop this package's service.
#
#   wn has two daemons: wn which is invoked by inetd; and swn
#   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 swn is selected.


# global:
  initd_pkg=wn

  initd_wn_daemon=/usr/sbin/swn
  initd_wn_daemon_wrapper=/etc/wn/wn.rc
  initd_wn_run_pid=/var/run/wn/wn.pid
  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}
      echo "."
      ;;
    restart|force-reload)
      echo -n "Restarting ${initd_pkg}..."
      start-stop-daemon --stop --oknodo --quiet --pidfile ${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."
      ;;
    reload)
      echo -n "Reloading ${initd_pkg} configuration..."
      start-stop-daemon\
        --stop --signal HUP --oknodo --quiet --pidfile ${initd_wn_run_pid}
      echo "done."
      ;;
    *)
      echo -n "Usage: /etc/init.d/${initd_pkg} "
      echo " {start|stop|restart|reload|force-reload}"
      exit 1
      ;;
  esac


  exit 0
