updated on Wed Jan 18 04:00:29 UTC 2012
[aur-mirror.git] / nutups / nut
blobd7e0d578ce4468fb994370e9a79612983507db41
1 #!/bin/bash
3 PATH=/sbin:/bin:/usr/sbin:/usr/bin
4 export PATH
6 . /etc/rc.conf
7 . /etc/rc.d/functions
9 PID=`pidof -o %PPID /usr/sbin/upsd`
11 # POWERDOWNFLAG *must* match that in upsmon.conf
12 # Loading POWERDOWNFLAG from /etc/sysconfig/ups
13 DRIVERPATH=/usr/lib/nut
14 if [ -f /etc/nut/ups ]; then
15 . /etc/sysconfig/ups
16 else
17 POWERDOWNFLAG=/etc/killpower
18 NUTUSER=nut
20 UPSDCONF=/etc/nut/upsd.conf
21 UPSCONF=/etc/nut/ups.conf
23 # if there are no config file, bail out
24 [ -f $UPSDCONF ] && [ -f $UPSCONF ] || exit 0
26 runcmd() {
27 echo -n "$1 "
28 shift
29 if [ "$BOOTUP" = "color" ]; then
30 $* && echo_success || echo_failure
31 else
34 echo
37 # See how we are called.
38 case "$1" in
39 start)
40 # new style drivers uses 'upsdrvctl'
41 echo -n "NUT Starting UPS model drivers: "
42 # starting ase nut user
43 daemon --user $NUTUSER `which upsdrvctl` start
44 echo
45 if [ $? -eq 0 ]; then
46 echo -n "NUT Starting UPS daemon: "
47 # starting ase nut user
48 daemon upsd -u $NUTUSER
49 echo
50 touch /var/lock/subsys/upsd
54 stop)
55 # new style upsd stop
56 action "NUT Stopping UPS daemon" \
57 upsd -c stop
58 # new style drivers uses 'upsdrvctl'
59 action "NUT Stopping UPS model drivers" \
60 upsdrvctl stop
62 rm -f /var/lock/subsys/upsd
65 powerdown)
66 # new style drivers
67 runcmd "NUT powerdown of attached UPS(es)" upsdrvctl shutdown
70 restart)
71 $0 stop
72 $0 start
75 reload)
76 # reloading upsd config files
77 action "NUT Reloading config files" \
78 upsd -c reload
81 status)
82 # new style drivers
83 action "NUT: checking UPS model drivers" upsdrvctl status
85 status upsd
88 echo "Usage: upsd {start|stop|powerdown|restart|reload|status}"
89 exit 1
90 esac
91 exit 0