blob: 68d39f668b85bb58c3c17032fe53cc9e83bda386 (
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
74
75
76
|
#!/bin/sh /etc/rc.common
# Copyright © 2012 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
START=87
STOP=23
USE_PROCD=1
DEFAULT=/etc/default/nut
UPSCGI_C=/var/etc/nut/hosts.conf
UPSCGI_S=/var/etc/nut/upsset.conf
nut_upscgi_upsset() {
local cfg="$1"
local enable
config_get_bool enable "$cfg" enable 0
if [ "$enable" -eq 1 ]; then
ln -sf /etc/nut/upsset.conf.enable "$UPSCGI_S"
else
ln -sf /etc/nut/upsset.conf.disable "$UPSCGI_S"
fi
}
nut_upscgi_add() {
local cfg="$1"
local upsname
local hostname
local port
local displayname
config_get upsname "$cfg" upsname
config_get hostname "$cfg" hostname localhost
config_get port "$cfg" port
config_get pass "$cfg" password
system="$upsname@$hostname"
if [ -n "$port" ]; then
system="$system:$port";
fi
config_get displayname "$cfg" displayname
echo "MONITOR $system \"$displayname\"" >> "$UPSCGI_C"
}
service_reload() {
mkdir -m 0755 -p "$(dirname "$UPSCGI_C")"
rm -f "$UPSCGI_C"
rm -f "$UPSCGI_S"
config_load nut_cgi
config_foreach nut_upscgi_add host
config_foreach nut_upscgi_upsset upsset
[ -s "$UPSCGI_C" ] && chmod 640 "$UPSCGI_C"
}
start_service() {
service_reload
}
reload_service() {
service_reload
}
stop_service() {
rm -f "$UPSCGI_C"
rm -f "$UPSCGI_S"
ln -sf /etc/nut/upsset.conf.disable "$UPSCGI_S"
}
service_triggers() {
procd_add_reload_trigger "nut_cgi"
}
|