]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/initscripts/packages/nut
suricata: Change midstream policy to "pass-flow"
[people/pmueller/ipfire-2.x.git] / src / initscripts / packages / nut
1 #! /bin/sh
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 ###############################################################################
21
22 PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin
23
24 NAME=nut
25 DESC="Network UPS Tools"
26 DEFAULT=/etc/sysconfig/nut
27 CONFIG=/etc/nut/nut.conf
28
29 . /etc/sysconfig/rc
30 . $rc_functions
31
32 # set upsd specific options. use "man upsd" for more info
33 UPSD_OPTIONS=""
34
35 # set upsmon specific options. use "man upsmon" for more info
36 UPSMON_OPTIONS=""
37
38 # Include defaults if available (transition period)
39 if [ -f $DEFAULT ] ; then
40 . $DEFAULT
41 fi
42
43 # Include NUT nut.conf
44 if [ -f $CONFIG ] ; then
45 . $CONFIG
46 fi
47
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!
53 exit 0
54 fi
55
56 upsd=/usr/sbin/upsd
57 upsdrvctl=/usr/sbin/upsdrvctl
58 upsmon=/usr/sbin/upsmon
59 log=">/dev/null 2>/dev/null"
60
61 start_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
68 evaluate_retval
69 ;;
70 stop)
71 $upsd -c stop >/dev/null 2>&1
72 evaluate_retval
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
83 start_stop_client () {
84 case "$MODE" in
85 standalone|netserver|netclient)
86 case "$1" in
87 start)
88 $upsmon $UPSMON_OPTIONS >/dev/null 2>&1
89 evaluate_retval
90 ;;
91 stop)
92 $upsmon -c stop >/dev/null 2>&1
93 evaluate_retval
94 ;;
95 esac
96 ;;
97 none|*)
98 return 1
99 ;;
100 esac
101 }
102
103 status_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
115 status_client () {
116 case "$MODE" in
117 standalone|netclient)
118 statusproc $upsmon
119 ;;
120 none|*)
121 return 1
122 ;;
123 esac
124 }
125
126 case "$1" in
127
128 start)
129 boot_mesg "Starting $DESC ..."
130 start_stop_server start
131 start_stop_client start
132 ;;
133
134 stop)
135 boot_mesg "Stopping $DESC ..."
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
145 status)
146 status_server
147 status_client
148 ;;
149
150 restart|force-reload)
151 boot_mesg "Restarting $DESC ..."
152 start_stop_client stop
153 start_stop_server stop
154 sleep 5
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
194 echo "Usage: $N {start|stop|status|reload|restart|force-reload|poweroff}" >&2
195 exit 1
196 ;;
197 esac
198
199 exit 0