#!/bin/sh
#
# source:
#   /var/cvs/projects/debian/wn/debian/dpkg.src/wn.init.d.in,v
#
# revision:
#   @(#) wn.init.d.in,v 1.5 1998/12/20 17:55:31 jplejacq Exp
#
# copyright:
#   Copyright (C) 1998 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: 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 swn 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)
      "${0}" stop
      sleep 5
      "${0}" start
      ;;
    *)
      echo -n "Usage: /etc/init.d/${initd_pkg} "
      echo " {start|stop|restart|reload|force-reload}"
      exit 1
      ;;
  esac


  exit 0
