APCUPSD does not send killpower command to UPS (only happens on Ubuntu 16.04)

Bug #1634572 reported by xb5i7o
62
This bug affects 12 people
Affects Status Importance Assigned to Milestone
apcupsd (Ubuntu)
Confirmed
Medium
Unassigned

Bug Description

I have spoken to users on the apcupsd mailing list and they seem to think this is a bug on Ubuntu 16.04.

as the title states, since i installed a fresh copy of Ubuntu 16.04, and compiled the latest version of apcupsd 3.14.14 source, when PC shuts down, killpower is not being sent to the UPS at all. Even when i see the final shutdown console before Ubuntu shuts down, there is no words of killpower being sent, like it used to do on Ubuntu 14.04:
It usually printed:
echo ""
 "apcupsd: Ordering UPS to kill power... "
 "done."
 "Please ensure the UPS has powered off before rebooting."
 "Otherwise, the UPS may cut the power during the reboot!"

But i dont see this message anymore, neither can i find any evidence of this in syslog or apcupsd.events log.
I was told that the USB's are shutdown before killpower is being sent.

This never used to happen to Ubuntu 14.04, it worked flawlessly and shut down the UPS correctly.
This is how i installed it before and how i installed it now:
cd apcupsd-3.14.14/
./configure --enable-usb
make
sudo make install

Does anyone know where the problem lies?

xb5i7o (xb5i7o)
tags: added: xenial
Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

Thank you for taking the time to report this bug and helping to make Ubuntu better. It seems that your bug report is not filed about a specific source package though, rather it is just filed against Ubuntu in general. It is important that bug reports be filed about source packages so that people interested in the package can find the bugs about it. You can find some hints about determining what package your bug might be about at https://wiki.ubuntu.com/Bugs/FindRightPackage. You might also ask for help in the #ubuntu-bugs irc channel on Freenode.

To change the source package that this bug is filed about visit https://bugs.launchpad.net/ubuntu/+bug/1634572/+editstatus and add the package name in the text box next to the word Package.

[This is an automated message. I apologize if it reached you inappropriately; please just reply to this message indicating so.]

tags: added: bot-comment
Paul White (paulw2u)
affects: ubuntu → apcupsd (Ubuntu)
Revision history for this message
xb5i7o (xb5i7o) wrote :

I have noticed as well, that sometimes when i update ubuntu, i get this near the end of the update:

insserv: warning: script 'K01apcupsd' missing LSB tags and overrides
insserv: warning: script 'ups-monitor' missing LSB tags and overrides
insserv: warning: script 'apcupsd' missing LSB tags and overrides

Is this the cause of the issue?

Revision history for this message
JanCeuleers (jan-ceuleers) wrote :

According to discussion on the apcupsd-users mailing list [1] this issue is OS-specific rather than being a problem in upstream apcupsd.

Specifically it is believed that this issue is due to Ubuntu shutting down USB before the killpower command is issued to the UPS, which which it is no longer possible to communicate without USB.

[1]: https://marc.info/?t=147606479000001&r=1&w=2

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in apcupsd (Ubuntu):
status: New → Confirmed
Revision history for this message
Alek_A (ackbeat) wrote :

> Specifically it is believed that this issue is due to Ubuntu shutting down USB before
> the killpower command is issued to the UPS, which which it is no longer possible to communicate
> without USB.

It seems that Ubuntu shuts down serial connections as well before the killpower command is issued to the UPS.

I have 4 different UPS at work with serial connections that also stopped shutting down and after update to 16.04.

How can I help with resolving the problem?

Revision history for this message
xb5i7o (xb5i7o) wrote :

Alek_A It seems like only now, more users are starting to see the problem, since ubuntu 16.04 is still fresh.
You helped by reporting this and joining the bug report, aslong as more users join this bug report, the developers will fix the issue. Hope they patch it up soon.

Revision history for this message
Alek_A (ackbeat) wrote :

Ok, thanks, I hope so. Currently we start our servers with power on button after power outages.

Changed in apcupsd (Ubuntu):
importance: Undecided → Medium
Revision history for this message
Cees (cees-inrijen) wrote :

Just bought an APC Back-UPS 350VA 230V (BK350EI) and after struggling for a couple of days find these posts on your forum. At first I had no monito on the server, which is now set. Everything goes so quickly that I cannot give any information. I see nothing of the script /etc/init-d/ups-monitor on the monitor during power failure.
If I run apctest with option 1 I can see the UPS react. I would really be helped with a solution for this.
Tanks, Cees

Revision history for this message
xb5i7o (xb5i7o) wrote :

Yes thank you! im glad more people are seeing the problem about this. Can someone set this as urgent for patching?

Revision history for this message
Cees (cees-inrijen) wrote :

Dear All, isn't possible to shift the killpower routine to an other part of the poweroff sequence. Just for Ubuntu to make it work for now and wait for the ultimate solution? Kind of quick fix I mean?

Revision history for this message
Alek_A (ackbeat) wrote :

I think that it might work. You can try if you know what to do. Post it here please if you succeed.

Revision history for this message
zhangchao (zctgbhu) wrote :

This problem has been solved in 16.10

apcupsd (3.14.14-0.1) unstable; urgency=medium

 ........
  * Hook killpower into systemd-shutdown.
    Hook script from Fedora, thanks. And mask ups-monitor.service,
    which is only relevant for /etc/init.d/halt.
    (Closes: #807689)
 ........

 -- Christian Hofstaedtler <email address hidden> Sat, 16 Jul 2016 14:10:23 +0000

Revision history for this message
xb5i7o (xb5i7o) wrote :

@zhangchao, is it possible that apcupsd unstable version 3.14.14-0.1 will work in 16.04 as well?

Id really appreciate if this can be made to work under the LTS 16.04 release.

Revision history for this message
Cees (cees-inrijen) wrote : Re: [Bug 1634572] Re: APCUPSD does not send killpower command to UPS (only happens on Ubuntu 16.04)

Thanks a lot!!⁣

Verzonden door TypeApp ​

Op 6 dec. 2016 10:13, bij 10:13, zhangchao <email address hidden> schreef:
>This problem has been solved in 16.10
>
>apcupsd (3.14.14-0.1) unstable; urgency=medium
>
> ........
> * Hook killpower into systemd-shutdown.
> Hook script from Fedora, thanks. And mask ups-monitor.service,
> which is only relevant for /etc/init.d/halt.
> (Closes: #807689)
> ........
>
> -- Christian Hofstaedtler <email address hidden> Sat, 16 Jul 2016 14:10:23
>+0000
>
>--
>You received this bug notification because you are subscribed to the
>bug
>report.
>https://bugs.launchpad.net/bugs/1634572
>
>Title:
> APCUPSD does not send killpower command to UPS (only happens on Ubuntu
> 16.04)
>
>To manage notifications about this bug go to:
>https://bugs.launchpad.net/ubuntu/+source/apcupsd/+bug/1634572/+subscriptions

Revision history for this message
Cees (cees-inrijen) wrote :

Thank you Zhangchao

Op 6-12-2016 om 9:58 schreef zhangchao:
> This problem has been solved in 16.10
>
> apcupsd (3.14.14-0.1) unstable; urgency=medium
>
> ........
> * Hook killpower into systemd-shutdown.
> Hook script from Fedora, thanks. And mask ups-monitor.service,
> which is only relevant for /etc/init.d/halt.
> (Closes: #807689)
> ........
>
> -- Christian Hofstaedtler <email address hidden> Sat, 16 Jul 2016 14:10:23
> +0000
>

Revision history for this message
xb5i7o (xb5i7o) wrote :

@zhangchao, where can i find unstable version??

Revision history for this message
xb5i7o (xb5i7o) wrote :

so i found the latest unstable version here:
http://packages.ubuntu.com/yakkety/apcupsd
version 3.14.14-0.2

I removed old stable 3.14.14 by recompiling and sudo make uninstall.

I then reinstalled latest unstable version 3.14.14-0.2, i shutdown but it still doesnt send killpower to UPS.
(Although my configurations of apcupsd was still there even after i uninstalled and installed new version)

The question is, why is this version not working on XENIAL and only on YAKETTY??

Please someone help? and if this version is not supposed to work on XENIAL, can any developer please fix the issue?

Revision history for this message
Bryan Kennedy (bkennedy.smm) wrote :

I am struggling with this bug as well.

Ubuntu version: 16.04
APC unit: BE600M1 - http://www.apc.com/shop/us/en/products/APC-Back-UPS-BE600M1-600VA-120V-1-USB-charging-port/P-BE600M1
APC connection: USB
Computer: Intel NUC6i5SYK

I can successfully shutdown the battery backup unit if I shutdown the apcupsd daemon, run apctest, and then select "1) Test kill UPS power". After 90 seconds the battery backup will fully shutoff.

However, if I restart apcupsd and then pull the battery backup power the computer will follow the apcupsd.conf instructions and properly shutdown, however the battery backup will never power off.

Has anyone discovered any workaround to try and issue the killpower command earlier in the Ubuntu shutdown process? I'm just looking for a short term quick fix for some units in the wild. Thanks for any workaround tips folks can provide.

Revision history for this message
Charl le Roux (charl-leroux) wrote :

I am struggling with this bug as well, but I am trying to shutdown Proxmox server and it is built on Debian.

#cat /etc/*-release
PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
NAME="Debian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=debian

This is a temporary fix - I created a doshutdown script, and I actually call the apcupsd --killpower function before I call the halt command like so:

#cat /etc/apcupsd/doshutdown

#!/bin/bash

# Send killpower command to UPS and halt the system instead of shutdown completely.

# Issue kill power command (make sure ups eprom 'Sleep delay' is long enough to allow for halt to # happen before the power is cut)

/sbin/apcupsd --killpower

# Do halt
/sbin/shutdown -H now

# Tell controlling script (/etc/apcupsd/apccontrol) NOT to continue with default action (i.e. shutdown).

exit 99

Revision history for this message
Alek_A (ackbeat) wrote :

Thanks for the idea, Charl! `/sbin/apcupsd --killpower` indeed kills the power when called not in shutdown sequence. Note that `/sbin/shutdown -H now` and `exit 99` is not necessary here as apccontrol does shutdown anyway.

Your workaround works for me as well! Though I made some additions to proposed /etc/apcupsd/doshutdown script:

#!/bin/bash
#

# Duplicate stdout and stderr to log so we can check it later
exec > >(tee -a /var/log/killpower.log)
exec 2>&1

# create a timestamp
date

# stop apcupsd to prevent simultaneous access to serial port (THIS IS IMPORTANT!)
echo Stopping apcupsd
/bin/systemctl stop apcupsd
# just to be sure
pkill apcupsd

# stop important services to make sure they stopped before power is killed
echo Stopping important services
/bin/systemctl stop pacemaker

echo Killing power
/sbin/apcupsd --killpower

echo Done.
echo

One can modify this script to his/her needs by replacing line `/bin/systemctl stop pacemaker` with what is appropriate for his/her system.

Also make sure that at the point `/sbin/apcupsd --killpower` is executed you have enough time to shut down rest of the system. By default the power will be actually killed in 20 seconds after the call. You can check what timeout is set in your UPS with command

apcaccess|grep DSHUTD
DSHUTD : 120 Seconds

As you see my UPS will kill the power in 120 seconds after `/sbin/apcupsd --killpower` called.

To change this value you should execute `systemctl stop apcupsd`, run `apctest`, then choose '5) Program EEPROM', choose '8) Change shutdown delay', execute `systemctl start apcupsd`.
In manual it is stated that you can also set this value in variable SLEEP in /etc/apcupsd/apcupsd.conf, and then in apctest choose '14) Set EEPROM with conf file values' - but that DON'T work for me, probably it is a bug of apcupsd.

Revision history for this message
Al (asniadow) wrote :

I have been fighting this problem for quite a while. It is gratifying that others also have the same problem. I have tried using several linux releases, including Debian, Fedora, Ubuntu, and Mint. All have the same problem, ie, the UPS will not power down after the system is shut down. My experience is that killpower is not shutting down the UPS.

I have had the problem with an APC back-ups 350 with a USB cable, an APC smartups 1400 with a serial interface to a USB port, and an APC smartups 620 with the same serial inteface to a usb port. Apcuspd v3.14.14.0, V3.14.12.0, and all of these with Fedora 25, Mint Mate 18.0, The latest release of Raspbian on a Raspberry PI, and Ubuntu mate on a Raspberry PI. The system shuts down as expected, but I cannot get the UPS to shutdown after the system shutdown. HELP!!!

Revision history for this message
Al (asniadow) wrote :

OH, by the way, I can shut down the UPS using the option in APCTEST in all the above configurations.

Revision history for this message
Alek_A (ackbeat) wrote :

Hi, Al. You may try method described in my previous post. It worked for me.

Revision history for this message
Matthew Clark (mattyclark1981) wrote :

Got a similar problem with an APC Smartups 450RM serial UPS.

As a temporary workaround I added commands in apccontrol to issue the killpower before starting the shutdown. I've had to up the shutdown delay to 3 minutes and up the lowbatt and lowruntime levels to ensure I can shutdown cleanly, but so far, it looks ok.

I'm no expert, so I expect I've missed something...

Revision history for this message
Alek_A (ackbeat) wrote :

If you don't stop/kill apcupsd BEFORE you kill power, you should be prepared that sometimes killpower would not work, because of apcupsd already accessing the UPS to obtain its state.

Revision history for this message
Cees (cees-inrijen) wrote :

Hello Alec,

 From your email below I created the file as you described. Is anynyting
else required to link it in?

Thanks for your help!

Best Regards,

Cees

Op 17-1-2017 om 04:51 schreef Alek_A:
> Thanks for the idea, Charl! `/sbin/apcupsd --killpower` indeed kills the
> power when called not in shutdown sequence. Note that `/sbin/shutdown -H
> now` and `exit 99` is not necessary here as apccontrol does shutdown
> anyway.
>
> Your workaround works for me as well! Though I made some additions to
> proposed /etc/apcupsd/doshutdown script:
>
> #!/bin/bash
> #
>
> # Duplicate stdout and stderr to log so we can check it later
> exec > >(tee -a /var/log/killpower.log)
> exec 2>&1
>
> # create a timestamp
> date
>
> # stop apcupsd to prevent simultaneous access to serial port (THIS IS IMPORTANT!)
> echo Stopping apcupsd
> /bin/systemctl stop apcupsd
> # just to be sure
> pkill apcupsd
>
> # stop important services to make sure they stopped before power is killed
> echo Stopping important services
> /bin/systemctl stop pacemaker
>
> echo Killing power
> /sbin/apcupsd --killpower
>
> echo Done.
> echo
>
>
> One can modify this script to his/her needs by replacing line `/bin/systemctl stop pacemaker` with what is appropriate for his/her system.
>
> Also make sure that at the point `/sbin/apcupsd --killpower` is executed
> you have enough time to shut down rest of the system. By default the
> power will be actually killed in 20 seconds after the call. You can
> check what timeout is set in your UPS with command
>
> apcaccess|grep DSHUTD
> DSHUTD : 120 Seconds
>
> As you see my UPS will kill the power in 120 seconds after
> `/sbin/apcupsd --killpower` called.
>
> To change this value you should execute `systemctl stop apcupsd`, run `apctest`, then choose '5) Program EEPROM', choose '8) Change shutdown delay', execute `systemctl start apcupsd`.
> In manual it is stated that you can also set this value in variable SLEEP in /etc/apcupsd/apcupsd.conf, and then in apctest choose '14) Set EEPROM with conf file values' - but that DON'T work for me, probably it is a bug of apcupsd.
>

Revision history for this message
Cees (cees-inrijen) wrote :

Hello Alec,

"On 17-1-2017 At 04:51 Alek_A wrote:"

Hello Alec,

From your email below I created the file as you described. Is anything else required to link it in?

Thanks for your help!

Best Regards,

Cees

Revision history for this message
Alek_A (ackbeat) wrote :

Hi Cees,

Nothing else is required, I'm still using this script without problems.

Just, as I mentioned, replace "/bin/systemctl stop pacemaker" with command(s) that stop the critical services in your system (services that take some time to stop and that have to be stopped for sure before proceeding with killpower). You may omit this line if you run no critical services, or if you run an ordinary desktop system (not a server).

Best regards,
Alek

Revision history for this message
Lucas Sandery (lucas+-) wrote :

I got around this by creating (and of course doing chmod +x on) a script at /lib/systemd/system-shutdown/apcups-killpower

#!/bin/sh
if [ "$1" = "poweroff" -a -f /etc/apcupsd/powerfail ]; then
    /etc/apcupsd/apccontrol killpower
fi

Idea from https://wiki.archlinux.org/index.php/APC_UPS#Make_apcupsd_kill_UPS_power_once_the_hibernate_is_done
(with credit to djgera https://bbs.archlinux.org/viewtopic.php?pid=1354737#p1354737 and fsateler https://github.com/systemd/systemd/issues/4894#issuecomment-267372354)

Revision history for this message
xb5i7o (xb5i7o) wrote :

Hi Lucas,

Your solution worked for Ubuntu 16.04!! and seems to be the easiest for me. THANK YOU !!!
Not sure about the SLEEP delay value in apcupsd.conf because by default its 20 seconds from the moment killpower is called but as soon as PC shuts down, it takes about 180 seconds instead. i tried to change the value to 120 but i didnt see any difference in the time. I guess this SLEEP value doesnt really work like Alek stated, although it currently does give enough time till the UPS actually shuts down.

One question though, when will this actually be fixed by the developers so we can remove these custom scripts in future? and how will we know this is fixed? Surely we are not meant to create custom scripts like this and this should work after installing apcupsd like it did in previous versions of Ubuntu.

Revision history for this message
thomas (riker1) wrote :

Hi
I am having the same problem.
No powerup after power is back

Looks like UPS did not shut down.

Finally I did not understand the solution provided.

anyone having the steps how to ensure after power failure, shutting down desktop ubuntu and ups,
restarting desktop when power is back (Bios setting: always on ensured)
- handle the case. Power is coming back during shutdown.

Thanks

Revision history for this message
xb5i7o (xb5i7o) wrote :

Hi @thomas

Install APCUPSD as you normally would and then...
You need to create a custom script with +x (make executable)
with these contents:

#!/bin/sh
if [ "$1" = "poweroff" -a -f /etc/apcupsd/powerfail ]; then
    /etc/apcupsd/apccontrol killpower
fi

After that, save the script into this path /lib/systemd/system-shutdown/

Then try it again and let me know! it works.

Revision history for this message
thomas (riker1) wrote :

Hi @Xb517o

looks like this did the trick.

Thanks

Is it ok that UPS is blinking red and orange?

When reinserting the plug after some time power came back, UPS status green again and desktop powering up!

Perfect thanks

Revision history for this message
thomas (riker1) wrote :

just a question.

what happens when power is coming back during shutdown or before UPS is killed?

Thanks

Revision history for this message
Gabriel Kozsar (kozsarg) wrote :

Thank you xb5i7o (xb5i7o) #32

helped me today big time

Intel NUC7CJYH - Ubuntu16.04LTS - APCUPSD 3.14.12 over USB to APC BackUPS 700 (BX700U-FR)

It works ! Perfect.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.