From a23c4e85c5f6c9f9dcf67743b93c492ba833e365 Mon Sep 17 00:00:00 2001 From: Daniel Dickinson Date: Wed, 11 Jan 2017 18:53:58 -0500 Subject: [PATCH 1/8] 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 --- net/nut/Config.in | 75 -------- net/nut/Makefile | 294 ++++++++++++++++++++++++-------- net/nut/files/nut-cgi.init | 44 +++++ net/nut/files/nut-monitor.init | 162 +++++++++++++++++- net/nut/files/nut-sched.default | 10 ++ net/nut/files/nut-server.init | 141 ++++++++++++++- net/nut/files/nut_cgi | 6 + net/nut/files/nut_monitor | 54 ++++++ net/nut/files/nut_server | 23 +++ utils/collectd/Makefile | 4 +- 10 files changed, 656 insertions(+), 157 deletions(-) create mode 100755 net/nut/files/nut-cgi.init create mode 100644 net/nut/files/nut-sched.default create mode 100644 net/nut/files/nut_cgi create mode 100644 net/nut/files/nut_monitor create mode 100644 net/nut/files/nut_server diff --git a/net/nut/Config.in b/net/nut/Config.in index b48102f34..a5f1ff4be 100644 --- a/net/nut/Config.in +++ b/net/nut/Config.in @@ -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 - diff --git a/net/nut/Makefile b/net/nut/Makefile index a6ed1c647..cc9a5de73 100644 --- a/net/nut/Makefile +++ b/net/nut/Makefile @@ -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 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)))) diff --git a/net/nut/files/nut-cgi.init b/net/nut/files/nut-cgi.init new file mode 100755 index 000000000..d63d98ba9 --- /dev/null +++ b/net/nut/files/nut-cgi.init @@ -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 +} + diff --git a/net/nut/files/nut-monitor.init b/net/nut/files/nut-monitor.init index e9fdb336d..a629f91bf 100755 --- a/net/nut/files/nut-monitor.init +++ b/net/nut/files/nut-monitor.init @@ -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() { diff --git a/net/nut/files/nut-sched.default b/net/nut/files/nut-sched.default new file mode 100644 index 000000000..d8b13f0e3 --- /dev/null +++ b/net/nut/files/nut-sched.default @@ -0,0 +1,10 @@ +#!/bin/sh + +uci batch <>$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() { diff --git a/net/nut/files/nut_cgi b/net/nut/files/nut_cgi new file mode 100644 index 000000000..9f0bed6fc --- /dev/null +++ b/net/nut/files/nut_cgi @@ -0,0 +1,6 @@ +#config host +# option upsname upsname +# option hostname localhost +# option port # optional port number +# option displayname "Display Name" + diff --git a/net/nut/files/nut_monitor b/net/nut/files/nut_monitor new file mode 100644 index 000000000..0b71e95cf --- /dev/null +++ b/net/nut/files/nut_monitor @@ -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 + diff --git a/net/nut/files/nut_server b/net/nut/files/nut_server new file mode 100644 index 000000000..bebd169db --- /dev/null +++ b/net/nut/files/nut_server @@ -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 diff --git a/utils/collectd/Makefile b/utils/collectd/Makefile index 70921245e..db5a669f2 100644 --- a/utils/collectd/Makefile +++ b/utils/collectd/Makefile @@ -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,)) From c1d26bacdff1dc104f59ecd06d777286fabf9c6f Mon Sep 17 00:00:00 2001 From: Daniel Dickinson Date: Wed, 11 Jan 2017 18:54:16 -0500 Subject: [PATCH 2/8] net/nut: Protect CGI via HTTP Basic Auth When using uhttpd (the default), protect NUT CGI via HTTP Basic Auth. Signed-off-by: Daniel Dickinson --- net/nut/Makefile | 1 + net/nut/files/add_nut_httpd_conf | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 net/nut/files/add_nut_httpd_conf diff --git a/net/nut/Makefile b/net/nut/Makefile index cc9a5de73..a5773f1f8 100644 --- a/net/nut/Makefile +++ b/net/nut/Makefile @@ -275,6 +275,7 @@ define Package/nut-web-cgi/conffiles /etc/nut/upsstats.html /etc/nut/upsstats-single.html /etc/config/nut_cgi +/etc/httpd.conf endef define Package/nut-web-cgi/install diff --git a/net/nut/files/add_nut_httpd_conf b/net/nut/files/add_nut_httpd_conf new file mode 100644 index 000000000..b8fa847f8 --- /dev/null +++ b/net/nut/files/add_nut_httpd_conf @@ -0,0 +1,6 @@ +#!/bin/sh + +grep -q '/cgi-bin/nut' /etc/httpd.conf 2>/dev/null || { + echo '/cgi-bin/nut:root:$p$root' >>/etc/httpd.conf + /etc/init.d/uhttpd restart +} From 5503dac80676b858f81855610170796247a86830 Mon Sep 17 00:00:00 2001 From: Daniel Dickinson Date: Wed, 11 Jan 2017 18:54:29 -0500 Subject: [PATCH 3/8] net/nut: Add back serial support It looks like serial support was accidentally dropped due to missing pieces on Config.in and Makefile. Add back serial support by fixing that. Signed-off-by: Daniel Dickinson --- net/nut/Config.in | 7 +++++++ net/nut/Makefile | 3 +++ 2 files changed, 10 insertions(+) diff --git a/net/nut/Config.in b/net/nut/Config.in index a5f1ff4be..b7f403b78 100644 --- a/net/nut/Config.in +++ b/net/nut/Config.in @@ -23,3 +23,10 @@ help If you have a UPS you can connect to via SNMP, select this. default n + + config NUT_DRIVER_SERIAL + depends on PACKAGE_nut + bool "Build with suport for serial drivers" + help + If you have a UPS connected via serial cable, select this. + default n diff --git a/net/nut/Makefile b/net/nut/Makefile index a5773f1f8..25d93c48d 100644 --- a/net/nut/Makefile +++ b/net/nut/Makefile @@ -24,6 +24,7 @@ PKG_INSTALL:=1 PKG_CONFIG_DEPENDS:= \ CONFIG_NUT_DRIVER_SNMP \ CONFIG_NUT_DRIVER_USB \ + CONFIG_NUT_DRIVER_SERIAL \ CONFIG_NUT_SSL include $(INCLUDE_DIR)/package.mk @@ -323,6 +324,7 @@ define DriverPackage DEPENDS:=nut +nut-common $(if $(filter $(1),snmp),DEPENDS+= @NUT_DRIVER_SNMP) $(if $(filter $(1),usb),DEPENDS+= @NUT_DRIVER_USB) + $(if $(filter $(1),serial),DEPENDS+= @NUT_DRIVER_SERIAL) endef # Deliberately empty description in order to trigger a build failure. # It should be overridden by the list below, and when updating to a @@ -478,6 +480,7 @@ CONFIGURE_ARGS += \ --$(if $(CONFIG_NUT_DRIVER_USB),with,without)-usb \ --without-avahi \ --$(if $(CONFIG_NUT_DRIVER_SNMP),with,without)-snmp \ + --$(if $(CONFIG_NUT_DRIVER_SERAL),with,without)-serial \ --without-neon \ --without-powerman \ --with-cgi \ From c94e334c4e5251d09995e3f6c8b80d61928a451c Mon Sep 17 00:00:00 2001 From: Daniel Dickinson Date: Wed, 11 Jan 2017 18:54:40 -0500 Subject: [PATCH 4/8] net-nut: Add UPS notifications via sendmail Add option to send email notification via sendmail (or replacement). Signed-off-by: Daniel Dickinson --- net/nut/Makefile | 19 ++++++++++ net/nut/files/nut-sendmail-notify | 10 ++++++ net/nut/files/nut-sendmail-notify.default | 44 +++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100755 net/nut/files/nut-sendmail-notify create mode 100644 net/nut/files/nut-sendmail-notify.default diff --git a/net/nut/Makefile b/net/nut/Makefile index 25d93c48d..c2c38da98 100644 --- a/net/nut/Makefile +++ b/net/nut/Makefile @@ -152,6 +152,24 @@ define Package/nut-upsmon/install ln -sf /var/etc/nut/upsmon.conf $(1)/etc/nut/upsmon.conf endef +define Package/nut-upsmon-sendmail-notify + $(call Package/nut/Default) + TITLE+= (upsmon with notifications via sendmail) + DEPENDS:=nut +nut-upsmon + CONFLICTS:=nut-upssched +endef + +define Package/nut-upsmon-sendmail-notify/description +$(call Package/nut/description/Default) +upsmon with default notification via sendmail +endef + +define Package/nut-upsmon-sendmail-notify/install + $(INSTALL_DIR) $(1)/usr/bin $(1)/etc/uci-defaults + $(INSTALL_BIN) ./files/nut-sendmail-notify $(1)/usr/bin/ + $(INSTALL_DATA) ./files/nut-sendmail-notify.default $(1)/etc/uci-defaults/nut-sendmail-notify +endef + define Package/nut-upsc $(call Package/nut/Default) TITLE+= (upsc command) @@ -504,6 +522,7 @@ $(eval $(call BuildPackage,nut)) $(eval $(call BuildPackage,nut-common)) $(eval $(call BuildPackage,nut-server)) $(eval $(call BuildPackage,nut-upsmon)) +$(eval $(call BuildPackage,nut-upsmon-sendmail-notify)) $(eval $(call BuildPackage,nut-upsc)) $(eval $(call BuildPackage,nut-upscmd)) $(eval $(call BuildPackage,nut-upslog)) diff --git a/net/nut/files/nut-sendmail-notify b/net/nut/files/nut-sendmail-notify new file mode 100755 index 000000000..749aa9bf6 --- /dev/null +++ b/net/nut/files/nut-sendmail-notify @@ -0,0 +1,10 @@ +#!/bin/sh + +/usr/sbin/sendmail root < Date: Wed, 11 Jan 2017 18:54:51 -0500 Subject: [PATCH 5/8] net/nut: Fix '/var/run' world readable warning Use /var/run/nut as statepath and set appropriate owner and permissions on /var/run/nut in order to avoid pidfile for nut being world-readable. Signed-off-by: Daniel Dickinson --- net/nut/Makefile | 2 +- net/nut/files/nut-monitor.init | 8 +++++--- net/nut/files/nut-server.init | 12 +++++++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/net/nut/Makefile b/net/nut/Makefile index c2c38da98..bd450a469 100644 --- a/net/nut/Makefile +++ b/net/nut/Makefile @@ -506,7 +506,7 @@ CONFIGURE_ARGS += \ --without-freeipmi \ --$(if $(CONFIG_NUT_SSL),with,without)-ssl $(if $(CONFIG_NUT_SSL),--with-openssl) \ --without-libltdl \ - --with-statepath=/var/run \ + --with-statepath=/var/run/nut \ --with-drvpath=/lib/nut \ --with-user=root \ --with-group=root diff --git a/net/nut/files/nut-monitor.init b/net/nut/files/nut-monitor.init index a629f91bf..388c376ee 100755 --- a/net/nut/files/nut-monitor.init +++ b/net/nut/files/nut-monitor.init @@ -143,9 +143,6 @@ nut_upsmon_add() { } start_service() { - [ -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 @@ -159,6 +156,11 @@ start_service() { chmod 640 $UPSMON_C chmod 640 /var/etc/nut/nut.conf + [ -d /var/run/nut ] || { + mkdir -m 0750 -p /var/run/nut + chown ${runas:-root}:$(id -gn ${runas:-root}) /var/run/nut + } + chown ${runas:-root}:$(id -gn ${runas:-root}) $UPSMON_C $DEBUG /usr/sbin/upsmon $UPSMON_OPTIONS } diff --git a/net/nut/files/nut-server.init b/net/nut/files/nut-server.init index 0d6a06915..e064dd721 100755 --- a/net/nut/files/nut-server.init +++ b/net/nut/files/nut-server.init @@ -22,6 +22,11 @@ listen_address() { echo "LISTEN $address $port" >>$UPSD_C } +upsd_statepath() { + local cfg="$1" + config_get statepath "$cfg" statepath +} + upsd_config() { local cfg="$1" local maxage maxconn certfile @@ -116,6 +121,10 @@ start_service() { chmod 0640 $UPS_C chmod 0640 $UPSD_C chmod 0640 /var/etc/nut/nut.conf + [ -d "${statepath:-/var/run/nut}" ] || { + mkdir -m 0750 -p "${statepath:-/var/run/nut}" + chown $runas:$(id -gn $runas) "${statepath:-/var/run/nut}" + } if [ -n "$runas" ]; then chown -R $runas:$(id -gn $runas) /var/etc/nut @@ -134,12 +143,13 @@ nut_driver_stop() { config_get driver "$cfg" driver - [ -r /var/run/$driver-$cfg ] && /usr/sbin/upsdrvctl stop $cfg + [ -r ${statepath:-/var/run/nut}/$driver-$cfg ] && /usr/sbin/upsdrvctl stop $cfg } stop_service() { [ -r $PID_F ] && /usr/sbin/upsd -c stop config_load ups + config_foreach upsd_statepath upsd config_foreach nut_driver_stop driver } From b27c7fd64b0f01fae88c0c238d2a9e11c0d7032b Mon Sep 17 00:00:00 2001 From: Daniel Dickinson Date: Wed, 11 Jan 2017 18:55:19 -0500 Subject: [PATCH 6/8] net/nut: Make myself maintainer per private mail Current maintainer (Martin Rowe) offered to hand over maintership because I'm interested in doing more with the package than he requires for his own use, so he felt it made sense for me to maintain the package. I accepted, hence this commit. Signed-off-by: Daniel Dickinson --- net/nut/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/nut/Makefile b/net/nut/Makefile index bd450a469..629f60ef8 100644 --- a/net/nut/Makefile +++ b/net/nut/Makefile @@ -9,12 +9,12 @@ include $(TOPDIR)/rules.mk PKG_NAME:=nut PKG_VERSION:=2.7.4 -PKG_RELEASE:=2 +PKG_RELEASE:=3 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=http://www.networkupstools.org/source/2.7/ PKG_MD5SUM:=3ba53656933d7471f95140b32a5b8d5c -PKG_MAINTAINER:=Martin Rowe +PKG_MAINTAINER:=Daniel Dickinson PKG_LICENSE:=GPL-2.0 PKG_LICENSE_FILES:=LICENSE-GPL2 From a69c25d5e31c907f63de93358e78ba3be5a61acc Mon Sep 17 00:00:00 2001 From: Daniel Dickinson Date: Tue, 10 Jan 2017 15:19:45 -0500 Subject: [PATCH 7/8] net/nut: Avoid building with libwrap when present We don't want non-deterministic builds do turn off libwrap in configure options. Signed-off-by: Daniel Dickinson --- net/nut/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/nut/Makefile b/net/nut/Makefile index 629f60ef8..c5168b4a4 100644 --- a/net/nut/Makefile +++ b/net/nut/Makefile @@ -86,7 +86,8 @@ define Package/nut-common DEPENDS:= nut \ +NUT_DRIVER_SNMP:libnetsnmp \ +NUT_DRIVER_USB:libusb-compat \ - +NUT_SSL:libopenssl + +NUT_SSL:libopenssl \ + +PACKAGE_libwrap:libwrap endef define Package/nut-common/description @@ -501,6 +502,7 @@ CONFIGURE_ARGS += \ --$(if $(CONFIG_NUT_DRIVER_SERAL),with,without)-serial \ --without-neon \ --without-powerman \ + --without-wrap \ --with-cgi \ --without-ipmi \ --without-freeipmi \ From 604f22ee69898fb1ba3807d086f70ddcbc4e1fd5 Mon Sep 17 00:00:00 2001 From: Daniel Dickinson Date: Wed, 11 Jan 2017 18:59:15 -0500 Subject: [PATCH 8/8] net/nut: Ship upsset.conf for nut-cgi Per user request ship the sample upsset.conf file so that upsset functionality can be used with nut-cgi Signed-off-by: Daniel Dickinson --- net/nut/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/nut/Makefile b/net/nut/Makefile index c5168b4a4..714a59879 100644 --- a/net/nut/Makefile +++ b/net/nut/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=nut PKG_VERSION:=2.7.4 -PKG_RELEASE:=3 +PKG_RELEASE:=4 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=http://www.networkupstools.org/source/2.7/ @@ -307,6 +307,7 @@ define Package/nut-web-cgi/install $(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 + $(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/nut/upsset.conf.sample $(1)/etc/nut/upsset.conf $(INSTALL_DIR) $(1)/etc/config $(INSTALL_CONF) ./files/nut_cgi $(1)/etc/config/nut_cgi $(INSTALL_DIR) $(1)/etc/init.d