|
Lines 11-23
Link Here
|
| 11 |
# |
11 |
# |
| 12 |
# apcupsd_enable (bool): Set to "NO" by default. |
12 |
# apcupsd_enable (bool): Set to "NO" by default. |
| 13 |
# Set it to "YES" to enable apcupsd. |
13 |
# Set it to "YES" to enable apcupsd. |
| 14 |
# apcupsd_args (str): Custom additional arguments to be passed |
14 |
# apcupsd_flags (str): Custom additional arguments to be passed |
| 15 |
# to apcupsd (default empty). |
15 |
# to apcupsd (default --kill-on-powerfail). |
|
|
16 |
# apcupsd_configs (str): A list of configs to run multiple instances. |
| 16 |
# |
17 |
# |
| 17 |
|
18 |
|
| 18 |
. /etc/rc.subr |
19 |
. /etc/rc.subr |
| 19 |
|
20 |
|
| 20 |
name="apcupsd" |
21 |
name=apcupsd |
| 21 |
rcvar=apcupsd_enable |
22 |
rcvar=apcupsd_enable |
| 22 |
|
23 |
|
| 23 |
load_rc_config $name |
24 |
load_rc_config $name |
|
Lines 24-34
Link Here
|
| 24 |
|
25 |
|
| 25 |
: ${apcupsd_enable="NO"} |
26 |
: ${apcupsd_enable="NO"} |
| 26 |
: ${apcupsd_flags="--kill-on-powerfail"} |
27 |
: ${apcupsd_flags="--kill-on-powerfail"} |
| 27 |
: ${apcupsd_pidfile="/var/run/apcupsd.pid"} |
|
|
| 28 |
: ${apcupsd_lockfile="/var/spool/lock/apcupsd.lock"} |
| 29 |
|
28 |
|
| 30 |
pidfile="/var/run/apcupsd.pid" |
29 |
pidfile=/var/run/${name}.pid |
| 31 |
required_files="%%ETCDIR%%/apcupsd.conf" |
30 |
required_files="${apcupsd_configs:-%%ETCDIR%%/apcupsd.conf}" |
| 32 |
command="%%PREFIX%%/sbin/apcupsd" |
31 |
command=%%PREFIX%%/sbin/${name} |
|
|
32 |
restart_cmd=${name}_restart_cmd |
| 33 |
|
33 |
|
| 34 |
run_rc_command "$1" |
34 |
apcupsd_precmd() |
|
|
35 |
{ |
| 36 |
config=$1 |
| 37 |
|
| 38 |
dn="`/usr/bin/dirname ${pidfile}`" |
| 39 |
if [ -n "${config}" ]; then |
| 40 |
# Specific config |
| 41 |
base="`/usr/bin/basename ${config} .conf`" |
| 42 |
pidfile="${dn}/${base}.pid" |
| 43 |
command_args="-f ${config} -P ${pidfile}" |
| 44 |
else |
| 45 |
# Default config |
| 46 |
command_args="" |
| 47 |
fi |
| 48 |
} |
| 49 |
|
| 50 |
apcupsd_restart_cmd() |
| 51 |
{ |
| 52 |
if [ -n "${apcupsd_configs}" ]; then |
| 53 |
# One or more named configs |
| 54 |
for config in ${apcupsd_configs}; do |
| 55 |
apcupsd_precmd ${config} |
| 56 |
run_rc_command stop |
| 57 |
done |
| 58 |
for config in ${apcupsd_configs}; do |
| 59 |
apcupsd_precmd ${config} |
| 60 |
run_rc_command start |
| 61 |
done |
| 62 |
else |
| 63 |
# Default config |
| 64 |
apcupsd_precmd |
| 65 |
run_rc_command stop |
| 66 |
run_rc_command start |
| 67 |
fi |
| 68 |
} |
| 69 |
|
| 70 |
if [ "$1" = restart ]; then |
| 71 |
apcupsd_precmd |
| 72 |
run_rc_command $1 |
| 73 |
elif [ -n "${apcupsd_configs}" ]; then |
| 74 |
# One or more named configs |
| 75 |
for config in ${apcupsd_configs}; do |
| 76 |
apcupsd_precmd ${config} |
| 77 |
run_rc_command $1 |
| 78 |
done |
| 79 |
else |
| 80 |
# Default config |
| 81 |
apcupsd_precmd |
| 82 |
run_rc_command $1 |
| 83 |
fi |