pen/init.pen

97 lines
2.2 KiB
Plaintext
Raw Normal View History

#! /bin/sh
# Copyright (c) 1995-2004 SUSE LINUX AG, Germany.
#
# Author: joe@suse.de, template by ro@suse.de
# using parts from Torsten.Goedicke@wlw.de
#
# /etc/init.d/pen
# and its symbolic link
# /usr/sbin/rcpen
#
### BEGIN INIT INFO
# Provides: pen
# Required-Start: $time $named $syslog
# Required-Stop:
# Default-Start: 3 5
# Default-Stop: 0 1 2 4 6
# Description: A simple load balancer for tcp based protocols
### END INIT INFO
. /etc/rc.status
JOBNAME="$0"
NAME=pen
DAEMON=/usr/bin/run$NAME.sh
CF=/etc/$NAME.cfg
PIDDIR="/var/run"
PIDALL="$PIDDIR/run$NAME.pid"
if [ -f $CF ]; then
. $CF
else
echo "Error: Configuration file $CF not found" && exit 0
fi
# Determine the base and follow a runlevel link name.
base=${0##*/}
link=${base#*[SK][0-9][0-9]}
# Force execution if not called by a runlevel directory.
test -x $DAEMON || exit 0
rc_reset
case "$1" in
start)
PID=`$PS | grep $NAME | grep -v grep | grep -v $JOBNAME`
if [ -n "$PID" ]; then
echo "$NAME load balancer is already running as"
echo "$PID"
else
echo -n "Starting pen load balancer instances"
for i in $COUNT
do
eval PIDFILE=\$PID${i}
eval OPTIONS=\$PEN${i}
CFFILE=`echo $PIDFILE | sed 's/pid/conf/'`
echo $OPTIONS > $CFFILE
$DAEMON $CFFILE &
echo $! >> $PIDALL
done
fi
rc_status -v
;;
stop)
echo -n "Shutting down pen load balancer instances"
test -f $PIDALL && kill -TERM `cat $PIDALL` 2> /dev/null
test -f $PIDALL && kill -KILL `cat $PIDALL` 2> /dev/null
rm -f $PIDALL
for i in $COUNT
do
eval PIDFILE=\$PID${i}
eval OPTIONS=\$PEN${i}
CFFILE=`echo $PIDFILE | sed 's/pid/conf/'`
test -f $PIDFILE && kill -TERM `cat $PIDFILE` 2> /dev/null
rm -f $PIDFILE $CFFILE
done
rc_status -v
;;
restart)
echo -n "Restarting pen load balancer instances"
for i in $COUNT
do
eval PIDFILE=\$PID${i}
eval OPTIONS=\$PEN${i}
CFFILE=`echo $PIDFILE | sed 's/pid/conf/'`
echo $OPTIONS > $CFFILE
kill -TERM `cat $PIDFILE`
done
rc_status -v
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
rc_exit