#294256 apcupsd: Multiple instances apcupsd for multiple APCs (patch provided)

Package:
apcupsd
Source:
apcupsd
Description:
APC UPS Power Management (daemon)
Submitter:
Yaroslav Halchenko
Date:
2015-05-01 10:00:05 UTC
Severity:
wishlist
#294256#5
Date:
2005-02-08 19:07:55 UTC
From:
To:
Dear Maintainer,

It would be very useful to have next patch applied. It let me start 3
independent apcupsd to manage 3 attached (1 serial+2 usb) APCs with no
harm. Of cause they all should have separate configuration files
/etc/apcupsd/apcupsd*conf with different port numbers
assigned. Besides that it is very easy to setup and use.

Besides that it has a bit improved reporting of the problem if
start/stop failed

Here is the patch
--------------starts
--- apcupsd.dpkg-dist	2005-02-07 13:28:33.000000000 -0500
+++ apcupsd	2005-02-08 14:00:36.071268581 -0500
@@ -6,6 +6,8 @@

 DAEMON=/sbin/apcupsd
 CONFIG=/etc/default/apcupsd
+CONFIGFILES=/etc/apcupsd/apcupsd*.conf
+POWERFAIL=/var/spool/apcupsd/powerfail

 test -x $DAEMON || exit 0

@@ -25,23 +27,34 @@
 case "$1" in
 	start)
 		echo -n "Starting APC UPS power management: "
-		rm -f /var/spool/apcupsd/powerfail
-    		if [ "`pidof apcupsd`" = "" ]
-    		then
-        		start-stop-daemon --start --quiet --exec $DAEMON
-        		echo "apcupsd."
-    		else
-        		echo ""
-        		echo "A copy of the daemon is still running.  If you just stopped it,"
-        		echo "please wait about 5 seconds for it to shut down."
-        		exit 0
-    		fi
+		rm -f $POWERFAIL
+		for f in $CONFIGFILES
+		do
+		   PIDFILE=`echo $f | sed 's/.*apcupsd\([^.]*\).conf/\/var\/run\/apcupsd\1.pid/g'`
+		   echo -n "$PIDFILE "
+		   if [ ! -e /proc/`cat /var/run/apcupsd.pid` ]
+		   then
+		       start-stop-daemon --start --pidfile $PIDFILE --quiet --exec $DAEMON -- -f $f -P $PIDFILE \
+			   || echo -n "failed! "
+#		       sleep 2
+		   else
+		       echo ""
+		       echo "A copy of the daemon is still running.  If you just stopped it,"
+		       echo "please wait about 5 seconds for it to shut down."
+		       exit 0
+		   fi
+		done
+		echo ""
   	;;
   	stop)
     		echo -n "Stopping APC UPS power management: "
-    		#start-stop-daemon --stop --quiet --exec $DAEMON
-    		echo "apcupsd."
-		start-stop-daemon --stop --pidfile /var/run/apcupsd.pid || echo "Not Running."
+		for f in $CONFIGFILES
+		do
+		   PIDFILE=`echo $f | sed 's/.*apcupsd\([^.]*\).conf/\/var\/run\/apcupsd\1.pid/g'`
+		   echo -n "$PIDFILE "
+		   start-stop-daemon --stop --pidfile $PIDFILE --quiet --exec $DAEMON \
+		     || echo -n "failed: not running? "
+		done
 		echo ""

   	;;
--------------ends
#294256#10
Date:
2005-02-14 16:01:55 UTC
From:
To:
If the submitter of this bug report would like us to include his idea in
the apcupsd release, we will be glad to do so. For that to happen, we
will need a small document describing it and how to use it as well as
the full script. I'm not sure we will integrate it into the mainstream
code (I reserve judgment on this ...), but at a minimum we can include
the script and the document in our examples directory.

Send the full script and document to apcuspd-users@lists.sourceforge.net

#294256#15
Date:
2005-11-22 18:28:14 UTC
From:
To:
There were a few bugs in the patch previously attached to this bug;
FWIW, here's an updated version (against 3.10.17-2).
--- apcupsd.dpkg-dist 2005-04-03 06:40:19.000000000 -0500 +++ apcupsd 2005-11-20 20:21:23.000000000 -0600 @@ -6,6 +6,8 @@ DAEMON=/sbin/apcupsd CONFIG=/etc/default/apcupsd +CONFIGFILES=/etc/apcupsd/apcupsd*.conf +POWERFAIL=/var/spool/apcupsd/powerfail test -x $DAEMON || exit 0 @@ -24,36 +26,50 @@ case "$1" in start) - echo -n "Starting APC UPS power management: " - rm -f /etc/apcupsd/powerfail - if [ "`pidof apcupsd`" = "" ] - then - start-stop-daemon --start --quiet --exec $DAEMON - echo "apcupsd." - else + echo -n "Starting APC UPS power management:" + rm -f $POWERFAIL + for f in $CONFIGFILES + do + CONF=`echo $f | sed 's|^.*/\([^.]*\)\.conf$|\1|'` + PIDFILE=/var/run/${CONF}.pid + echo -n " $CONF" + if [ ! -f $PIDFILE -o ! -e /proc/`cat $PIDFILE 2>/dev/null` ] + then + start-stop-daemon --start --pidfile $PIDFILE --quiet \ + --exec $DAEMON -- -f $f -P $PIDFILE \ + || echo -n " failed!" + sleep 2 + else echo "" echo "A copy of the daemon is still running. If you just stopped it," echo "please wait about 5 seconds for it to shut down." exit 0 - fi + fi + done + echo "." ;; stop) - echo -n "Stopping APC UPS power management: " - #start-stop-daemon --stop --quiet --exec $DAEMON - echo "apcupsd." - start-stop-daemon --stop --pidfile /var/run/apcupsd.pid || echo "Not Running." - rm -f /var/run/apcupsd.pid - echo "" - + echo -n "Stopping APC UPS power management:" + for f in $CONFIGFILES + do + CONF=`echo $f | sed 's|^.*/\([^.]*\)\.conf$|\1|'` + PIDFILE=/var/run/${CONF}.pid + echo -n " $CONF" + start-stop-daemon --stop --pidfile $PIDFILE --quiet \ + --exec $DAEMON \ + || echo -n " failed: not running?" + done + echo "." ;; restart|force-reload) - echo -n "Restarting APC UPS power management: " + echo -n "Restarting APC UPS power management:" $0 stop sleep 10 $0 start ;; status) #/sbin/apcaccess status + # XXX only displays status for primary UPS $APCACCESS status ;; *)
#294256#20
Date:
2009-01-31 22:52:04 UTC
From:
To:
this patch looks good and works for me.

usage:
for each apcupsd instance you want to run, add a
/etc/apcupsd/apcupsd-$NAME.conf config file.

I've got apcupsd 3.12.4-2 on debian etch and am still missing this patch.
Has it already been aplied to upstream?

Thanks.
AZ

#294256#25
Date:
2009-01-31 23:24:52 UTC
From:
To:
Michael Braun wrote:

i'll address it post lenny.

#294256#30
Date:
2009-02-20 16:31:56 UTC
From:
To:
ok -- to make it more useful -- I've pushed my scripts (along with
original init.d script (in upstream branch) to

http://github.com/yarikoptic/apcupsd-multi/

Script of interest to Levon is assignAPC

hope this useful to someone ;-)

#294256#37
Date:
2013-07-11 20:47:47 UTC
From:
To:
The following updated patch to the init script more-or-less works with apcupsd
from squeeze (3.14.8-2), but segfaults with the version from wheezy (3.14.10-2)
for multiple acpupsd (the first does continue to work).

The patch applies to both versions cleanly, as the init script is identical.

It doesn't seem to consistantly stop the apcupsd processes though, but the PIDs
seem correct.

live well,
  vagrant
--- 3.14.10-2/etc/init.d/apcupsd	2012-05-28 01:55:29.000000000 -0700
+++ /etc/init.d/apcupsd	2013-07-11 13:31:48.000000000 -0700
@@ -15,6 +15,7 @@
 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 DAEMON=/sbin/apcupsd
 CONFIG=/etc/default/apcupsd
+CONFIGFILES=/etc/apcupsd/apcupsd*.conf
 NAME=apcupsd
 DESC="UPS power management"

@@ -38,23 +39,39 @@

 		rm -f /etc/apcupsd/powerfail

-		if [ "`pidof apcupsd`" = "" ]
-		then
-			start-stop-daemon --start --quiet --exec $DAEMON
-			echo "$NAME."
-		else
-			echo ""
-			echo "A copy of the daemon is still running.  If you just stopped it,"
-			echo "please wait about 5 seconds for it to shut down."
-			exit 0
-		fi
+		for f in $CONFIGFILES
+		do
+			CONF=`echo $f | sed 's|^.*/\([^.]*\)\.conf$|\1|'`
+			PIDFILE=/var/run/$(basename ${CONF}).pid
+			echo -n " $CONF"
+			if [ ! -f $PIDFILE -o ! -e /proc/`cat $PIDFILE 2>/dev/null` ]
+			then
+				start-stop-daemon --start --pidfile $PIDFILE --quiet \
+				--exec $DAEMON -- -f $f -P $PIDFILE \
+				|| echo -n " failed!"
+			else
+				echo ""
+				echo "A copy of the daemon is still running.  If you just stopped it,"
+				echo "please wait about 5 seconds for it to shut down."
+				exit 0
+			fi
+		done
+		echo "."
+
 		;;

 	stop)
 		echo -n "Stopping $DESC: "
-		start-stop-daemon --stop --oknodo --pidfile /var/run/apcupsd.pid || echo "Not Running."
-		rm -f /var/run/apcupsd.pid
-		echo "$NAME."
+		for f in $CONFIGFILES
+		do
+			CONF=`echo $f | sed 's|^.*/\([^.]*\)\.conf$|\1|'`
+			PIDFILE=/var/run/$(basename ${CONF}).pid
+			echo -n " $CONF"
+			start-stop-daemon --stop --pidfile $PIDFILE --quiet \
+				--exec $DAEMON \
+				|| echo -n " failed: not running?"
+		done
+		echo "."
 		;;

 	restart|force-reload)

#294256#42
Date:
2015-05-01 09:54:45 UTC
From:
To:
[...]

What's the status of this bug?

I think that having multiple-UPS support in apcupsd would significantly
improve the Debian package.

I tested the init.d apcupsd script (/etc/init.d/apcupsd) suggested on
https://wiki.debian.org/apcupsd#Configuring_.28Multiple_UPS_Devices.29
and it seems to work correctly: as soon as you create multiple
apcupsd*.conf files (with distinct UPSNAME, DEVICE, NISPORT,
EVENTSFILE, and STATFILE values), it starts multiples instances of
apcupsd.

Unfortunately, there's no licensing info on the wiki page...
If the author of this modified init.d script could be tracked down and
asked to license it under the same terms as apcupsd (GPL-2+), the
script could be adopted for the Debian package (after possible further
modifications...).
According to
https://wiki.debian.org/apcupsd?action=diff&rev1=2&rev2=3
it seems that the init.d script with multiple UPS support was added to
the wiki by a user nicknamed "paper".

What do the maintainers of the apcupsd Debian package think about this?
Please share your opinion.

Thanks for your time!
Bye.