Import ports/sysutils/apcupsd, a daemon for monitoring APC UPSes.

We already have sysutils/apc-upsd which hasn't been maintained upstream
in >10 years, which I intend to rm unless there are objections.

From maintainer Kirill Bychkov with various input from myself.

Apcupsd can be used for power mangement and controlling most of APC's
UPS models. Apcupsd works with most of APC's Smart-UPS models as well as
most simple signalling models such a Back-UPS, and BackUPS-Office.
During a power failure, apcupsd will inform the users about the power
failure and that a shutdown may occur. If power is not restored, a
system shutdown will follow when the battery is exhausted, a timeout
(seconds) expires, or runtime expires based on internal APC calculations
determined by power consumption rates.
This commit is contained in:
sthen 2010-05-25 21:56:33 +00:00
parent 407a7ddd8b
commit 8005714669
14 changed files with 402 additions and 0 deletions

114
sysutils/apcupsd/Makefile Normal file
View File

@ -0,0 +1,114 @@
# $OpenBSD: Makefile,v 1.1.1.1 2010/05/25 21:56:33 sthen Exp $
COMMENT-main = daemon for controlling APC UPSes
COMMENT-cgi = CGI scripts for web monitoring
COMMENT-x11 = gapcmon - GUI for apcupsd
DISTNAME = apcupsd-3.14.8
PKGNAME-main = ${DISTNAME}
PKGNAME-cgi = ${DISTNAME:S/-/-cgi-/}
PKGNAME-x11 = ${DISTNAME:S/-/-x11-/}
CATEGORIES = sysutils
HOMEPAGE = http://www.apcupsd.com
MAINTAINER = Kirill Bychkov <yason@linklevel.net>
# GPLv2
PERMIT_PACKAGE_CDROM = Yes
PERMIT_PACKAGE_FTP = Yes
PERMIT_DISTFILES_CDROM =Yes
PERMIT_DISTFILES_FTP = Yes
WANTLIB = c pthread
MASTER_SITES = ${MASTER_SITE_SOURCEFORGE:=apcupsd/}
CONFIGURE_STYLE = gnu old # old prevents overriding sysconfdir
USE_GMAKE = Yes
MAKE_FLAGS = VERBOSE=2
WEB_ROOT = /var/www
SUBST_VARS += WEB_ROOT
CONFIGURE_ARGS = --mandir=${LOCALBASE}/man \
--sbindir=${LOCALBASE}/sbin \
--sysconfdir=${SYSCONFDIR}/apcupsd \
--enable-install-distdir \
--with-cgi-bin=${WEB_ROOT}/cgi-bin/apcupsd \
--with-lock-dir=/var/run \
--with-nisip=127.0.0.1 \
--enable-usb
PSEUDO_FLAVORS = no_x11
FLAVORS = snmp
FLAVOR ?=
MULTI_PACKAGES = -main
MULTI_PACKAGES += -cgi
PREFIX-cgi = ${WEB_ROOT}
CONFIGURE_ARGS += --enable-cgi
LIB_DEPENDS-cgi = gd::graphics/gd
.if !${FLAVOR:L:Mno_x11}
MULTI_PACKAGES += -x11
USE_X11 = Yes
CONFIGURE_ARGS += --enable-gapcmon
LIB_DEPENDS-x11 = gio-2.0,glib-2.0,gmodule-2.0,gobject-2.0,gthread-2.0::devel/glib2 \
atk-1.0.>=2009::devel/atk \
cairo.>=7::graphics/cairo \
gconf-2.>=6::devel/gconf2
RUN_DEPENDS-x11 = :desktop-file-utils-*:devel/desktop-file-utils
WANTLIB-x11 += ORBit-2 X11 Xau Xcomposite Xcursor Xdamage Xdmcp Xext
WANTLIB-x11 += Xfixes Xi Xinerama Xrandr Xrender dbus-1 expat fontconfig
WANTLIB-x11 += freetype gdk-x11-2.0 gdk_pixbuf-2.0 glitz gtk-x11-2.0
WANTLIB-x11 += iconv intl m pango-1.0 pangocairo-1.0 pangoft2-1.0
WANTLIB-x11 += pixman-1 png pthread-stubs xcb xcb-render xcb-render-util
WANTLIB-x11 += z ${WANTLIB}
.endif
.if ${FLAVOR:L:Msnmp}
CONFIGURE_ARGS += --enable-net-snmp
LIB_DEPENDS-main += netsnmp::net/net-snmp
WANTLIB-main = ${WANTLIB} crypto
.endif
FAKE_FLAGS = sysconfdir=${TRUEPREFIX}/share/examples/apcupsd/etc
pre-configure:
perl -pi -e 's,/etc/apcupsd,${SYSCONFDIR}/apcupsd,g' \
${WRKSRC}/doc/apcupsd.8 ${WRKSRC}/doc/apcaccess.8
perl -pi -e 's,/usr/local/etc/apcupsd,${SYSCONFDIR}/apcupsd,g' \
${WRKSRC}/doc/apcupsd.conf.5
perl -pi -e 's,/etc/rc.apcupsd,${PREFIX}/sbin/apcupsctl,' \
${WRKSRC}/platforms/openbsd/README
perl -pi -e 's,cuaa0,cua00,' ${WRKSRC}/platforms/openbsd/README
post-install:
.for i in status rpt
${INSTALL_DATA_DIR} ${PREFIX}/share/examples/apcupsd/$i
.endfor
${INSTALL_DATA_DIR} ${PREFIX}/share/doc/apcupsd
${INSTALL_DATA} ${WRKSRC}/examples/status/* \
${PREFIX}/share/examples/apcupsd/status
${INSTALL_DATA} ${WRKSRC}/examples/rpt/* \
${PREFIX}/share/examples/apcupsd/rpt
${INSTALL_DATA} ${WRKSRC}/c ${PREFIX}/share/doc/apcupsd/COPYRIGHT
${INSTALL_DATA} ${WRKSRC}/COPYING ${PREFIX}/share/doc/apcupsd
${INSTALL_DATA} ${WRKSRC}/DISCLAIMER ${PREFIX}/share/doc/apcupsd
${INSTALL_DATA} ${WRKSRC}/platforms/openbsd/README \
${PREFIX}/share/doc/apcupsd/README.openbsd
${INSTALL_DATA} ${WRKSRC}/src/cgi/apcupsd.css \
${PREFIX}/share/examples/apcupsd/etc
${INSTALL_DATA} ${WRKSRC}/src/cgi/README \
${WRKINST}/${WEB_ROOT}/cgi-bin/apcupsd/README
${INSTALL_SCRIPT} ${FILESDIR}/copy-libs.sh \
${WRKINST}/${WEB_ROOT}/cgi-bin/apcupsd/
cd ${PREFIX}/share; chown -R root:wheel doc/apcupsd examples/apcupsd
chmod 755 ${PREFIX}/sbin/apcupsctl
.include <bsd.port.mk>

View File

@ -0,0 +1,5 @@
MD5 (apcupsd-3.14.8.tar.gz) = zRfwqQPcIiDlXtVOJCNZ0g==
RMD160 (apcupsd-3.14.8.tar.gz) = 9kJYLgFQbruYbBbfAUKea7CMfos=
SHA1 (apcupsd-3.14.8.tar.gz) = y3p7QBeX4SnJKmuNwr97GTsdbHI=
SHA256 (apcupsd-3.14.8.tar.gz) = jn8ldNOrr2Y32j55CGDD+bpk+rHsflC7CA3kQ5RBxac=
SIZE (apcupsd-3.14.8.tar.gz) = 1317601

View File

@ -0,0 +1,10 @@
#!/bin/sh -e
if [ `id -u` != 0 ]; then
echo `basename $0`: must be run as root
exit 1
fi
for i in `ldd /var/www/cgi-bin/apcupsd/upsimage.cgi | sed -e '1,3d' -e 's/^.* \([^ ]*\)$/\1/g'`; do
cp $i /var/www/$i
done

View File

@ -0,0 +1,27 @@
$OpenBSD: patch-platforms_openbsd_Makefile,v 1.1.1.1 2010/05/25 21:56:33 sthen Exp $
--- platforms/openbsd/Makefile.orig Sun Jun 1 22:57:55 2008
+++ platforms/openbsd/Makefile Sun May 16 15:25:58 2010
@@ -5,8 +5,12 @@ include $(topdir)/autoconf/targets.mak
all-install: install-openbsd
all-uninstall: uninstall-openbsd
-
+
install-openbsd:
+ $(call MKDIR,$(sbindir))
+ $(call INSTPROG,744,apcupsd,$(sbindir)/apcupsctl)
+
+xx-install-openbsd:
$(call DISTINST,OpenBSD)
$(call MKDIR,/etc)
$(call INSTPROG,744,apcupsd,/etc/rc.apcupsd)
@@ -48,6 +52,9 @@ install-openbsd:
fi
uninstall-openbsd:
+ $(call UNINST,$(sbindir)/apcupsctl)
+
+xx-uninstall-openbsd:
$(call DISTUNINST,OpenBSD)
-$(call UNINST,/etc/rc.apcupsd)
$(VV)-today="`date +%Y%m%d%H%M`"; \

View File

@ -0,0 +1,83 @@
$OpenBSD: patch-src_apcupsd_c,v 1.1.1.1 2010/05/25 21:56:33 sthen Exp $
--- src/apcupsd.c.orig Tue May 18 02:07:50 2010
+++ src/apcupsd.c Tue May 18 02:20:02 2010
@@ -68,9 +68,10 @@ UPSINFO *core_ups = NULL;
static void daemon_start(void);
-int shm_OK = 0;
+int pidcreated = 0;
extern int kill_on_powerfail;
extern FILE *trace_fd;
+extern char *pidfile;
/*
* The terminate function and trapping signals allows apcupsd
@@ -91,11 +92,10 @@ void apcupsd_terminate(int sig)
log_event(ups, LOG_WARNING, _("apcupsd exiting, signal %u\n"), sig);
clear_files();
-
device_close(ups);
-
delete_lockfile(ups);
-
+ if (pidcreated)
+ unlink(pidfile);
clean_threads();
log_event(ups, LOG_WARNING, _("apcupsd shutdown succeeded"));
destroy_ups(ups);
@@ -107,6 +107,8 @@ void apcupsd_error_cleanup(UPSINFO *ups)
{
device_close(ups);
delete_lockfile(ups);
+ if (pidcreated)
+ unlink(pidfile);
clean_threads();
log_event(ups, LOG_ERR, _("apcupsd error shutdown completed"));
destroy_ups(ups);
@@ -261,7 +263,6 @@ int main(int argc, char *argv[])
Dmsg1(10, "Attached to driver: %s\n", ups->driver->driver_name);
ups->start_time = time(NULL);
- delete_lockfile(ups);
if (!hibernate_ups && !shutdown_ups && go_background) {
daemon_start();
@@ -270,7 +271,6 @@ int main(int argc, char *argv[])
openlog("apcupsd", LOG_CONS | LOG_PID, ups->sysfac);
}
- make_pid_file();
init_signals(apcupsd_terminate);
/* Create temp events file if we are not doing a hibernate or shutdown */
@@ -282,6 +282,14 @@ int main(int argc, char *argv[])
}
}
+ if (create_lockfile(ups) == LCKERROR) {
+ Error_abort1(_("Failed to acquire device lock file\n"),
+ ups->device);
+ }
+
+ make_pid_file();
+ pidcreated = 1;
+
setup_device(ups);
if (hibernate_ups) {
@@ -295,13 +303,6 @@ int main(int argc, char *argv[])
}
prep_device(ups);
-
- if (create_lockfile(ups) == LCKERROR) {
- Error_abort1(_("Failed to reacquire serial port lock file on device %s\n"),
- ups->device);
- }
-
- shm_OK = 1;
/*
* From now ... we must _only_ start up threads!

View File

@ -0,0 +1,12 @@
$OpenBSD: patch-src_gapcmon_gapcmon_h,v 1.1.1.1 2010/05/25 21:56:33 sthen Exp $
--- src/gapcmon/gapcmon.h.orig Sun May 16 14:30:57 2010
+++ src/gapcmon/gapcmon.h Sun May 16 14:29:53 2010
@@ -69,7 +69,7 @@ G_BEGIN_DECLS
#define GAPC_REFRESH_FACTOR_1K 1000 /* micro.secs for visual refresh */
#define GAPC_REFRESH_FACTOR_ONE_TIME 500
-#define GAPC_HOST_DEFAULT "localhost"
+#define GAPC_HOST_DEFAULT "127.0.0.1"
#define GAPC_PORT_DEFAULT 3551
#define GAPC_WATT_DEFAULT 600
#define GAPC_REFRESH_DEFAULT 8.0

View File

@ -0,0 +1,2 @@
CGI scripts that can query an apcupsd and display information
and statistics on a web page.

View File

@ -0,0 +1,8 @@
Apcupsd can be used for power mangement and controlling most of APC's
UPS models. Apcupsd works with most of APC's Smart-UPS models as well as
most simple signalling models such a Back-UPS, and BackUPS-Office.
During a power failure, apcupsd will inform the users about the power
failure and that a shutdown may occur. If power is not restored, a
system shutdown will follow when the battery is exhausted, a timeout
(seconds) expires, or runtime expires based on internal APC calculations
determined by power consumption rates.

View File

@ -0,0 +1 @@
Gnome monitoring application for apcupsd

View File

@ -0,0 +1,10 @@
Before using multimon and the other CGI programs, first ensure that
apcupsd is configured to run the Network Information Server. This is
done by setting NETSERVER on in ${SYSCONFDIR}/apcupsd/apcupsd.conf.
This switch is on by default.
To run scripts in chrooted apache (default behaviour), configuration
files must be available to the webserver:
# mv ${SYSCONFDIR}/apcupsd /var/www/${SYSCONFDIR}/apcupsd
# ln -s /var/www/${SYSCONFIDR}/apcupsd ${SYSCONFDIR}/
And some libraries must be copied in:
# ${WEB_ROOT}/cgi-bin/apcupsd/copy-libs.sh

View File

@ -0,0 +1,20 @@
To start apcupsd at boot time, edit ${SYSCONFDIR}/apcupsd/apcupsd.conf
and add the following lines to ${SYSCONFDIR}/rc.local:
if [ -x ${PREFIX}/sbin/apcupsd]; then
echo -n ' apcupsd'; ${PREFIX}/sbin/apcupsctl start
fi
To allow the system to be fully powered down (in order to preserve
UPS battery), add the following lines to ${SYSCONFDIR}/rc.shutdown:
if [ -f ${SYSCONFDIR}/apcupsd/powerfail ]; then
echo
echo "APCUPSD requested this system is powered down."
echo
powerdown=YES
echo
echo "Please ensure that the UPS has powered off before rebooting"
echo "Otherwise, the UPS may cut the power during the reboot!!!"
echo
fi

View File

@ -0,0 +1,11 @@
@comment $OpenBSD: PLIST-cgi,v 1.1.1.1 2010/05/25 21:56:33 sthen Exp $
cgi-bin/apcupsd/
@group bin
cgi-bin/apcupsd/README
@mode 700
cgi-bin/apcupsd/copy-libs.sh
@mode
@bin cgi-bin/apcupsd/multimon.cgi
@bin cgi-bin/apcupsd/upsfstats.cgi
@bin cgi-bin/apcupsd/upsimage.cgi
@bin cgi-bin/apcupsd/upsstats.cgi

View File

@ -0,0 +1,84 @@
@comment $OpenBSD: PLIST-main,v 1.1.1.1 2010/05/25 21:56:33 sthen Exp $
@group bin
@man man/man5/apcupsd.conf.5
@man man/man8/apcaccess.8
@man man/man8/apccontrol.8
@man man/man8/apctest.8
@man man/man8/apcupsd.8
@bin sbin/apcaccess
@bin sbin/apctest
sbin/apcupsctl
@bin sbin/apcupsd
@bin sbin/smtp
@comment share/applications/
share/doc/apcupsd/
@group
share/doc/apcupsd/COPYING
share/doc/apcupsd/COPYRIGHT
share/doc/apcupsd/DISCLAIMER
share/doc/apcupsd/README.openbsd
share/examples/apcupsd/
share/examples/apcupsd/etc/
@sample ${SYSCONFDIR}/apcupsd/
share/examples/apcupsd/etc/apccontrol
@mode 744
@sample ${SYSCONFDIR}/apcupsd/apccontrol
@mode
share/examples/apcupsd/etc/apcupsd.conf
@sample ${SYSCONFDIR}/apcupsd/apcupsd.conf
share/examples/apcupsd/etc/apcupsd.css
@sample ${SYSCONFDIR}/apcupsd/apcupsd.css
share/examples/apcupsd/etc/changeme
@mode 744
@sample ${SYSCONFDIR}/apcupsd/changeme
@mode
share/examples/apcupsd/etc/commfailure
@mode 744
@sample ${SYSCONFDIR}/apcupsd/commfailure
@mode
share/examples/apcupsd/etc/commok
@mode 744
@sample ${SYSCONFDIR}/apcupsd/commok
@mode
share/examples/apcupsd/etc/hosts.conf
@sample ${SYSCONFDIR}/apcupsd/hosts.conf
share/examples/apcupsd/etc/multimon.conf
@sample ${SYSCONFDIR}/apcupsd/multimon.conf
share/examples/apcupsd/etc/offbattery
@mode 744
@sample ${SYSCONFDIR}/apcupsd/offbattery
@mode
share/examples/apcupsd/etc/onbattery
@mode 744
@sample ${SYSCONFDIR}/apcupsd/onbattery
@mode
share/examples/apcupsd/rpt/
share/examples/apcupsd/rpt/Back-UPS-350-USB.rpt
share/examples/apcupsd/rpt/Back-UPS-350ES.rpt
share/examples/apcupsd/rpt/Back-UPS-500-USB.rpt
share/examples/apcupsd/rpt/Back-UPS-500ES.rpt
share/examples/apcupsd/rpt/Back-UPS-BR-800.rpt
share/examples/apcupsd/rpt/Back-UPS-CS-650.rpt
share/examples/apcupsd/rpt/Back-UPS-ES-550.rpt
share/examples/apcupsd/rpt/Back-UPS-XS-1300-LCD.rpt
share/examples/apcupsd/rpt/BackUPS.rpt
share/examples/apcupsd/rpt/Smart-UPS-1500.rpt
share/examples/apcupsd/rpt/SmartUPS-USB.rpt
share/examples/apcupsd/rpt/SmartUPS.rpt
share/examples/apcupsd/rpt/hid-ups.rpt
share/examples/apcupsd/status/
share/examples/apcupsd/status/Back-UPS-BX-1500.status
share/examples/apcupsd/status/Back-UPS-Pro-1000.status
share/examples/apcupsd/status/BackUPS-USB.status
share/examples/apcupsd/status/JapaneseUPS.status
share/examples/apcupsd/status/PowerStack450.status
share/examples/apcupsd/status/SmartUPS-vs-650.status
share/examples/apcupsd/status/SmartUPS1000.status
share/examples/apcupsd/status/SmartUPS1400.status
share/examples/apcupsd/status/SmartUPS3000.status
share/examples/apcupsd/status/SmartUPS5000.status
share/examples/apcupsd/status/SmartUPS600.status
share/examples/apcupsd/status/SmartUPS700-2.status
share/examples/apcupsd/status/SmartUPS700.status
share/examples/apcupsd/status/newbackupspro1.status
share/examples/apcupsd/status/newbackupspro2.status

View File

@ -0,0 +1,15 @@
@comment $OpenBSD: PLIST-x11,v 1.1.1.1 2010/05/25 21:56:33 sthen Exp $
@group bin
@bin bin/gapcmon
share/applications/gapcmon.desktop
@group
share/pixmaps/
@group bin
share/pixmaps/apcupsd.png
share/pixmaps/charging.png
share/pixmaps/gapc_prefs.png
share/pixmaps/onbatt.png
share/pixmaps/online.png
share/pixmaps/unplugged.png
@exec %D/bin/update-desktop-database
@unexec-delete %D/bin/update-desktop-database