]> git.ipfire.org Git - ipfire-2.x.git/blame - src/initscripts/packages/nut
Early spring clean: Remove trailing whitespaces, and correct licence headers
[ipfire-2.x.git] / src / initscripts / packages / nut
CommitLineData
4ad79fe6 1#! /bin/sh
66c36198
PM
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> #
6# #
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. #
11# #
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. #
16# #
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/>. #
19# #
20###############################################################################
4ad79fe6
AF
21
22PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin
23
24NAME=nut
25DESC="Network UPS Tools"
26DEFAULT=/etc/sysconfig/nut
27CONFIG=/etc/nut/nut.conf
28
29. /etc/sysconfig/rc
30. $rc_functions
31
32# set upsd specific options. use "man upsd" for more info
33UPSD_OPTIONS=""
34
35# set upsmon specific options. use "man upsmon" for more info
36UPSMON_OPTIONS=""
37
38# Include defaults if available (transition period)
39if [ -f $DEFAULT ] ; then
40 . $DEFAULT
41fi
42
43# Include NUT nut.conf
44if [ -f $CONFIG ] ; then
45 . $CONFIG
46fi
47
48# Explicitly require the configuration to be done in /etc/nut/nut.conf
49if [ "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!
53 exit 0
54fi
55
4ad79fe6 56upsd=/usr/sbin/upsd
3fe41c01 57upsdrvctl=/usr/sbin/upsdrvctl
4ad79fe6
AF
58upsmon=/usr/sbin/upsmon
59log=">/dev/null 2>/dev/null"
60
4ad79fe6
AF
61start_stop_server () {
62 case "$MODE" in
63 standalone|netserver)
64 case "$1" in
65 start)
66 ! $upsdrvctl start >/dev/null 2>&1 && boot_mesg "(upsdrvctl failed)"
67 $upsd $UPSD_OPTIONS >/dev/null 2>&1
df2aa8e1 68 evaluate_retval
4ad79fe6
AF
69 ;;
70 stop)
71 $upsd -c stop >/dev/null 2>&1
df2aa8e1 72 evaluate_retval
4ad79fe6
AF
73 ! $upsdrvctl stop >/dev/null 2>&1 && boot_mesg "(upsdrvctl failed)"
74 ;;
75 esac
76 ;;
77 none|netclient|*)
78 return 1
79 ;;
80 esac
81}
82
83start_stop_client () {
84 case "$MODE" in
85 standalone|netserver|netclient)
86 case "$1" in
87 start)
88 $upsmon $UPSMON_OPTIONS >/dev/null 2>&1
df2aa8e1 89 evaluate_retval
4ad79fe6
AF
90 ;;
91 stop)
92 $upsmon -c stop >/dev/null 2>&1
df2aa8e1 93 evaluate_retval
4ad79fe6
AF
94 ;;
95 esac
96 ;;
97 none|*)
98 return 1
99 ;;
100 esac
101}
102
df2aa8e1
DW
103status_server () {
104 case "$MODE" in
105 standalone|netserver)
106 statusproc $upsd
107 statusproc $upsmon
108 ;;
109 none|netclient|*)
110 return 1
111 ;;
112 esac
113}
114
115status_client () {
116 case "$MODE" in
117 standalone|netclient)
118 statusproc $upsmon
119 ;;
120 none|*)
121 return 1
122 ;;
123 esac
124}
125
4ad79fe6
AF
126case "$1" in
127
128 start)
df2aa8e1 129 boot_mesg "Starting $DESC ..."
4ad79fe6
AF
130 start_stop_server start
131 start_stop_client start
132 ;;
133
134 stop)
df2aa8e1 135 boot_mesg "Stopping $DESC ..."
4ad79fe6
AF
136 start_stop_server stop
137 start_stop_client stop
138 ;;
139
140 reload)
141 $upsd -c reload >/dev/null 2>&1
142 $upsmon -c reload >/dev/null 2>&1
143 ;;
144
df2aa8e1
DW
145 status)
146 status_server
147 status_client
148 ;;
149
4ad79fe6 150 restart|force-reload)
df2aa8e1 151 boot_mesg "Restarting $DESC ..."
4ad79fe6
AF
152 start_stop_client stop
153 start_stop_server stop
154 sleep 5
4ad79fe6
AF
155 start_stop_server start
156 start_stop_client start
157 ;;
158
159 poweroff)
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 ..."
165 sleep 1
166 if $upsdrvctl shutdown ; then
167 sleep 5
168 boot_mesg "Waiting for UPS to cut the power"
169 else
170 boot_mesg "Shutdown failed."
171 boot_mesg "Waiting for UPS batteries to run down"
172 fi
173 if [ "$wait_delay" ] ; then
174 boot_mesg " (will reboot after $wait_delay) ..."
175 sleep "$wait_delay"
176 /etc/init.d/reboot stop
177 fi
178 else
179 boot_mesg "Power down flag is not set (UPS shutdown not needed)"
180 fi
181 else
182 if [ -z "$flag" ] ; then
183 boot_mesg "##########################################################"
184 boot_mesg "## POWERDOWNFLAG is not defined in /etc/nut/upsmon.conf ##"
185 boot_mesg "## ##"
186 boot_mesg "## Please read the Manual page upsmon.conf(5) ##"
187 boot_mesg "##########################################################"
188 fi
189 fi
190 ;;
191
192 *)
193 N=/etc/init.d/$NAME
df2aa8e1 194 echo "Usage: $N {start|stop|status|reload|restart|force-reload|poweroff}" >&2
4ad79fe6
AF
195 exit 1
196 ;;
197esac
198
199exit 0