1
0
mirror of https://git.FreeBSD.org/ports.git synced 2024-11-29 01:13:08 +00:00
freebsd-ports/sysutils/apcupsd/files/apcupsd.sh.sample

66 lines
1.3 KiB
Bash

#!/bin/sh
# $FreeBSD$
# startup scripts for APCUPSD.
if ! PREFIX=$(expr $0 : "\(/.*\)/etc/rc\.d/$(basename $0)\$"); then
echo "$0: Cannot determine the PREFIX" >&2
exit 1
fi
# If there is a global system configuration file, suck it in.
if [ -r /etc/defaults/rc.conf ]; then
. /etc/defaults/rc.conf
source_rc_confs
elif [ -r /etc/rc.conf ]; then
. /etc/rc.conf
fi
apcupsd_enable=${apcupsd_enable:-YES}
apcupsd_program=${apcupsd_program:-${PREFIX}/sbin/apcupsd}
apcupsd_flags=${apcupsd_flags:-"--kill-on-powerfail"}
apcupsd_pidfile=${apcupsd_pidfile:-/var/run/apcupsd.pid}
apcupsd_lockfile=${apcupsd_pidfile:-/var/spool/lock/apcupsd.lock}
case $1 in
start)
case "${apcupsd_enable}" in
[Yy][Ee][Ss])
rm -f /var/run/powerfail
rm -f /var/run/nologin
if [ -f ${apcupsd_program} ]; then
echo -n " apcupsd"
${apcupsd_program} ${apcupsd_flags} || return=" Failed."
touch ${apcupsd_lockfile}
fi
;;
esac
;;
stop)
if [ -f ${apcupsd_pidfile} ]; then
PID=`cat ${apcupsd_pidfile}`
kill -KILL $PID || return=" Failed."
rm -f ${apcupsd_pidfile}
# some slaves won't die
killall apcupsd
else
return=" Failed."
fi
;;
restart)
$0 stop
$0 start;
;;
status)
${PREFIX}/sbin/apcaccess status
;;
*)
echo "usage: $0 {start|stop|restart|status}" 1>&2
;;
esac
exit 0;