#! /bin/sh
### BEGIN INIT INFO
# Provides:          papercut
# Required-Start:    $local_fs $remote_fs mysql postgresql
# Required-Stop:     $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      S 0 1 6
# Short-Description: Papercut NNTP server
# Description:       Papercut is a simple and extensible NNTP server, meant
#                    to provide news access to existing content, e.g. web based
#                    bulletin board systems.
### END INIT INFO
#
# Author:	Jérémy Bobbio <jeremy.bobbio@etu.upmc.fr>.
#

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="Papercut NNTP server"
NAME=papercut
DAEMON=/usr/bin/$NAME
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

#
#	Function that starts the daemon/service.
#
d_start() {
	echo -n "Starting $DESC: $NAME"
	start-stop-daemon --start --quiet --pidfile $PIDFILE \
			  --exec $DAEMON &&
	    echo "." ||
	    echo " failed!"
}

#
#	Function that stops the daemon/service.
#
d_stop() {
	echo -n "Stopping $DESC: $NAME"
	start-stop-daemon --stop --quiet --pidfile $PIDFILE &&
	    echo "." ||
	    echo " not running."
}

case "$1" in
  start)
	d_start
	;;
  stop)
	d_stop
	;;
  restart|force-reload)
	d_stop
	sleep 1
	d_start
	;;
  *)
	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
