File rbldnsd.init of Package rbldnsd

#!/bin/bash
#
# Copyright (c) 2010 Stefan Jakobs
# Author: Stefan Jakobs
#
#    This program is free software; you can 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 of the License, or
#    (at your option) any later version.
#
#    This program 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
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# based on the template by SuSE Linux
#
# /etc/init.d/rbldnsd
#
# /usr/local/sbin/rcrbldnsd
#
### BEGIN INIT INFO
# Provides:		rbldnsd
# Required-Start:	$network $remote_fs $syslog
# Should-Start:		$named
# Required-Stop:	$null
# Should-Stop:		$null
# Default-Start:	3 5
# Default-Stop:		0 1 2 6
# Short-Description:	rbldnsd is a DNS daemon
# Description:		rbldnsd is a small and fast DNS daemon which 
#	is especially made to serve DNSBL zones. The daemon can serve
#	both IP-based (ordb.org, dsbl.org etc) and name-based 
#	(rfc-ignorant.org) blocklists.
### END INIT INFO

RBLDNSD_BIN=/usr/sbin/rbldnsd
RBLDNSD_PID=/var/run/rbldnsd.pid
RBLDNSD_CONFIG=/etc/sysconfig/rbldnsd

# Check existence of the binary
test -x $RBLDNSD_BIN || { echo "RBLDNSD_BIN not installed"; exit 5; }

# Check existence of the needed config file
test -r $RBLDNSD_CONFIG || { echo "$RBLDNSD_CONFIG not installed" ;
	if [ "$1" = "stop" ]; then exit 0 ;
	else exit 6; fi; }
# Read config
. $RBLDNSD_CONFIG

if (( $DAEMON == 0 )) ; then DAEMON="-n"; else DAEMON=""; fi
if [[ -n $STATS ]]; then OPTIONS="-s $STATS $OPTIONS" ; fi
if [[ -n $CHROOT ]]; then OPTIONS="-r $CHROOT $OPTIONS"; fi

# Shell functions sourced from /etc/rc.status:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     ditto but be verbose in local rc status
#      rc_status -v -r  ditto and clear the local rc status
#      rc_failed        set local and overall rc status to failed
#      rc_failed <num>  set local and overall rc status to <num><num>
#      rc_reset         clear local rc status (overall remains)
#      rc_exit          exit appropriate to overall rc status
. /etc/rc.status

# Reset status of this service
rc_reset

# Return values acc. to LSB for all commands but status:
# 0 - success
# 1 - generic or unspecified error
# 2 - invalid or excess argument(s)
# 3 - unimplemented feature (e.g. "reload")
# 4 - insufficient privilege
# 5 - program is not installed
# 6 - program is not configured
# 7 - program is not running
# 
# Note that starting an already running service, stopping
# or restarting a not-running service as well as the restart
# with force-reload (in case signalling is not supported) are
# considered a success.


case "$1" in 
    start)
	echo -n "Starting rbldnsd "
	/sbin/startproc $RBLDNSD_BIN $DAEMON -u $USER -l $TTL \
		-l $LOG -p $RBLDNSD_PID -b $IP -c $CHECK_TIME \
		$OPTIONS 

	# Remember status and be verbose
	rc_status -v
	;;
    stop)
	echo -n "Shutting down rbldnsd "
	/sbin/killproc -TERM $RBLDNSD_BIN

        # Remember status and be verbose
        rc_status -v
        ;;
    restart)
        ## Stop the service and regardless of whether it was
        ## running or not, start it again.
        $0 stop
        $0 start

        # Remember status and be quiet
        rc_status
        ;;
    reload|force-reload)
	## Signal the daemon to reload its zone files.
	## It will do this on signal 1 (SIGHUP)

	echo -n "Reload service rbldnsd "
        /sbin/killproc -HUP $RBLDNSD_BIN
	rc_status -v
	;;
    status)
	echo -n "Checking for service rbldnsd "

	/sbin/checkproc -p $RBLDNSD_PID $RBLDNSD_BIN

        # Remember status and be quiet
        rc_status -v
        ;;
    *)
        echo "Usage: $0 {start|stop|status|restart|reload|force-reload}"
        exit 1
        ;;
esac
rc_exit