net/nut: Build optional separate packages and ucify

With a LuCI app (of which I have one written) ucification makes
sense (and is in fact needed), so ucify the initscripts.

Also, rather than making selection of things to include an image
a matter of selecting compile-time config options, make optional
things into seperate packages that are built in default builds,
and leave selection of what to include or not up to the user
(e.g. using ImageBuilder, or adding packages via opkg).

Signed-off-by: Daniel Dickinson <lede@cshore.thecshore.com>
This commit is contained in:
Daniel Dickinson 2017-01-11 18:53:58 -05:00
parent 80f93e5513
commit a23c4e85c5
10 changed files with 656 additions and 157 deletions

View File

@ -1,77 +1,3 @@
config NUT_SERVER
depends on PACKAGE_nut
bool "Include server components (upsd)"
help
upsd is responsible for serving the data from the drivers to the
clients. It connects to each driver and maintains a local cache of the
current state. Queries from the clients are served from this cache, so
delays are minimal. This program is essential, and must be running at
all times to actually make any use out of the drivers and clients.
default y
config NUT_CLIENTS_UPSC
depends on PACKAGE_nut
bool "Include command line client (upsc)"
help
upsc is provided as a quick way to poll the status of a UPS server. It
can be used inside shell scripts and other programs that need UPS data
but don't want to include the full interface.
default y
config NUT_CLIENTS_UPSLOG
depends on PACKAGE_nut
bool "Include logging client (upslog)"
help
upslog is a daemon that will poll a UPS at periodic intervals, fetch the
variables that interest you, format them, and write them to a file.
default n
config NUT_CLIENTS_UPSCMD
depends on PACKAGE_nut
bool "Include UPS controller (upscmd)"
help
upscmd allows you to invoke "instant commands" in your UPS hardware. Not
all hardware supports this, so check the list with -l to see if anything
will work on your equipment. On hardware that supports it, you can use
this program to start and stop battery tests, invoke a front panel test
(beep!), turn the load on or off, and more.
default n
config NUT_CLIENTS_UPSRW
depends on PACKAGE_nut
bool "Include UPS variable editor (upsrw)"
help
upsrw allows you to view and change the read/write variables inside your
UPS. It sends commands via the upsd to your driver, which configures the
hardware for you. The list of variables that allow you to change their
values is based on the capabilities of your UPS equipment. Not all
models support this feature. Typically, cheaper hardware does not
support any of them.
default n
config NUT_CLIENTS_UPSMON
depends on PACKAGE_nut
bool "Include monitor and shutdown controller (upsmon)"
help
upsmon is the client process that is responsible for the most important
part of UPS monitoring--shutting down the system when the power goes
out. It can call out to other helper programs for notification purposes
during power events. upsmon can monitor multiple systems using a single
process. Every UPS that is defined in the upsmon.conf configuration file
is assigned a power value and a type (slave or master).
default y
config NUT_CLIENTS_UPSSCHED
depends on NUT_CLIENTS_UPSMON
bool "Include helper for triggering events from upsmon (upssched)"
help
upssched was created to allow users to execute programs at times relative
to events being monitored by upsmon. The original purpose was to allow
for a shutdown to occur after some fixed period on battery, but there are
other uses that are possible.
You can alternatively write your own script and save some space.
default n
config NUT_SSL
depends on PACKAGE_nut
bool "Build with support for OpenSSL"
@ -97,4 +23,3 @@
help
If you have a UPS you can connect to via SNMP, select this.
default n

View File

@ -1,5 +1,5 @@
#
# Copyright (C) 2006-2015 OpenWrt.org
# Copyright (C) 2006-2016 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
@ -18,19 +18,12 @@ PKG_MAINTAINER:=Martin Rowe <martin.p.rowe@gmail.com>
PKG_LICENSE:=GPL-2.0
PKG_LICENSE_FILES:=LICENSE-GPL2
PKG_BUILD_DIR:=$(BUILD_DIR)/nut-$(PKG_VERSION)
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
PKG_INSTALL:=1
PKG_CONFIG_DEPENDS:= \
CONFIG_NUT_CLIENTS_UPSC \
CONFIG_NUT_CLIENTS_UPSCMD \
CONFIG_NUT_CLIENTS_UPSLOG \
CONFIG_NUT_CLIENTS_UPSMON \
CONFIG_NUT_CLIENTS_UPSRW \
CONFIG_NUT_CLIENTS_UPSSCHED \
CONFIG_NUT_DRIVER_SNMP \
CONFIG_NUT_DRIVER_USB \
CONFIG_NUT_SERVER \
CONFIG_NUT_SSL
include $(INCLUDE_DIR)/package.mk
@ -39,10 +32,10 @@ define Package/nut/Default
SECTION:=net
CATEGORY:=Network
URL:=http://www.networkupstools.org/
DEPENDS:=nut
TITLE:=Network UPS Tools (NUT)
endef
define Package/nut/description
define Package/nut/description/Default
Network UPS Tools (NUT) is a client/server monitoring system that
allows computers to share uninterruptible power supply (UPS) and
power distribution unit (PDU) hardware. Clients access the hardware
@ -52,68 +45,222 @@ endef
define Package/nut
$(call Package/nut/Default)
TITLE:=Network UPS Tools
DEPENDS:= \
+libpthread \
+NUT_DRIVER_SNMP:libnetsnmp \
+NUT_DRIVER_USB:libusb-compat \
+NUT_SSL:libopenssl
MENU:=1
endef
define Package/nut/description
$(call Package/nut/description/Default)
endef
define Package/nut/config
source "$(SOURCE)/Config.in"
endef
define Package/nut/conffiles
/etc/nut/nut.conf
$(if $(CONFIG_NUT_CLIENTS_UPSMON),/etc/nut/upsmon.conf)
$(if $(CONFIG_NUT_CLIENTS_UPSSCHED),/etc/nut/upssched.conf)
$(if $(CONFIG_NUT_SERVER),/etc/nut/ups.conf)
$(if $(CONFIG_NUT_SERVER),/etc/nut/upsd.conf)
$(if $(CONFIG_NUT_SERVER),/etc/nut/upsd.users)
define Package/nut/install
true
endef
define Package/nut/install
define Package/nut-server/install
$(INSTALL_DIR) $(1)/etc/nut
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_DIR) $(1)/usr/lib
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/nut/nut.conf.sample $(1)/etc/nut/nut.conf
$(if $(or $(CONFIG_NUT_CLIENTS_UPSC),\
$(CONFIG_NUT_CLIENTS_UPSCMD),\
$(CONFIG_NUT_CLIENTS_LOG),\
$(CONFIG_NUT_CLIENTS_UPSRW),\
$(CONFIG_NUT_CLIENTS_UPSMON),\
$(CONFIG_NUT_CLIENTS_UPSSCHED)),$(CP) $(PKG_INSTALL_DIR)/usr/lib/libupsclient.so* $(1)/usr/lib/)
$(if $(or $(CONFIG_NUT_SERVER),\
$(CONFIG_NUT_CLIENTS_UPSMON)),$(INSTALL_DIR) $(1)/etc/init.d)
$(if $(CONFIG_NUT_SERVER),$(INSTALL_DIR) $(1)/lib/nut)
$(if $(CONFIG_NUT_SERVER),$(INSTALL_DIR) $(1)/usr/share/nut)
$(if $(CONFIG_NUT_SERVER),$(CP) ./files/nut-server.init $(1)/etc/init.d/)
$(if $(CONFIG_NUT_SERVER),$(CP) $(PKG_INSTALL_DIR)/usr/sbin/upsd $(1)/usr/sbin)
$(if $(CONFIG_NUT_SERVER),$(CP) $(PKG_INSTALL_DIR)/usr/sbin/upsdrvctl $(1)/usr/sbin)
$(if $(CONFIG_NUT_SERVER),$(CP) $(PKG_INSTALL_DIR)/usr/share/nut/cmdvartab $(1)/usr/share/nut/)
$(if $(CONFIG_NUT_SERVER),$(CP) $(PKG_INSTALL_DIR)/usr/share/nut/driver.list $(1)/usr/share/nut/)
$(if $(CONFIG_NUT_SERVER),$(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/nut/ups.conf.sample $(1)/etc/nut/ups.conf)
$(if $(CONFIG_NUT_SERVER),$(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/nut/upsd.conf.sample $(1)/etc/nut/upsd.conf)
$(if $(CONFIG_NUT_SERVER),$(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/nut/upsd.users.sample $(1)/etc/nut/upsd.users)
$(if $(CONFIG_NUT_CLIENTS_UPSC),$(CP) $(PKG_INSTALL_DIR)/usr/bin/upsc $(1)/usr/bin/)
$(if $(CONFIG_NUT_CLIENTS_UPSCMD),$(CP) $(PKG_INSTALL_DIR)/usr/bin/upscmd $(1)/usr/bin/)
$(if $(CONFIG_NUT_CLIENTS_UPSLOG),$(CP) $(PKG_INSTALL_DIR)/usr/bin/upslog $(1)/usr/bin/)
$(if $(CONFIG_NUT_CLIENTS_UPSRW),$(CP) $(PKG_INSTALL_DIR)/usr/bin/upsrw $(1)/usr/bin/)
$(if $(CONFIG_NUT_CLIENTS_UPSMON),$(CP) ./files/nut-monitor.init $(1)/etc/init.d/)
$(if $(CONFIG_NUT_CLIENTS_UPSMON),$(CP) $(PKG_INSTALL_DIR)/usr/sbin/upsmon $(1)/usr/sbin/)
$(if $(CONFIG_NUT_CLIENTS_UPSMON),$(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/nut/upsmon.conf.sample $(1)/etc/nut/upsmon.conf)
$(if $(CONFIG_NUT_CLIENTS_UPSSCHED),$(CP) $(PKG_INSTALL_DIR)/usr/bin/upssched-cmd $(1)/usr/bin/)
$(if $(CONFIG_NUT_CLIENTS_UPSSCHED),$(CP) $(PKG_INSTALL_DIR)/usr/sbin/upssched $(1)/usr/sbin/)
$(if $(CONFIG_NUT_CLIENTS_UPSSCHED),$(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/nut/upssched.conf.sample $(1)/etc/nut/upssched.conf)
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_DIR) $(1)/usr/share/nut
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/nut-server.init $(1)/etc/init.d/nut-server
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/upsd $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/upsdrvctl $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/share/nut/cmdvartab $(1)/usr/share/nut/
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/share/nut/driver.list $(1)/usr/share/nut/
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_CONF) ./files/nut_server $(1)/etc/config/nut_server
ln -sf /var/etc/nut/nut.conf $(1)/etc/nut/nut.conf
ln -sf /var/etc/nut/ups.conf $(1)/etc/nut/ups.conf
ln -sf /var/etc/nut/upsd.users $(1)/etc/nut/upsd.users
ln -sf /var/etc/nut/upsd.conf $(1)/etc/nut/upsd.conf
endef
define Package/nut-common
$(call Package/nut/Default)
TITLE+= (common)
DEPENDS:= nut \
+NUT_DRIVER_SNMP:libnetsnmp \
+NUT_DRIVER_USB:libusb-compat \
+NUT_SSL:libopenssl
endef
define Package/nut-common/description
$(call Package/nut/description/Default)
This package contains the common files.
endef
define Package/nut-common/install
$(INSTALL_DIR) $(1)/etc/nut
$(INSTALL_DIR) $(1)/usr/lib
$(CP) $(PKG_INSTALL_DIR)/usr/lib/libupsclient.so* $(1)/usr/lib/
ln -sf /var/etc/nut/nut.conf $(1)/etc/nut/nut.conf
endef
define Package/nut-server
$(call Package/nut/Default)
TITLE+= (server)
DEPENDS:=nut +nut-common
endef
define Package/nut-server/description
$(call Package/nut/description/Default)
upsd is responsible for serving the data from the drivers to the
clients. It connects to each driver and maintains a local cache of the
current state. Queries from the clients are served from this cache, so
delays are minimal. This program is essential, and must be running at
all times to actually make any use out of the drivers and clients.
endef
define Package/nut-server/conffiles
/etc/config/nut_server
endef
define Package/nut-upsmon
$(call Package/nut/Default)
TITLE+= (monitor)
DEPENDS:=nut +nut-common
USERID:=nut=113:nut=113
endef
define Package/nut-upsmon/description
$(call Package/nut/description/Default)
upsmon is the client process that is responsible for the most important
part of UPS monitoring--shutting down the system when the power goes
out. It can call out to other helper programs for notification purposes
during power events. upsmon can monitor multiple systems using a single
process. Every UPS that is defined in the upsmon.conf configuration file
is assigned a power value and a type (slave or master).
endef
define Package/nut-upsmon/conffiles
/etc/config/nut_monitor
endef
define Package/nut-upsmon/install
$(INSTALL_DIR) $(1)/etc/nut
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/nut-monitor.init $(1)/etc/init.d/nut-monitor
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/upsmon $(1)/usr/sbin/
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_CONF) ./files/nut_monitor $(1)/etc/config/nut_monitor
ln -sf /var/etc/nut/upsmon.conf $(1)/etc/nut/upsmon.conf
endef
define Package/nut-upsc
$(call Package/nut/Default)
TITLE+= (upsc command)
DEPENDS:=nut +nut-common
endef
define Package/nut-upsc/description
$(call Package/nut/description/Default)
upsc is provided as a quick way to poll the status of a UPS server. It
can be used inside shell scripts and other programs that need UPS data
but don not want to include the full interface.
endef
define Package/nut-upsc/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/upsc $(1)/usr/bin
endef
define Package/nut-upslog
$(call Package/nut/Default)
TITLE+= (logging client)
DEPENDS:=nut +nut-common
endef
define Package/nut-upslog/description
$(call Package/nut/description/Default)
upslog is a daemon that will poll a UPS at periodic intervals, fetch the
variables that interest you, format them, and write them to a file.
endef
define Package/nut-upslog/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/upslog $(1)/usr/bin/
endef
define Package/nut-upscmd
$(call Package/nut/Default)
TITLE+= (controller)
DEPENDS:=nut +nut-common
endef
define Package/nut-upscmd/description
$(call Package/nut/description/Default)
upscmd allows you to invoke "instant commands" in your UPS hardware. Not
all hardware supports this, so check the list with -l to see if anything
will work on your equipment. On hardware that supports it, you can use
this program to start and stop battery tests, invoke a front panel test
(beep!), turn the load on or off, and more.
endef
define Package/nut-upscmd/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/upscmd $(1)/usr/bin/
endef
define Package/nut-upsrw
$(call Package/nut/Default)
TITLE+= (variable editor)
DEPENDS:=nut +nut-common
endef
define Package/nut-upsrw/description
$(call Package/nut/description/Default)
upsrw allows you to view and change the read/write variables inside your
UPS. It sends commands via the upsd to your driver, which configures the
hardware for you. The list of variables that allow you to change their
values is based on the capabilities of your UPS equipment. Not all
models support this feature. Typically, cheaper hardware does not
support any of them.
endef
define Package/nut-upsrw/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/upsrw $(1)/usr/bin/
endef
define Package/nut-upssched
$(call Package/nut/Default)
TITLE+= (helper for triggering events from upsmon)
DEPENDS:=nut +nut-common +nut-upsmon
endef
define Package/nut-upssched/description
$(call Package/nut/description/Default)
upssched was created to allow users to execute programs at times relative
to events being monitored by upsmon. The original purpose was to allow
for a shutdown to occur after some fixed period on battery, but there are
other uses that are possible.
You can alternatively write your own script and save some space.
endef
define Package/nut-upssched/conffiles
/etc/nut/upssched.conf
endef
define Package/nut-upssched/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_DIR) $(1)/etc/nut
$(INSTALL_DIR) $(1)/etc/uci-defaults
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/upssched-cmd $(1)/usr/bin/
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/upssched $(1)/usr/sbin/
$(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/nut/upssched.conf.sample $(1)/etc/nut/upssched.conf
$(INSTALL_DATA) ./files/nut-sched.default $(1)/etc/uci-defaults/nut-upssched
endef
define Package/nut-web-cgi
$(call Package/nut/Default)
TITLE+= Web CGI interface
DEPENDS+=+libgd
DEPENDS:=nut +nut-common +libgd
endef
define Package/nut-web-cgi/description
@ -127,23 +274,29 @@ define Package/nut-web-cgi/conffiles
/etc/nut/upsset.conf
/etc/nut/upsstats.html
/etc/nut/upsstats-single.html
/etc/config/nut_cgi
endef
define Package/nut-web-cgi/install
$(INSTALL_DIR) $(1)/www/cgi-bin/nut $(1)/www/nut
$(INSTALL_DIR) $(1)/etc/nut
$(INSTALL_DIR) $(1)/usr/share/www/cgi-bin
$(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/nut/hosts.conf.sample $(1)/etc/nut/hosts.conf
$(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/nut/upsset.conf.sample $(1)/etc/nut/upsset.conf
$(CP) $(PKG_INSTALL_DIR)/usr/html/* $(1)/www/nut/
$(INSTALL_DIR) $(1)/etc/uci-defaults
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/cgi-bin/* $(1)/www/cgi-bin/nut
$(INSTALL_CONF) ./files/add_nut_httpd_conf $(1)/etc/uci-defaults/add_nut_httpd_conf
$(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/nut/upsstats.html.sample $(1)/etc/nut/upsstats.html
$(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/nut/upsstats-single.html.sample $(1)/etc/nut/upsstats-single.html
$(CP) $(PKG_INSTALL_DIR)/usr/share/www/nut $(1)/usr/share/www/
$(CP) $(PKG_INSTALL_DIR)/usr/share/www/cgi-bin/nut $(1)/usr/share/www/cgi-bin/
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_CONF) ./files/nut_cgi $(1)/etc/config/nut_cgi
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/nut-cgi.init $(1)/etc/init.d/nut-cgi
ln -sf /var/etc/nut/hosts.conf $(1)/etc/nut/hosts.conf
endef
define Package/nut-avahi-service
$(call Package/nut/Default)
TITLE+= (Avahi service)
DEPENDS+=+avahi-daemon
DEPENDS:=nut +avahi-daemon
endef
define Package/nut-avahi-service/description
@ -166,6 +319,7 @@ define DriverPackage
define Package/nut-driver-$(2)
$(call Package/nut/Default)
TITLE:=$(2) (NUT $(1) driver)
DEPENDS:=nut +nut-common
$(if $(filter $(1),snmp),DEPENDS+= @NUT_DRIVER_SNMP)
$(if $(filter $(1),usb),DEPENDS+= @NUT_DRIVER_USB)
endef
@ -325,15 +479,13 @@ CONFIGURE_ARGS += \
--$(if $(CONFIG_NUT_DRIVER_SNMP),with,without)-snmp \
--without-neon \
--without-powerman \
--with-cgi \
--without-ipmi \
--without-freeipmi \
--$(if $(CONFIG_NUT_SSL),with,without)-ssl $(if $(CONFIG_NUT_SSL),--with-openssl) \
--without-libltdl \
--$(if $(CONFIG_PACKAGE_nut-web-cgi),with,without)-cgi \
--with-statepath=/var/run \
--with-drvpath=/lib/nut \
--with-cgipath=/usr/share/www/cgi-bin/nut \
--with-htmlpath=/usr/share/www/nut \
--with-user=root \
--with-group=root
@ -345,6 +497,14 @@ define Build/InstallDev
endef
$(eval $(call BuildPackage,nut))
$(eval $(call BuildPackage,nut-common))
$(eval $(call BuildPackage,nut-server))
$(eval $(call BuildPackage,nut-upsmon))
$(eval $(call BuildPackage,nut-upsc))
$(eval $(call BuildPackage,nut-upscmd))
$(eval $(call BuildPackage,nut-upslog))
$(eval $(call BuildPackage,nut-upsrw))
$(eval $(call BuildPackage,nut-upssched))
$(eval $(call BuildPackage,nut-web-cgi))
$(eval $(call BuildPackage,nut-avahi-service))
$(foreach d,$(filter-out $(SERIAL_DRIVERLIST_IGNORE),$(SERIAL_DRIVERLIST)),$(eval $(call BuildPackage,nut-driver-$(d))))

44
net/nut/files/nut-cgi.init Executable file
View File

@ -0,0 +1,44 @@
#!/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=51
DEFAULT=/etc/default/nut
UPSCGI_C=/var/etc/nut/hosts.conf
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
}
start() {
rm -f $UPSCGI_C
config_load nut_cgi
config_foreach nut_upscgi_add host
chmod 640 /var/etc/nut/hosts.conf
}
stop() {
rm -f $UPSCGI_C
}

View File

@ -2,18 +2,170 @@
START=60
USE_PROCD=1
UPSMON_C=/var/etc/nut/upsmon.conf
restart() {
stop_service
start_service
nut_upsmon_conf() {
local cfg="$1"
echo "# Config file automatically generated from UCI config" > $UPSMON_C
config_get runas "$cfg" runas "nut"
[ -n "$runas" ] && echo "RUN_AS_USER $runas" >> $UPSMON_C
config_get val "$cfg" minsupplies 1
echo "MINSUPPLIES $val" >> $UPSMON_C
config_get val "$cfg" shutdowncmd "/sbin/halt"
echo "SHUTDOWNCMD \"$val\"" >> $UPSMON_C
config_get val "$cfg" notifycmd
[ -n "$val" ] && echo "NOTIFYCMD \"$val\"" >> $UPSMON_C
config_get val "$cfg" pollfreq 5
echo "POLLFREQ $val" >> $UPSMON_C
config_get val "$cfg" pollfreqalert 5
echo "POLLFREQALERT $val" >> $UPSMON_C
config_get val "$cfg" hostsync 15
echo "HOSTSYNC $val" >> $UPSMON_C
config_get val "$cfg" deadtime 15
echo "DEADTIME $val" >> $UPSMON_C
config_get val "$cfg" powerdownflag /var/run/killpower
echo "POWERDOWNFLAG $val" >> $UPSMON_C
config_get val "$cfg" onlinemsg
[ -n "$val" ] && echo "NOTIFYMSG ONLINE \"$val\"" >> $UPSMON_C
config_get val "$cfg" onbattmsg
[ -n "$val" ] && echo "NOTIFYMSG ONBATT \"$val\"" >> $UPSMON_C
config_get val "$cfg" lowbattmsg
[ -n "$val" ] && echo "NOTIFYMSG LOWBATT \"$val\"" >> $UPSMON_C
config_get val "$cfg" fsdmsg
[ -n "$val" ] && echo "NOTIFYMSG FSD \"$val\"" >> $UPSMON_C
config_get val "$cfg" commokmsg
[ -n "$val" ] && echo "NOTIFYMSG COMMOK \"$val\"" >> $UPSMON_C
config_get val "$cfg" commbadmsg
[ -n "$val" ] && echo "NOTIFYMSG COMMBAD \"$val\"" >> $UPSMON_C
config_get val "$cfg" shutdownmsg
[ -n "$val" ] && echo "NOTIFYMSG SHUTDOWN \"$val\"" >> $UPSMON_C
config_get val "$cfg" replbattmsg
[ -n "$val" ] && echo "NOTIFYMSG REPLBATT \"$val\"" >> $UPSMON_C
config_get val "$cfg" nocommmsg
[ -n "$val" ] && echo "NOTIFYMSG NOCOMM \"$val\"" >> $UPSMON_C
config_get val "$cfg" noparentmsg
[ -n "$val" ] && echo "NOTIFYMSG NOPARENT \"$val\"" >> $UPSMON_C
notifylist() {
local value="$1"
append optval "$value" "+"
}
setnotify() {
local cfg="$1"
local optname="$2"
local optval
config_list_foreach "$cfg" "$optname" notifylist
if [ -z "$optval" ]; then
# If no list fallback to trying option, fallback to default
config_get optval "$cfg" "$optname" "$default"
if [ -n "$optval" ]; then
echo "$optval"
else
# No default, so do the NUT default
echo "SYSLOG"
fi
else
echo "$optval"
fi
}
local default optval
val=""
config_list_foreach "$cfg" defaultnotify notifylist
default="$optval"
echo "NOTIFYFLAG ONLINE $(setnotify "$cfg" onlinenotify)" >> $UPSMON_C
echo "NOTIFYFLAG ONBATT $(setnotify "$cfg" onbattnotify)" >> $UPSMON_C
echo "NOTIFYFLAG LOWBATT $(setnotify "$cfg" lowbatnotify)" >> $UPSMON_C
echo "NOTIFYFLAG FSD $(setnotify "$cfg" fsdnotify)" >> $UPSMON_C
echo "NOTIFYFLAG COMMOK $(setnotify "$cfg" commoknotify)" >> $UPSMON_C
echo "NOTIFYFLAG COMMBAD $(setnotify "$cfg" commbadnotify)" >> $UPSMON_C
echo "NOTIFYFLAG SHUTDOWN $(setnotify "$cfg" shutdownnotify)" >> $UPSMON_C
echo "NOTIFYFLAG REPLBATT $(setnotify "$cfg" repolbattnotify)" >> $UPSMON_C
echo "NOTIFYFLAG NOCOMM $(setnotify "$cfg" nocommnotify)" >> $UPSMON_C
echo "NOTIFYFLAG NOPARENT $(setnotify "$cfg" noparentnotify)" >> $UPSMON_C
config_get val "$cfg" rbwarntime 43200
echo "RBWARNTIME $val" >> $UPSMON_C
config_get val "$cfg" nocommwarntime 300
echo "NOCOMMWARNTIME $val" >> $UPSMON_C
config_get val "$cfg" finaldelay 5
echo "FINALDELAY $val" >> $UPSMON_C
config_get val "$cfg" certpath
if [ -n "$val" ]; then echo "CERTPATH $val" >> $UPSMON_C; fi
config_get_bool val "$cfg" certverify 0
if [ -n "$val" ]; then echo "CERTVERIFY $val" >> $UPSMON_C; fi
config_get_bool val "$cfg" forcessl 0
if [ -n "$val" ]; then echo "FORCESSL $val" >> $UPSMON_C; fi
}
nut_upsmon_add() {
local cfg="$1"
local type="$2"
local upsname
local hostname
local port
local powervalue
local username
local password
local system
# If no core config, use defaults
[ -r $UPSMON_C ] || nut_upsmon_conf ""
config_get upsname "$cfg" upsname
config_get hostname "$cfg" hostname localhost
config_get port "$cfg" port
config_get powervalue "$cfg" powervalue 1
config_get username "$cfg" username
config_get password "$cfg" password
system="$upsname@$hostname"
if [ -n "$port" ]; then
system="$system:$port";
fi
echo "MONITOR $system $powervalue $username $password $type" >> $UPSMON_C
}
start_service() {
upsmon -p
[ -d $RUN_D ] || mkdir -p $RUN_D
mkdir -p /var/etc/nut
chmod 640 /var/etc/nut
rm -f $UPSMON_C
config_load nut_monitor
config_foreach nut_upsmon_conf upsmon
config_foreach nut_upsmon_add master master
config_foreach nut_upsmon_add slave slave
[ -z "$(cat /var/etc/nut/nut.conf)" ] && echo "MODE=netclient" >>/var/etc/nut/nut.conf
chmod 640 $UPSMON_C
chmod 640 /var/etc/nut/nut.conf
chown ${runas:-root}:$(id -gn ${runas:-root}) $UPSMON_C
$DEBUG /usr/sbin/upsmon $UPSMON_OPTIONS
}
stop_service() {
upsmon -c stop
[ -r $PID_F ] && /usr/sbin/upsmon -c stop
rm -f $UPSMON_C
}
reload_service() {

View File

@ -0,0 +1,10 @@
#!/bin/sh
uci batch <<EOF
set nut_monitor.@upsmon[-1]=upsmon
set nut_monitor.@upsmon[-1].notifycmd=/usr/bin/upssched-cmd
set nut_monitor.@upsmon[-1].defaultnotify="SYSLOG EXEC"
commit nut_monitor
EOF

View File

@ -1,21 +1,146 @@
#!/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=50
RUN_D=/var/run
PID_F=$RUN_D/upsd.pid
UPS_C=/var/etc/nut/ups.conf
USERS_C=/var/etc/nut/upsd.users
UPSD_C=/var/etc/nut/upsd.conf
USE_PROCD=1
restart() {
stop_service
start_service
listen_address() {
local cfg="$1"
config_get address "$cfg" address "::1"
config_get port "$cfg" port
echo "LISTEN $address $port" >>$UPSD_C
}
upsd_config() {
local cfg="$1"
local maxage maxconn certfile
# Note runas support requires you make sure USB device file is readable by
# the runas user
config_get runas "$cfg" runas
config_get maxage "$cfg" maxage
[ -n "$maxage" ] && echo "MAXAGE $maxage" >>$UPSD_C
config_get statepath "$cfg" statepath
[ -n "$statepath" ] && echo "STATEPATH $statepath" >>$UPSD_C
config_get maxconn "$cfg" maxconn
[ -n "$maxconn" ] && echo "MAXCONN $maxconn" >>$UPSD_C
#NOTE: certs only apply to SSL-enabled version
config_get certfile "$cfg" certfile
[ -n "$certfile" ] && echo "CERTFILE $certfile" >>$UPSD_C
}
nut_user_add() {
local cfg="$1"
local a
local val
config_get val "$cfg" username "$1"
echo "[$val]" >> $USERS_C
config_get val "$cfg" password
echo " password = $val" >> $USERS_C
config_get val "$cfg" actions
for a in $val; do
echo " actions = $a" >> $USERS_C
done
instcmd() {
local val="$1"
echo " instcmds = $val" >> $USERS_C
}
config_list_foreach "$cfg" instcmd instcmd
config_get val "$cfg" upsmon
if [ -n "$val" ]; then
echo " upsmon $val" >> $USERS_C
fi
}
start_service() {
upsdrvctl start
upsd
local runas statepath
mkdir -p /var/etc/nut
chmod -R 750 /var/etc/nut
rm -f $UPSD_C
rm -f $USERS_C
rm -f $UPSD_C
rm -f /var/etc/nut/nut.conf
echo "# Config file automatically generated from UCI config" > $UPS_C
echo "# Config file automatically generated from UCI config" > $USERS_C
echo "# Config file automatically generated from UCI config" > $UPSD_C
local in_driver have_drivers
config_cb() {
if [ "$1" != "driver" ]; then
in_driver=
else
echo "[$2]" >> $UPS_C
in_driver=true
have_drivers=true
fi
}
option_cb() {
if [ "$in_driver" = "true" ]; then
echo " $1 = $2" >> $UPS_C
fi
}
config_load nut_server
config_foreach nut_user_add user
config_foreach upsd_config upsd
config_foreach listen_address listen_address
echo "MODE=netserver" >>/var/etc/nut/nut.conf
chmod 0640 $USERS_C
chmod 0640 $UPS_C
chmod 0640 $UPSD_C
chmod 0640 /var/etc/nut/nut.conf
if [ -n "$runas" ]; then
chown -R $runas:$(id -gn $runas) /var/etc/nut
fi
if [ "$have_drivers" = "true" ]; then
$DEBUG /usr/sbin/upsd ${runas:+-u $runas} $OPTIONS
$DEBUG /usr/sbin/upsdrvctl ${runas:+-u $runas} start
fi
}
nut_driver_stop() {
local cfg="$1"
local driver
config_get driver "$cfg" driver
[ -r /var/run/$driver-$cfg ] && /usr/sbin/upsdrvctl stop $cfg
}
stop_service() {
upsd -c stop
upsdrvctl stop
[ -r $PID_F ] && /usr/sbin/upsd -c stop
config_load ups
config_foreach nut_driver_stop driver
}
reload_service() {

6
net/nut/files/nut_cgi Normal file
View File

@ -0,0 +1,6 @@
#config host
# option upsname upsname
# option hostname localhost
# option port # optional port number
# option displayname "Display Name"

54
net/nut/files/nut_monitor Normal file
View File

@ -0,0 +1,54 @@
#config upsmon 'upsmon'
# option runas run-as-user
# option minsupplies 1
# option shutdowncmd /sbin/halt
# option notifycmd /path/to/cmd
# list defaultnotify SYSLOG
# option pollfreq 5
# option pollfreqalert 5
# option hostsync 15
# option deadtime 15
# option powerdownflags /var/run/killpower
# option onlinemsg "online message"
# option onbattmsg "on battery message"
# option lowbattmsg "low battery message"
# option fsdmsg "forced shutdown message"
# option comokmsg "communications restored message"
# option combadmsg "communications bad message"
# option shutdowmsg "shutdown message"
# option replbattmsg "replace battery message"
# option nocommmsg "no communications message"
# option noparentmsg "no parent message"
# option onlinenotify "online notify flag 1|0"
# option onbattnotify "on battery notify flag 1|0"
# option lowbattnotify "low battery notify flag 1|0"
# option fsdnotify "forced shutdown notify flag 1|0"
# option comoknotify "communications restored notify flag 1|0"
# option combadnotify "communications bad notify flag 1|0"
# option shutdownotify "shutdown notify flag 1|0"
# option replbattnotify "replace battery notify flag 1|0"
# option nocommnotify "no communications notify flag 1|0"
# option noparentnotify "no parent notify flag 1|0"
# option rbwarntime 4200 # replace battery warn time
# option nocommwarntime 300 # no communications warn time
# option finaldelay 5 # final delay
# option certpath /path/to/ca/dir
# option certverify 0
# option forcessl 0
#config master
# option upsname upsname
# option hostname localhost
# option port # optional port number
# option powervalue 1
# option username upsuser
# option password upspassword
#config slave
# option upsname upsname
# option hostname localhost
# option port # optional port number
# option powervalue 1
# option username upsuser
# option password upspassword

23
net/nut/files/nut_server Normal file
View File

@ -0,0 +1,23 @@
#config driver 'upsname'
# option driver usbhid-ups
# option port auto
# option other other-value
# option runas root
#config user
# option username upsuser
# option password upspassword
# option actions optional-action
# list instcmd optional-instant-command
# option upsmon slave|master
#config listen_address
# option address ::1
# option port 3493
#config upsd 'upsd'
# option maxage 15
# option statepath /var/run/nut
# option maxconn 1024
# NB: certificates only apply to SSL-enabled version
# option certfile /usr/local/etc/upsd.pem

View File

@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=collectd
PKG_VERSION:=5.5.3
PKG_RELEASE:=1
PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
PKG_SOURCE_URL:=http://collectd.org/files/
@ -338,7 +338,7 @@ $(eval $(call BuildPlugin,netlink,netlink input,netlink,+PACKAGE_collectd-mod-ne
$(eval $(call BuildPlugin,network,network input/output,network,+PACKAGE_COLLECTD_ENCRYPTED_NETWORK:libgcrypt))
$(eval $(call BuildPlugin,nginx,nginx status input,nginx,+PACKAGE_collectd-mod-nginx:libcurl))
$(eval $(call BuildPlugin,ntpd,NTP daemon status input,ntpd,))
$(eval $(call BuildPlugin,nut,UPS monitoring input,nut,+PACKAGE_collectd-mod-nut:nut))
$(eval $(call BuildPlugin,nut,UPS monitoring input,nut,+PACKAGE_collectd-mod-nut:nut-common))
$(eval $(call BuildPlugin,olsrd,OLSRd status input,olsrd,))
$(eval $(call BuildPlugin,onewire,onewire sensor input,onewire,+PACKAGE_collectd-mod-onewire:libow-capi @BROKEN))
$(eval $(call BuildPlugin,openvpn,OpenVPN traffic/compression input,openvpn,))