summaryrefslogtreecommitdiffstats
path: root/system/nut/rc.ups
blob: 0d9f4bc76918399f56d7dae9d4b22f475dad1ca6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/sh
# Slackware startup script for Network UPS Tools
# Copyright 2010 V'yacheslav Stetskevych

# UPS drivers live here
DRIVERPATH=/usr/libexec/nut
export PATH=$DRIVERPATH:$PATH

POWERDOWNFLAG=/etc/killpower
NUTUSER=nut
NUTGROUP=nut
UPSDCONF=/etc/ups/upsd.conf
UPSCONF=/etc/ups/ups.conf
UPSMONCONF=/etc/ups/upsmon.conf

# Check for existense of the nut user and group
# For slackbuilds.org, assigned nut uid/gid are 218/218.
# See http://slackbuilds.org/uid_gid.txt
if ! grep -q ^$NUTGROUP: /etc/group; then
	echo "  You must have a \"$NUTGROUP\" group to run this script."
	echo "    # groupadd -g 218 $NUTGROUP"
	exit 1
elif ! grep -q ^$NUTUSER: /etc/passwd; then
	echo "  You must have a \"$NUTUSER\" user to run this script."
	echo "    # useradd -u 218 -g $NUTGROUP -s /bin/false $NUTUSER"
	exit 1
fi

start_driver() {
	upsdrvctl -u $NUTUSER start || exit 1
}

start_upsd() {
	upsd -u $NUTUSER || exit 1
}

start_upsmon() {
	upsmon -u $NUTUSER || exit 1
}

stop() {
	echo "Stopping the UPS services... "
	if pgrep upsd 2>&1 >/dev/null; then
		upsd -c stop; fi
	if pgrep upsmon 2>&1 >/dev/null; then
		upsmon -c stop; fi
	upsdrvctl stop
}

case "$1" in
	start)	# starts everything (for a ups server box)
		start_driver
		start_upsd
		start_upsmon
		;;
	start_upsmon) # starts upsmon only (for a ups client box)
		start_upsmon
		;;
	stop) # stops all UPS-related daemons
		stop	
		;;
	shutdown) # shuts down the UPS
		echo "Killing inverter..."
		upsdrvctl shutdown
		;;
	reload)
		echo "Reloading config files..."
		upsd -c reload
		upsmon -c reload
		;;
	*)
		echo "Usage: $0 {start|start_upsmon|stop|shutdown|reload}"
esac