apcupsd, a daemon to manage and monitor APC UPSes.

This commit is contained in:
bouyer 2000-01-21 19:15:59 +00:00
parent 3bf6037ae5
commit 9de579284d
15 changed files with 485 additions and 0 deletions

29
sysutils/apcupsd/Makefile Normal file
View file

@ -0,0 +1,29 @@
# $NetBSD: Makefile,v 1.1.1.1 2000/01/21 19:15:59 bouyer Exp $
#
DISTNAME= apcupsd-3.5.8.src
PKGNAME= apcupsd-3.5.8
CATEGORIES= sysutils
MASTER_SITES= ftp://sunsite.unc.edu/pub/linux/system/ups/
MAINTAINER= bouyer@netbsd.org
HOMEPAGE= http://www.brisse.dk/site/apcupsd/
USE_GMAKE= yes
do-install:
${INSTALL_PROGRAM} ${WRKSRC}/apcupsd-netbsd ${PREFIX}/sbin/apcupsd
${INSTALL_PROGRAM} ${WRKSRC}/apcaccess-netbsd ${PREFIX}/bin/apcaccess
${SED} -e 's|@@PREFIX@@|${PREFIX}|' ${WRKSRC}/installs/powersc > \
${WRKDIR}/powersc
${INSTALL_SCRIPT} ${WRKDIR}/powersc ${PREFIX}/sbin/
${SED} -e 's|@@PREFIX@@|${PREFIX}|' ${WRKSRC}/installs/apcupsd.conf > \
${WRKDIR}/apcupsd.conf.sample
${INSTALL_DATA} ${WRKDIR}/apcupsd.conf.sample ${PREFIX}/etc/
@${MKDIR} ${PREFIX}/share/doc/apcupsd
${INSTALL_DATA} ${WRKSRC}/readmes/README* \
${WRKSRC}/readmes/minicom.apcupsd ${PREFIX}/share/doc/apcupsd/
${SED} -e 's|@@PREFIX@@|${PREFIX}|' ${WRKSRC}/docs/apcupsd.man8 > \
${WRKDIR}/apcupsd.8
${INSTALL_MAN} ${WRKDIR}/apcupsd.8 ${PREFIX}/man/man8/
.include "../../mk/bsd.pkg.mk"

View file

@ -0,0 +1,3 @@
$NetBSD: md5,v 1.1.1.1 2000/01/21 19:15:59 bouyer Exp $
MD5 (apcupsd-3.5.8.src.tar.gz) = ced9e22844bd9b490bb5ec7dbed8b014

View file

@ -0,0 +1,52 @@
$NetBSD: patch-aa,v 1.1.1.1 2000/01/21 19:15:59 bouyer Exp $
--- Makefile.orig Wed Apr 7 18:06:41 1999
+++ Makefile Tue Jul 20 18:36:50 1999
@@ -85,7 +85,7 @@
SHELL = /bin/sh
ECHO = echo
-MAKE = make
+MAKE ?= make
CHOWN = chown
CHMOD = chmod
CP = cp
@@ -120,6 +120,7 @@
#* *
#****************************************************************************
+all: netbsd
default :
@$(ECHO)
@$(ECHO) "Usage: make <system-type>"
@@ -201,7 +202,7 @@
@$(ECHO) >> .ver
@$(ECHO) \#ifndef __$(OS)__ >> .ver
@$(ECHO) \#define __$(OS)__ >> .ver
- @$(ECHO) \#endif /*\ __$(OS)__ *\/ >> .ver
+ @$(ECHO) \#endif /*\ __$(OS)__\ \*\/ >> .ver
@$(ECHO) >> .ver
@if [ -d /usr/include/ncurses ]; then \
if [ -f /usr/include/ncurses/curses.h ]; then \
@@ -227,7 +228,7 @@
$(ECHO) \#undef __CURSES__ >> .ver; \
fi
@$(ECHO) >> .ver
- @$(ECHO) \#endif /*\_APC_VERSION_H *\/ >> .ver
+ @$(ECHO) \#endif /*\_APC_VERSION_H\ \*\/ >> .ver
@$(MV) -f .ver $@
ifdef MUSIC
@@ -301,6 +302,12 @@
@$(MAKE) depend $(APCUPSD) \
OS="freebsd" \
CC="cc"
+
+netbsd :
+ @$(MAKE) depend $(APCUPSD) \
+ OS="netbsd" \
+ CC="cc"
+
# Generic: Generic BSD-ish system running gcc

View file

@ -0,0 +1,14 @@
$NetBSD: patch-ab,v 1.1.1.1 2000/01/21 19:15:59 bouyer Exp $
--- apcaction.c Wed Apr 7 18:06:41 1999
+++ apcaction.c Sun Jul 18 19:48:13 1999
@@ -59,7 +59,9 @@
#include <stdio.h>
#include <unistd.h>
+#ifndef __NetBSD__
#include <getopt.h>
+#endif /* __NetBSD__ */
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>

View file

@ -0,0 +1,20 @@
$NetBSD: patch-ac,v 1.1.1.1 2000/01/21 19:15:59 bouyer Exp $
--- apchttp.c Wed Apr 7 18:06:41 1999
+++ apchttp.c Sun Jul 18 19:50:58 1999
@@ -70,7 +70,6 @@
#include <ctype.h>
#include <errno.h>
-#include <netinet/in.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@@ -80,6 +79,7 @@
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
+#include <netinet/in.h>
/* apc includes */
#include <apc_version.h>

View file

@ -0,0 +1,14 @@
$NetBSD: patch-ad,v 1.1.1.1 2000/01/21 19:15:59 bouyer Exp $
--- apcreports.c Wed Apr 7 18:06:41 1999
+++ apcreports.c Sun Jul 18 19:48:17 1999
@@ -58,7 +58,9 @@
#include <stdio.h>
#include <unistd.h>
+#ifndef __NetBSD__
#include <getopt.h>
+#endif /* __NetBSD__ */
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>

View file

@ -0,0 +1,73 @@
$NetBSD: patch-ae,v 1.1.1.1 2000/01/21 19:15:59 bouyer Exp $
--- apcserial.c.orig Wed Apr 7 18:06:41 1999
+++ apcserial.c Fri Jan 7 18:54:39 2000
@@ -59,7 +59,9 @@
#include <stdio.h>
#include <unistd.h>
+#ifndef __NetBSD__
#include <getopt.h>
+#endif /* __NetBSD__ */
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
@@ -135,10 +137,10 @@
newtio.c_oflag = 0; /* Raw output */
newtio.c_lflag = 0; /* No local echo */
-#ifdef __freebsd__
+#if defined(__freebsd__) || defined (__NetBSD__)
newtio.c_ispeed = DEFAULT_SPEED; /* Set input speed */
newtio.c_ospeed = DEFAULT_SPEED; /* Set output speed */
-#endif /* __freebsd__ */
+#endif /* __freebsd__ || __NetBSD__ */
/* w.p. This makes a non.blocking read() with 5 sec. timeout */
newtio.c_cc[VMIN] = 0;
@@ -195,7 +197,6 @@
{
char response[32]; /* w.p. */
char a;
- FILE *pwdf;
int errflag = 0;
response[0] = '\0';
@@ -230,19 +231,6 @@
}
}
}
- if ((((pwdf = fopen(PWRFAIL, "r" )) == NULL) &&
- (ups->mode.type != BK)) ||
- (((pwdf = fopen(PWRFAIL, "r" )) == NULL) &&
- (ups->LineUp != 0) && (ups->mode.type == BK))) {
- fprintf(stderr,
- "%s: Attempting to kill the power!\n" \
- "%s: Nice TRY but not TODAY!\n" \
- "%s: Shutdown not called first.\n" \
- "%s: Bug found by Tom Kunicki\n",
- ups->argvalue, ups->argvalue,
- ups->argvalue, ups->argvalue);
- terminate(0);
- } else {
errflag=0; /* w.p. */
if ((ups->class.type == SHAREMASTER) ||
(ups->class.type == SHARENETMASTER)) {
@@ -259,7 +247,6 @@
ups->argvalue);
sleep(15);
}
- fclose(pwdf);
fprintf(stderr,
"%s: Attempting to kill the power!\n",
@@ -407,9 +394,7 @@
}
}
/* w.p. */
- sleep(10);
terminate(0);
- }
} else {
if (ups->mode.type <= SHAREBASIC) {
switch(ups->cable.type) {

View file

@ -0,0 +1,28 @@
$NetBSD: patch-af,v 1.1.1.1 2000/01/21 19:15:59 bouyer Exp $
--- apcupsd.c.orig Wed Apr 7 18:06:41 1999
+++ apcupsd.c Fri Jan 7 18:55:53 2000
@@ -100,7 +100,9 @@
#include <stdio.h>
#include <unistd.h>
+#ifndef __NetBSD__
#include <getopt.h>
+#endif /* __NetBSD__ */
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
@@ -290,13 +292,6 @@
* it should close them.
*********************************************************************/
void terminate (int sig) {
- /*
- * XXX - Is someone able to explain me why here we find a sleep for 10
- * seconds ?
- *
- * -RF
- */
- sleep(10);
#ifdef NEW_THREADS
restore_signals();
#endif /* NEW_THREADS */

View file

@ -0,0 +1,17 @@
$NetBSD: patch-ag,v 1.1.1.1 2000/01/21 19:16:00 bouyer Exp $
--- include/apc_defines.h Wed Apr 7 18:06:41 1999
+++ nclude/apc_defines.h Sun Jul 18 19:45:49 1999
@@ -66,6 +66,12 @@
#define PWRFAIL "/var/run/powerfail"
#endif /* __freebsd__ */
+#ifdef __NetBSD__
+#define APCCONF "/etc/apcupsd.conf"
+#define UPS_STAT "/var/log/apcupsd.status"
+#define PWRFAIL "/var/run/powerfail"
+#endif /* __NetBSD__ */
+
#ifndef APCCONF
#define APCCONF "/etc/apcupsd.conf"
#endif

View file

@ -0,0 +1,75 @@
$NetBSD: patch-ah,v 1.1.1.1 2000/01/21 19:16:00 bouyer Exp $
--- docs/apcupsd.man8.orig Wed Apr 7 18:06:41 1999
+++ docs/apcupsd.man8 Tue Jul 20 19:27:28 1999
@@ -8,13 +8,13 @@
.SH NAME
apcupsd \- daemon for Most APCC's UPS support under Linux and UNIX
.SH SYNOPSIS
-.B /sbin/apcupsd
+.B @@PREFIX@@/sbin/apcupsd
.br
-.B /sbin/powersc
+.B @@PREFIX@@/sbin/powersc
.br
.B /etc/apcupsd.conf
.br
-.B /sbin/apcaccess
+.B @@PREFIX@@/bin/apcaccess
.SH DESCRIPTION
.LP
This daemon can be used for controlling the APC SmartUPS. During a power
@@ -23,7 +23,7 @@
about this fact. If power is not restored, a system shutdown will follow
when the battery is exausted, a timeout (seconds) expires, or runtime
minutes based on internal values based on power consumption rates. The
-whole shutdown is now made by script calls to the "/sbin/powersc"
+whole shutdown is now made by script calls to the "@@PREFIX@@/sbin/powersc"
file called by "apcupsd", so no changes in the inittab are necessary.
There is now no communication between "apcupsd" and init(1) process.
.LP
@@ -46,7 +46,7 @@
.SH CONFIGURATION
It is necessary to write configuration info to the file "/etc/apcupsd.conf".
This file is a plain ASCII file and you can use your favorite editor for
-configuration. For simple configuration, see enclosed sample file.
+configuration. For simple configuration, see sample file in @@PREFIX@@/etc
.LP
Configuration commands in
.B /etc/apcupsd.conf
@@ -54,7 +54,7 @@
.LP
.B CONTROL
-- <path|filename>
-.B /sbin/powersc
+.B @@PREFIX@@/sbin/powersc
.br
Name of control script called by "apcupsd".
.LP
@@ -123,7 +123,7 @@
-- <name of serial port>
.br
Please specify which device is used for UPS communication.
-The default is /dev/ttyS[0|1|2|3].
+The default is /dev/tty0[0|1|2|3].
.LP
.B LOCKFILE
-- <path to lockfile>
@@ -165,7 +165,7 @@
-- <time in seconds>
.br
Please specify time in seconds for "apcupsd" to update the psuedo
-proc fs file "/etc/apcupsd.status". This rate is reset if there is
+proc fs file "/var/log/apcupsd.status". This rate is reset if there is
a power state change.
.LP
This will be replaced with "apcaccess 'status'" calls. This will prevent
@@ -478,7 +478,7 @@
.B /etc/apcupsd.conf
- configuration file.
.br
-.B /etc/apcupsd.status
+.B /var/log/apcupsd.status
- psuedo procfs-type file.
.br
.B /var/log/apcupsd.log

View file

@ -0,0 +1,112 @@
$NetBSD: patch-ai,v 1.1.1.1 2000/01/21 19:16:00 bouyer Exp $
--- installs/powersc.orig Tue Jul 20 18:58:51 1999
+++ installs/powersc Tue Jul 20 19:14:13 1999
@@ -4,25 +4,9 @@
POWERPID=/var/run/power.pid
APCPID=/var/run/apcupsd.pid
-if [ -x /sbin/shutdown ]; then
SHUTDOWN=/sbin/shutdown
-elif [ -x /sbin/shutdown.bsd ]; then
- SHUTDOWN=/sbin/shutdown.bsd
-else
- echo Command shutdown or shutdown.bsd not found!
- exit 1
-fi
-if [ -x /usr/local/sbin/apcupsd ]; then
- APCUPSD=/usr/local/sbin/apcupsd
-elif [ -x /usr/sbin/apcupsd ]; then
- APCUPSD=/usr/sbin/apcupsd
-elif [ -x /sbin/apcupsd ]; then
- APCUPSD=/sbin/apcupsd
-else
- echo Command apcupsd not found!
- exit 1
-fi
+ APCUPSD=@@PREFIX@@/sbin/apcupsd
if test "$(whoami)" != "root"; then
printf "Sorry, you must be root to run this script." | wall
@@ -32,42 +16,52 @@
case "$1" in
POWEROUT)
printf "Warning there are Power problems." | wall
+ /usr/bin/logger -p user.info -t apcupsd \
+ "Warning there are Power problems."
;;
ONBATTERY)
printf "Power Failure running on UPS." | wall
+ /usr/bin/logger -p user.info -t apcupsd \
+ "Power Failure running on UPS."
;;
FAILING)
printf "Battery Power Failed, Normal Shutdown.\n" | wall
+ /usr/bin/logger -p user.emerg -t apcupsd \
+ "UPS Battery Power Failed, Normal Shutdown."
;;
TIMEOUT)
printf "Online Battery timeout, Normal Shutdown.\n" | wall
+ /usr/bin/logger -p user.emerg -t apcupsd \
+ "UPS Online Battery timeout, Normal Shutdown."
;;
LOADLIMIT)
printf "Battery Load Limits Reached, Normal Shutdown.\n" | wall
+ /usr/bin/logger -p user.emerg -t apcupsd \
+ "UPS Battery Load Limits Reached, Normal Shutdown."
;;
RUNLIMIT)
printf "Battery RunTime Limits Reached, Normal Shutdown.\n" | wall
+ /usr/bin/logger -p user.emerg -t apcupsd \
+ "Battery RunTime Limits Reached, Normal Shutdown."
;;
DOSHUTDOWN)
printf "Beginning Shutdown Sequence!!!!!" | wall
- ps x | gawk '{ if (($5 == "init") && ($1 == "1")) print $6 }' \
- | cut -f2 -d[ | cut -f1 -d] \
- > /tmp/run.level.power
if [ -f $POWERPID ]
then
exit 0
else
echo $$ > $POWERPID
- $SHUTDOWN -h now
+ $SHUTDOWN -h now "UPS Powerfail"
fi
;;
MAINSBACK | WAITASEC)
printf "Power has returned..." | wall
+ /usr/bin/logger -p user.info -t apcupsd \
+ "Power has returned..."
if [ -f $POWERPID ]; then
printf "Attempting to cancel shutdown."
kill $(cat $POWERPID)
rm -f $POWERPID
- init $(cat /tmp/run.level.power)
fi
;;
ANNOYME)
@@ -75,14 +69,20 @@
;;
EMERGENCY)
printf "Emergency Shutdown, Possible Battery Failure!!!!" | wall
- $SHUTDOWN -h now
+ /usr/bin/logger -p user.emerg -t apcupsd \
+ "Emergency Shutdown, Possible Battery Failure!!!!"
+ $SHUTDOWN -h now "Emergency Shutdown"
;;
CHANGEME)
printf "Emergency, Batteries Have Failed!!!!\nChange Them NOW!!!!" | wall
+ /usr/bin/logger -p user.emerg -t apcupsd \
+ "Emergency, Batteries Have Failed!!!! Change Them NOW!!!!"
;;
REMOTE)
printf "Remote Calls, Normal Shutdown.\nBeginning Shutdown Sequence!!!!!" | wall
- $SHUTDOWN -h now
+ /usr/bin/logger -p user.emerg -t apcupsd \
+ "Remote Calls, Normal Shutdown"
+ $SHUTDOWN -h now "Remote Calls, Normal Shutdown"
;;
KILL) sleep 1
$APCUPSD killpower

View file

@ -0,0 +1,26 @@
$NetBSD: patch-aj,v 1.1.1.1 2000/01/21 19:16:00 bouyer Exp $
--- installs/apcupsd.conf.orig Tue Jul 20 19:32:16 1999
+++ installs/apcupsd.conf Tue Jul 20 19:32:54 1999
@@ -3,7 +3,7 @@
# "apcupsd" POSIX config file
#
# CONTROL <string>
-CONTROL /sbin/powersc
+CONTROL @@PREFIX@@/sbin/powersc
#
# UPSCABLE [ simple | smart | 940-00(20B,23A,24B,24C,24G,95A,95C) | ether ]
UPSCABLE 940-0024B
@@ -22,10 +22,10 @@
UPSMODE disable
#
#DEVICE <string> /dev/<serial port>
-DEVICE /dev/ttyS0
+DEVICE /dev/tty00
#
#LOCKFILE <path to lockfile>
-LOCKFILE /var/lock
+LOCKFILE /var/run
#
#ACCESS <string> [ true | false ] Enable Access Support
ACCESS true

View file

@ -0,0 +1 @@
UPS power management under for APCC Products.

View file

@ -0,0 +1,5 @@
It allows your computer/server to run during power problems
for a specified length of time or the life of the batteries
in your BackUPS, BackUPS Pro, SmartUPS v/s, or SmartUPS, and
then properly executes a controlled shutdown during an
extended power failure.

View file

@ -0,0 +1,16 @@
@comment $NetBSD: PLIST,v 1.1.1.1 2000/01/21 19:15:59 bouyer Exp $
bin/apcaccess
sbin/apcupsd
sbin/powersc
etc/apcupsd.conf.sample
man/man8/apcupsd.8
share/doc/apcupsd/README.BackUPS-Pro
share/doc/apcupsd/README.NewerBackUPS-Pro
share/doc/apcupsd/README.Share-UPS
share/doc/apcupsd/README.SmartUPS-VS
share/doc/apcupsd/README.apcaccess
share/doc/apcupsd/README.autoconfig
share/doc/apcupsd/README.cable
share/doc/apcupsd/minicom.apcupsd
@dirrm share/doc/apcupsd