Having a hard time getting this to work.
Problem: apcupsd will not send the killpower signal to the APC UPS over the network when a shutdown occurs due to batteries too low.
If I have the UPS connected over USB, it all works as expected, but not over the network. I presume this is because the scripts in /usr/lib/systemd/system-shutdown/* are trigger after the network has stopped.
I’ve been doing some research on how to make a systemd.service oneshot that runs during shutdown before network is brought down, but after apcupsd is stopped.
I tried this .service file:
[Unit]
Description=APC UPS Killpower command
DefaultDependencies=no
Conflicts=reboot.target
Before=poweroff.target halt.target shutdown.target apcupsd.target
Requires=poweroff.target network.target
[Service]
Type=oneshot
ExecStart=/opt/apcupsd/apcupsd_shutdown
RemainAfterExit=yes
[Install]
WantedBy=shutdown.target
Or this:
[Unit]
Description=APC UPS Killpower command
Before=apcupsd.target
Requires=network.target
[Service]
Type=oneshot
ExecStart=/usr/bin/true
RemainAfterExit=yes
ExecStop=/opt/apcupsd/apcupsd_shutdown
[Install]
WantedBy=multi-user.target
Problem with these is that apcupsd hasn’t stopped yet (I think, I edited the apcupsd_shutdown script to ouput some logging to a text file that showed that apcupsd is still running, but I forget which .service file I did it for). I presume it is because all processes are issued the terminate command in parallel, so apcupsd is stopping while the ExecStop command in the second .service file is running and ExecStart command in the first .service file.
I tried adding an ExecStopPost= entry to run the service file for the apcupsd service:
[Unit]
Description=APC UPS Power Control Daemon for Linux
After=syslog.target
After=network-online.target
[Service]
ExecStartPre=-/bin/rm -f /etc/apcupsd/powerfail
ExecStart=/sbin/apcupsd -b -f /etc/apcupsd/apcupsd.conf
KillMode=process
ExecStopPost=/usr/lib/systemd/system-shutdown/apcupsd_shutdown
[Install]
WantedBy=multi-user.target
No dice on that one. Any ideas?
Oh, the KILLDELAY in the apcupsd.conf file is set to 0 (to disable it, which is default).