| 1 |
#!/bin/sh |
| 2 |
# $FreeBSD$ |
| 3 |
# startup scripts for APCUPSD. |
| 4 |
|
| 5 |
if ! PREFIX=$(expr $0 : "\(/.*\)/etc/rc\.d/$(basename $0)\$"); then |
| 6 |
echo "$0: Cannot determine the PREFIX" >&2 |
| 7 |
exit 1 |
| 8 |
fi |
| 9 |
|
| 10 |
# If there is a global system configuration file, suck it in. |
| 11 |
if [ -r /etc/defaults/rc.conf ]; then |
| 12 |
. /etc/defaults/rc.conf |
| 13 |
source_rc_confs |
| 14 |
elif [ -r /etc/rc.conf ]; then |
| 15 |
. /etc/rc.conf |
| 16 |
fi |
| 17 |
|
| 18 |
apcupsd_enable=${apcupsd_enable:-YES} |
| 19 |
apcupsd_program=${apcupsd_program:-${PREFIX}/sbin/apcupsd} |
| 20 |
apcupsd_flags=${apcupsd_flags:-"--kill-on-powerfail"} |
| 21 |
apcupsd_pidfile=${apcupsd_pidfile:-/var/run/apcupsd.pid} |
| 22 |
apcupsd_lockfile=${apcupsd_pidfile:-/var/spool/lock/apcupsd.lock |
| 23 |
|
| 24 |
case $1 in |
| 25 |
start) |
| 26 |
case "${apcupsd_enable}" in |
| 27 |
[Yy][Ee][Ss]) |
| 28 |
rm -f /var/run/powerfail |
| 29 |
rm -f /var/run/nologin |
| 30 |
if [ -f ${apcupsd_program} ]; then |
| 31 |
echo -n " apcupsd" |
| 32 |
${apcupsd_program} ${apcupsd_flags} || return=" Failed." |
| 33 |
touch ${apcupsd_lockfile} |
| 34 |
fi |
| 35 |
;; |
| 36 |
esac |
| 37 |
;; |
| 38 |
|
| 39 |
stop) |
| 40 |
if [ -f ${apcupsd_pidfile} ]; then |
| 41 |
PID=`cat ${apcupsd_pidfile}` |
| 42 |
kill -KILL $PID || return=" Failed." |
| 43 |
rm -f ${apcupsd_pidfile} |
| 44 |
else |
| 45 |
return=" Failed." |
| 46 |
fi |
| 47 |
;; |
| 48 |
|
| 49 |
restart) |
| 50 |
$0 stop |
| 51 |
$0 start; |
| 52 |
;; |
| 53 |
|
| 54 |
status) |
| 55 |
${PREFIX}/sbin/apcaccess status |
| 56 |
;; |
| 57 |
|
| 58 |
*) |
| 59 |
echo "usage: $0 {start|stop|restart|status}" 1>&2 |
| 60 |
;; |
| 61 |
esac |
| 62 |
|
| 63 |
exit 0; |