Subversion Repositories ALCASAR

Rev

Rev 489 | Blame | Last modification | View Log

#!/bin/sh
#
#
####
# This init-script tries to be LSB conform but platform independent.
# 
# Therefore check the following two variables to fit to your requests:
# HAVP_BIN HAVP_CONFIG PIDFILE
# Any configuration of HAVP is done in havp.config
# Type havp --help for help and read havp.config you should have received.
# chkconfig: 2345 11 89
# description: starts HAVP the High Availability Antivirus Proxy
#

. /etc/init.d/functions
HAVP_BIN=/usr/sbin/havp
HAVP_CONFIG=/etc/havp/havp.config
PIDFILE=/var/run/havp/havp.pid
NAME=havp
DESC=havp

test -x $HAVP_BIN || exit 0

# Include havp defaults if available
if [ -f /etc/sysconfig/havp ] ; then
        . /etc/sysconfig/havp
fi

havp_loopback=tmpfs
havp_mountpoint=/var/tmp/havp

#set -e

# Return values acc. to LSB for all commands but status:
# 1       generic or unspecified error (current practice)
# 2       invalid or excess argument(s)
# 3       unimplemented feature (for example, "reload")
# 4       user had insufficient privilege
# 5       program is not installed
# 6       program is not configured
# 7       program is not running
# 8-99    reserved for future LSB use
# 100-149 reserved for distribution use
# 150-199 reserved for application use
# 200-254 reserved
# Note that starting an already running service, stopping
# or restarting a not-running service as well as the restart
# with force-reload (in case signaling is not supported) are
# considered a success.

reload_havp()
{
        echo "Reloading HAVP ..."
        PID="`cat $PIDFILE`"
        if [ "$PID" != "" ]; then
                kill -HUP "$PID" >/dev/null 2>&1
                if [ $? -ne 0 ]; then
                        echo "Error: HAVP not running"
                        exit 1
                fi
        else
                echo "Error: HAVP not running or PIDFILE not readable"
                exit 1
        fi
        exit 0
}

case "$1" in
        start)
                if ! [ "`mount | grep $havp_mountpoint`" ]; then
                        echo -n "Mounting $havp_loopback under $havp_mountpoint ..."
                        mount -t tmpfs -o mand,noatime,size=50m,nosuid,noexec $havp_loopback $havp_mountpoint
                        chown -R havp:havp $havp_mountpoint
                        echo "done"
                fi
                if [ "`mount | grep $havp_mountpoint`" ]; then
                        echo -n "Cleaning up $havp_mountpoint"...
                        find $havp_mountpoint/ -type f -delete
                        echo " done"
                        echo -n "Starting $DESC: "
                        if [ ! -f $HAVP_BIN ]; then
                                echo "Error: $HAVP_BIN not found"
                                exit 5
                        fi
                        $HAVP_BIN -c $HAVP_CONFIG
                else
                       echo "Error: mount tmpfs point failed"
                fi
                exit $?
                ;;

        stop)
                echo "Shutting down $NAME ..."
                if [ ! -f "$PIDFILE" ]; then
                  echo "Error: HAVP not running or PIDFILE unreadable"
                  exit 1
                fi
                PID="`cat $PIDFILE`"
                if [ "$PID" != "" ]; then
                        kill -TERM "$PID" >/dev/null 2>&1
                        if [ $? -ne 0 ]; then
                                echo "Error: HAVP not running"
                                exit 1
                        fi
                else
                        echo "Error: HAVP not running or PIDFILE unreadable"
                        exit 1
                fi
                if [ "`mount | grep $havp_mountpoint`" ]; then
                        echo -n "Cleaning up $havp_mountpoint"...
                        find $havp_mountpoint/ -type f -delete
                        echo " done"
                        echo -n "Unmounting $havp_mountpoint ..."
                        umount $havp_mountpoint
                        echo "done"
                fi
                exit 0
                ;;

        restart)
                echo "Shutting down HAVP ..."
                $0 stop >/dev/null 2>&1
                $0 start
                exit $?
                ;;

        reload-lists)
                reload_havp
                ;;

        force-reload)
                reload_havp
                ;;

        reload)
                reload_havp
                ;;

        status)
                status havp
                exit 4
                ;;

        *)
                N=/etc/init.d/$NAME
                echo "Usage: $N {start|stop|status|restart|force-reload|reload|reload-lists}"
                exit 0
                ;;
esac

exit 0