2
###############################################################################
4
# IPFire.org - A linux based firewall #
5
# Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> #
7
# This program is free software: you can redistribute it and/or modify #
8
# it under the terms of the GNU General Public License as published by #
9
# the Free Software Foundation, either version 3 of the License, or #
10
# (at your option) any later version. #
12
# This program is distributed in the hope that it will be useful, #
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15
# GNU General Public License for more details. #
17
# You should have received a copy of the GNU General Public License #
18
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
20
###############################################################################
22
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin
25
DESC="Network UPS Tools"
26
DEFAULT=/etc/sysconfig/nut
27
CONFIG=/etc/nut/nut.conf
32
# set upsd specific options. use "man upsd" for more info
35
# set upsmon specific options. use "man upsmon" for more info
38
# Include defaults if available (transition period)
39
if [ -f $DEFAULT ] ; then
43
# Include NUT nut.conf
44
if [ -f $CONFIG ] ; then
48
# Explicitly require the configuration to be done in /etc/nut/nut.conf
49
if [ "x$MODE" = "xnone" ] ; then
50
log_failure_msg "$NAME disabled, please adjust the configuration to your needs "
51
log_failure_msg "and then set MODE to a suitable value in $CONFIG to enable it."
52
# exit success to avoid breaking the install process!
57
upsdrvctl=/usr/sbin/upsdrvctl
58
upsmon=/usr/sbin/upsmon
59
log=">/dev/null 2>/dev/null"
61
start_stop_server () {
66
! $upsdrvctl start >/dev/null 2>&1 && boot_mesg "(upsdrvctl failed)"
67
$upsd $UPSD_OPTIONS >/dev/null 2>&1
71
$upsd -c stop >/dev/null 2>&1
73
! $upsdrvctl stop >/dev/null 2>&1 && boot_mesg "(upsdrvctl failed)"
83
start_stop_client () {
85
standalone|netserver|netclient)
88
$upsmon $UPSMON_OPTIONS >/dev/null 2>&1
92
$upsmon -c stop >/dev/null 2>&1
105
standalone|netserver)
117
standalone|netclient)
129
boot_mesg "Starting $DESC ..."
130
start_stop_server start
131
start_stop_client start
135
boot_mesg "Stopping $DESC ..."
136
start_stop_server stop
137
start_stop_client stop
141
$upsd -c reload >/dev/null 2>&1
142
$upsmon -c reload >/dev/null 2>&1
150
restart|force-reload)
151
boot_mesg "Restarting $DESC ..."
152
start_stop_client stop
153
start_stop_server stop
155
start_stop_server start
156
start_stop_client start
160
flag=`sed -ne 's#^ *POWERDOWNFLAG *\(.*\)$#\1#p' /etc/nut/upsmon.conf`
161
wait_delay=`sed -ne 's#^ *POWEROFF_WAIT= *\(.*\)$#\1#p' $CONFIG`
162
if [ -f "$flag" ] ; then
163
if $upsmon -K >/dev/null 2>&1 ; then
164
boot_mesg "Shutting down the UPS ..."
166
if $upsdrvctl shutdown ; then
168
boot_mesg "Waiting for UPS to cut the power"
170
boot_mesg "Shutdown failed."
171
boot_mesg "Waiting for UPS batteries to run down"
173
if [ "$wait_delay" ] ; then
174
boot_mesg " (will reboot after $wait_delay) ..."
176
/etc/init.d/reboot stop
179
boot_mesg "Power down flag is not set (UPS shutdown not needed)"
182
if [ -z "$flag" ] ; then
183
boot_mesg "##########################################################"
184
boot_mesg "## POWERDOWNFLAG is not defined in /etc/nut/upsmon.conf ##"
186
boot_mesg "## Please read the Manual page upsmon.conf(5) ##"
187
boot_mesg "##########################################################"
194
echo "Usage: $N {start|stop|status|reload|restart|force-reload|poweroff}" >&2