4 # Required-Start: $local_fs $syslog $network
5 # Required-Stop: $local_fs $syslog $network
6 # Default-Start: 2 3 4 5
8 # Short-Description: Network UPS Tools initscript
9 # Description: This script take care of starting and stopping the
10 # Network UPS Tools components. When needed, it also
11 # handle the UPS hardware shutdown.
14 # Author: Arnaud Quette <aquette@debian.org>
16 PATH
=/sbin
:/usr
/sbin
:/bin
:/usr
/bin
:/usr
/local
/sbin
:/usr
/local
/bin
19 DESC
="Network UPS Tools"
20 DEFAULT
=/etc
/sysconfig
/nut
21 CONFIG
=/etc
/nut
/nut.conf
26 # set upsd specific options. use "man upsd" for more info
29 # set upsmon specific options. use "man upsmon" for more info
32 # Include defaults if available (transition period)
33 if [ -f $DEFAULT ] ; then
37 # Include NUT nut.conf
38 if [ -f $CONFIG ] ; then
42 # Explicitly require the configuration to be done in /etc/nut/nut.conf
43 if [ "x$MODE" = "xnone" ] ; then
44 log_failure_msg
"$NAME disabled, please adjust the configuration to your needs "
45 log_failure_msg
"and then set MODE to a suitable value in $CONFIG to enable it."
46 # exit success to avoid breaking the install process!
51 upsmon_pid
=${pid_dir}/upsmon.pid
52 upsd_pid
=${pid_dir}/upsd.pid
54 upsdrvctl
=/usr
/bin
/upsdrvctl
55 upsmon
=/usr
/sbin
/upsmon
56 log
=">/dev/null 2>/dev/null"
58 # Check if /var/run/nut exists and has the correct perms
59 check_var_directory
() {
60 [ ! -d ${pid_dir} ] && mkdir
-p ${pid_dir} \
61 && chown root
:nut
${pid_dir} \
62 && chmod 770 ${pid_dir}
65 start_stop_server
() {
70 ! $upsdrvctl start
>/dev
/null
2>&1 && boot_mesg
"(upsdrvctl failed)"
71 $upsd $UPSD_OPTIONS >/dev
/null
2>&1
74 $upsd -c stop
>/dev
/null
2>&1
75 ! $upsdrvctl stop
>/dev
/null
2>&1 && boot_mesg
"(upsdrvctl failed)"
85 start_stop_client
() {
87 standalone|netserver|netclient
)
90 $upsmon $UPSMON_OPTIONS >/dev
/null
2>&1
93 $upsmon -c stop
>/dev
/null
2>&1
106 boot_mesg
"Starting $DESC"
108 start_stop_server start
109 start_stop_client start
113 boot_mesg
"Stopping $DESC"
114 start_stop_server stop
115 start_stop_client stop
119 $upsd -c reload
>/dev
/null
2>&1
120 $upsmon -c reload
>/dev
/null
2>&1
123 restart|force-reload
)
124 boot_mesg
"Restarting $DESC"
125 start_stop_client stop
126 start_stop_server stop
129 start_stop_server start
130 start_stop_client start
134 flag
=`sed -ne 's#^ *POWERDOWNFLAG *\(.*\)$#\1#p' /etc/nut/upsmon.conf`
135 wait_delay
=`sed -ne 's#^ *POWEROFF_WAIT= *\(.*\)$#\1#p' $CONFIG`
136 if [ -f "$flag" ] ; then
137 if $upsmon -K >/dev
/null
2>&1 ; then
138 boot_mesg
"Shutting down the UPS ..."
140 if $upsdrvctl shutdown
; then
142 boot_mesg
"Waiting for UPS to cut the power"
144 boot_mesg
"Shutdown failed."
145 boot_mesg
"Waiting for UPS batteries to run down"
147 if [ "$wait_delay" ] ; then
148 boot_mesg
" (will reboot after $wait_delay) ..."
150 /etc
/init.d
/reboot stop
153 boot_mesg
"Power down flag is not set (UPS shutdown not needed)"
156 if [ -z "$flag" ] ; then
157 boot_mesg
"##########################################################"
158 boot_mesg
"## POWERDOWNFLAG is not defined in /etc/nut/upsmon.conf ##"
160 boot_mesg
"## Please read the Manual page upsmon.conf(5) ##"
161 boot_mesg
"##########################################################"
168 echo "Usage: $N {start|stop|reload|restart|force-reload|poweroff}" >&2