I'm trying to port this script over to start multiple instances of APCUPSD with different config files.
If this is in the wrong forum, I'm sorry. Thanks for any help you can provide.
If this is in the wrong forum, I'm sorry. Thanks for any help you can provide.
Code:
#!/bin/sh
### BEGIN INFO
# Provides: apcupsd
# Required-Start: $syslog
# Required-Stop: $syslog
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts apcupsd daemon
# Description: apcupsd provides UPS power management for APC products.
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/sbin/apcupsd
CONFIG=/usr/local/etc/apcupsd
NAME=apcupsd
DESC="UPS power management"
test -x $DAEMON || exit 0
test -e $CONFIG || exit 0
set -e
. $CONFIG
#if [ $ISCONFIGURED = no ]
#then
# echo "Please check your configuration ISCONFIGURED in /etc/default/apcupsd"
# exit 0
#fi
case "$1" in
start)
rm -f /usr/local/etc/apcupsd/powerfail
for conf in /usr/local/etc/apcupsd/apcupsd.*.conf ; do
inst=`basename $conf`
echo -n "Starting UPS monitoring ($inst):"
if [ "`pidof apcupsd-$inst`" = "" ]
then
start-stop-daemon --start --quiet --exec /usr/local/sbin/apcupsd --pidfile /var/run/apcupsd-$inst.pid -- -f $conf
# note the above is on ONE line in the script #
echo "$NAME."
else
echo ""
echo "A copy of the daemon is still running. If you just stopped it,"
echo "please wait about 5 seconds for it to shut down."
exit 0
fi
done
;;
stop)
for conf in /usr/local/etc/apcupsd/apcupsd.*.conf ; do
inst=`basename $conf`
echo -n "Shutting down UPS monitoring ($inst):"
start-stop-daemon --stop oknodo --pidfile /var/run/apcupsd-$inst.pid || echo "Not Running."
rm -f /var/run/apcupsd-$inst.pid
done
;;
restart|force-reload)
$0 stop
sleep 15
$0 start
;;
reload)
echo "$0: reload not implemented"
exit 3
;;
status)
for conf in /usr/local/etc/apcupsd/apcupsd.*.conf ; do
inst=`basename $conf`
status -p /var/run/apcupsd-$inst.pid apcupsd-$inst
RETVAL=$?
if [ $RETVAL -eq 0 ]
then
NISPORT=`grep ^NISPORT < $conf | sed -e "s/NISPORT *\([0-9]\)/\1/"`
/usr/local/sbin/apcaccess status localhost:$NISPORT | egrep "(STATUS)|(UPSNAME)"
fi
done
;;
*)
# N=/etc/init.d/$NAME
N=/sbin/init/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0