#!/bin/sh -e
#
# Init.d script for WendzelNNTPd
#
# Copyright (c) 2009-2021 Steffen Wendzel, https://www.wendzel.de
#
# This is free software; you may redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2,
# or (at your option) any later version.
#
# This is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License with
# this software;  if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

DAEMON=REPLACETHIS_WITH_DAEMONPATH

if [ "$1" != "start" -a "$1" != "stop" -a "$1" != "restart" ]; then
	echo "usage: $0 start|stop|restart"
	exit 1	
fi

if [ "$1" = "stop" -o "$1" = "restart" ]; then
	echo -n "Stopping WendzelNNTPd ... "
	for pid in `pgrep wendzelnntpd`; do
		if [ "$pid" != "$$" ]; then
			kill $pid
		fi
	done
	echo "done."
fi

if [ "$1" = "start" -o "$1" = "restart" ]; then
	ALREADY_RUNNING="n"
	for pid in `pgrep wendzelnntpd`; do
		if [ "$pid" != "$$" ]; then
			echo "WendzelNNTPd is already running."
			ALREADY_RUNNING="y"
		fi
	done
	if [ "$ALREADY_RUNNING" = "n" ]; then
		echo -n "Starting WendzelNNTPd ... "
		$DAEMON -d
		echo "done."
	fi
fi

exit 0
