#!/sbin/runscript
# Copyright 1999-2003 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2         
# $Header: /home/mbr/cvs/fwknop/init-scripts/fwknop-init.gentoo,v 1.3 2004/07/08 21:42:27 mbr Exp $

depend() {
        need logger
}

checkconfig() {
        if [ ! -f /etc/fwknop/fwknop.conf ] ; then
                eerror "Please create /etc/fwknop/fwknop.conf"
                eerror "You can find a sample config file at /etc/fwknop/fwknop.conf.sample"
                return 1
        fi
        return 0
}

start() {
        checkconfig || return $?

        ebegin "Starting fwknop"
        start-stop-daemon --start --quiet --pidfile /var/run/fwknop/fwknop.pid \
                --exec /usr/bin/fwknop
        eend $? "Failed to start fwknop"
}

stop() {
        ebegin "Stopping knopmd"
        start-stop-daemon --stop --quiet --pidfile /var/run/fwknop/knopmd.pid
        eend $? "Failed to stop knopmd"

        ebegin "Stopping fwknop"
        start-stop-daemon --stop --quiet --pidfile /var/run/fwknop/fwknop.pid
        eend $? "Failed to stop fwknop"

        ebegin "Stopping knopwatchd"
        start-stop-daemon --stop --quiet --pidfile /var/run/fwknop/knopwatchd.pid
        eend $? "Failed to stop knopwatchd"

        # clean stale pidfiles
        [ -f /var/run/fwknop/fwknop.pid ] && rm -f /var/run/fwknop/fwknop.pid
        [ -f /var/run/fwknop/knopwatchd.pid ] && rm -f /var/run/fwknop/knopwatchd.pid
        [ -f /var/run/fwknop/knopmd.pid ] && rm -f /var/run/fwknop/knopmd.pid
}
