#! /bin/sh

# This is a simple, bare-bones example of a SysV-style init.d script for INN.
# It tries to increase the file descriptor limits to the maximum allowed by
# the system since INN and related programs can be file descriptor hogs.

test -f '<pathbin>/rc.news' || exit 0

start () {
    ulimit -n unlimited
    # Start INN.
    su news -s /bin/sh -c '<pathbin>/rc.news' >> <pathlog>/rc.news 2>&1
    # Start another nnrpd daemon, handling initial TLS connections on port 563.
    # Optionally, you can use -s with a long string of spaces as argument that
    # will be overwritten when nnrpd changes its process title in ps(1) to give
    # information about the connected client.
    #su news -s /bin/sh -c '<pathbin>/nnrpd -D -p 563 -S \
    #  -s "                                        "' >> <pathlog>/rc.news 2>&1
}

case "$1" in

start)
    start
    ;;

stop)
    # Stop INN.
    su news -s /bin/sh -c '<pathbin>/rc.news stop' >> <pathlog>/rc.news 2>&1
    # Stop possible other nnrpd daemons.  One of the two following commands
    # is enough.
    #start-stop-daemon --stop --name nnrpd --quiet --oknodo
    #su news -s /bin/sh -c 'killall nnrpd' >> <pathlog>/rc.news 2>&1
    # Clean the PID file of the nnrpd daemon we started on port 563.
    #rm -f <pathrun>/nnrpd-563.pid
    ;;

reload|force-reload)
    # Reload INN.
    <pathbin>/ctlinnd -t 20 reload '' 'reload asked'
    ;;

restart)
    # Restart INN.
    if [ -f '<pathrun>/innd.pid' ]; then
        <pathbin>/ctlinnd -t 20 throttle 'restart asked' > /dev/null || true
        <pathbin>/ctlinnd -t 20 xexec innd > /dev/null || start
    else
        start
    fi
    ;;

*)
    echo "Recognized arguments: start|stop|reload|force-reload|restart" >&2
    exit 1
    ;;

esac

exit 0

