nut addon: Update to 2.7.2
[people/teissler/ipfire-2.x.git] / src / initscripts / init.d / nut
1 #! /bin/sh
2
3 PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin
4
5 NAME=nut
6 DESC="Network UPS Tools"
7 DEFAULT=/etc/sysconfig/nut
8 CONFIG=/etc/nut/nut.conf
9
10 . /etc/sysconfig/rc
11 . $rc_functions
12
13 # set upsd specific options. use "man upsd" for more info
14 UPSD_OPTIONS=""
15
16 # set upsmon specific options. use "man upsmon" for more info
17 UPSMON_OPTIONS=""
18
19 # Include defaults if available (transition period)
20 if [ -f $DEFAULT ] ; then
21 . $DEFAULT
22 fi
23
24 # Include NUT nut.conf
25 if [ -f $CONFIG ] ; then
26 . $CONFIG
27 fi
28
29 # Explicitly require the configuration to be done in /etc/nut/nut.conf
30 if [ "x$MODE" = "xnone" ] ; then
31 log_failure_msg "$NAME disabled, please adjust the configuration to your needs "
32 log_failure_msg "and then set MODE to a suitable value in $CONFIG to enable it."
33 # exit success to avoid breaking the install process!
34 exit 0
35 fi
36
37 upsd=/usr/sbin/upsd
38 upsdrvctl=/usr/sbin/upsdrvctl
39 upsmon=/usr/sbin/upsmon
40 log=">/dev/null 2>/dev/null"
41
42 start_stop_server () {
43 case "$MODE" in
44 standalone|netserver)
45 case "$1" in
46 start)
47 ! $upsdrvctl start >/dev/null 2>&1 && boot_mesg "(upsdrvctl failed)"
48 $upsd $UPSD_OPTIONS >/dev/null 2>&1
49 evaluate_retval
50 ;;
51 stop)
52 $upsd -c stop >/dev/null 2>&1
53 evaluate_retval
54 ! $upsdrvctl stop >/dev/null 2>&1 && boot_mesg "(upsdrvctl failed)"
55 ;;
56 esac
57 ;;
58 none|netclient|*)
59 return 1
60 ;;
61 esac
62 }
63
64 start_stop_client () {
65 case "$MODE" in
66 standalone|netserver|netclient)
67 case "$1" in
68 start)
69 $upsmon $UPSMON_OPTIONS >/dev/null 2>&1
70 evaluate_retval
71 ;;
72 stop)
73 $upsmon -c stop >/dev/null 2>&1
74 evaluate_retval
75 ;;
76 esac
77 ;;
78 none|*)
79 return 1
80 ;;
81 esac
82 }
83
84 status_server () {
85 case "$MODE" in
86 standalone|netserver)
87 statusproc $upsd
88 statusproc $upsmon
89 ;;
90 none|netclient|*)
91 return 1
92 ;;
93 esac
94 }
95
96 status_client () {
97 case "$MODE" in
98 standalone|netclient)
99 statusproc $upsmon
100 ;;
101 none|*)
102 return 1
103 ;;
104 esac
105 }
106
107 case "$1" in
108
109 start)
110 boot_mesg "Starting $DESC ..."
111 start_stop_server start
112 start_stop_client start
113 ;;
114
115 stop)
116 boot_mesg "Stopping $DESC ..."
117 start_stop_server stop
118 start_stop_client stop
119 ;;
120
121 reload)
122 $upsd -c reload >/dev/null 2>&1
123 $upsmon -c reload >/dev/null 2>&1
124 ;;
125
126 status)
127 status_server
128 status_client
129 ;;
130
131 restart|force-reload)
132 boot_mesg "Restarting $DESC ..."
133 start_stop_client stop
134 start_stop_server stop
135 sleep 5
136 start_stop_server start
137 start_stop_client start
138 ;;
139
140 poweroff)
141 flag=`sed -ne 's#^ *POWERDOWNFLAG *\(.*\)$#\1#p' /etc/nut/upsmon.conf`
142 wait_delay=`sed -ne 's#^ *POWEROFF_WAIT= *\(.*\)$#\1#p' $CONFIG`
143 if [ -f "$flag" ] ; then
144 if $upsmon -K >/dev/null 2>&1 ; then
145 boot_mesg "Shutting down the UPS ..."
146 sleep 1
147 if $upsdrvctl shutdown ; then
148 sleep 5
149 boot_mesg "Waiting for UPS to cut the power"
150 else
151 boot_mesg "Shutdown failed."
152 boot_mesg "Waiting for UPS batteries to run down"
153 fi
154 if [ "$wait_delay" ] ; then
155 boot_mesg " (will reboot after $wait_delay) ..."
156 sleep "$wait_delay"
157 /etc/init.d/reboot stop
158 fi
159 else
160 boot_mesg "Power down flag is not set (UPS shutdown not needed)"
161 fi
162 else
163 if [ -z "$flag" ] ; then
164 boot_mesg "##########################################################"
165 boot_mesg "## POWERDOWNFLAG is not defined in /etc/nut/upsmon.conf ##"
166 boot_mesg "## ##"
167 boot_mesg "## Please read the Manual page upsmon.conf(5) ##"
168 boot_mesg "##########################################################"
169 fi
170 fi
171 ;;
172
173 *)
174 N=/etc/init.d/$NAME
175 echo "Usage: $N {start|stop|status|reload|restart|force-reload|poweroff}" >&2
176 exit 1
177 ;;
178 esac
179
180 exit 0