3
# Provides: nut-client upsmon ups-monitor
4
# Required-Start: $local_fs $syslog $network $remote_fs
5
# Required-Stop: $local_fs $syslog $network $remote_fs
6
# Should-Start: nut-server
8
# Default-Start: 2 3 4 5
10
# Short-Description: Network UPS Tools monitor initscript
11
# Description: This script take care of starting and stopping the
12
# Network UPS Tools monitoring component (upsmon).
15
# Author: Arnaud Quette <aquette@debian.org>
17
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin
20
DESC="NUT - power device monitor and shutdown controller"
21
CONFIG=/etc/nut/nut.conf
23
upsmon_pid=${pid_dir}/upsmon.pid
25
log=">/dev/null 2>/dev/null"
27
# Define LSB log_* functions.
28
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
29
. /lib/lsb/init-functions
31
# set upsmon specific options. use "man upsmon" for more info
32
# this parameter is now located in nut.conf, and not in /etc/default/nut anymore
33
# FIXME: retrieved from 'nut' script during update
36
# Exit if the package is not installed
37
[ -x "$upsmon" ] || exit 0
39
# Include NUT nut.conf
40
[ -r $CONFIG ] && . $CONFIG
42
# FIXME: put all common bits, between nut-client and nut-server,
43
# into a common nut-function
45
# Explicitly require the configuration to be done in /etc/nut/nut.conf
46
if [ "x$MODE" = "xnone" -o -z "$MODE" ] ; then
47
log_action_msg "$NAME disabled, please adjust the configuration to your needs"
48
log_action_msg "Then set MODE to a suitable value in $CONFIG to enable it"
49
# exit success to avoid breaking the install process!
53
# Check if /var/run/nut exists and has the correct perms
54
check_var_directory() {
55
[ ! -d ${pid_dir} ] && mkdir -p ${pid_dir} \
56
&& chown root:nut ${pid_dir} \
57
&& chmod 770 ${pid_dir} \
58
&& [ -x /sbin/restorecon ] && /sbin/restorecon ${pid_dir}
61
# check if the right components are running
64
standalone|netserver|netclient)
65
status_of_proc -p $upsmon_pid $upsmon upsmon
72
start_stop_client () {
74
standalone|netserver|netclient)
75
# FIXME: for standalone|netserver, ensure 'nut-server status' returns ?
78
start-stop-daemon -S -q -p $upsmon_pid -x $upsmon \
79
-- $UPSMON_OPTIONS >/dev/null 2>&1 && return 0 || return 1
82
start-stop-daemon -K -o -q -p $upsmon_pid -n upsmon >/dev/null 2>&1 \
83
&& return 0 || return 1
96
log_daemon_msg "Starting $DESC" "$NAME"
98
start_stop_client start
103
log_daemon_msg "Stopping $DESC" "$NAME"
104
start_stop_client stop
109
log_daemon_msg "Reloading $DESC" "$NAME"
110
$upsmon -c reload >/dev/null 2>&1
114
restart|force-reload)
115
# FIXME: lack consistency, due to initscript split.
116
# This only addresses partial reload.
117
# Full reload requires to:
119
# - restart (Ie stop+start) nut-server
121
log_daemon_msg "Restarting $DESC" "$NAME"
122
start_stop_client stop || true
123
# should then 'start_stop_server stop', Ie /etc/init.d/nut-server stop
126
# should first 'start_stop_server start', Ie /etc/init.d/nut-server start
127
start_stop_client start
132
#log_daemon_msg "Checking status of $DESC"
133
echo "Checking status of $DESC"
140
standalone|netserver)
142
flag=`sed -ne 's#^ *POWERDOWNFLAG *\(.*\)$#\1#p' /etc/nut/upsmon.conf`
143
if [ -z "$flag" ] ; then
144
log_action_msg "##########################################################"
145
log_action_msg "## POWERDOWNFLAG is not defined in /etc/nut/upsmon.conf ##"
146
log_action_msg "## ##"
147
log_action_msg "## Please read the Manual page upsmon.conf(5) ##"
148
log_action_msg "##########################################################"
152
# Defer to nut-server to actually poweroff the UPS, if needed
153
# (the need is tested here though!)
154
if $upsmon -K >/dev/null 2>&1 ; then
155
log_daemon_msg "UPS poweroff required..."
157
if [ -x /etc/init.d/nut-server ] ; then
158
exec /etc/init.d/nut-server poweroff
160
log_action_msg "Failure: /etc/init.d/nut-server script missing"
163
log_action_msg "Power down flag is not set (UPS poweroff not needed)"
168
log_action_msg "'$MODE' configuration does not require UPS poweroff"
175
echo "Usage: $N {start|stop|reload|restart|force-reload|status|poweroff}" >&2