From 95e2006653fed23045f651c6d35cee7ceb26c07e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Forsman?= Date: Mon, 22 Jul 2013 14:09:13 +0200 Subject: [PATCH] apcupsd-service: put UPS in hibernate mode when shutting down This adds a special systemd service that calls "apcupsd --killpower" (put UPS in hibernate mode) just before shutting down the system. Without this command, the UPS will stay on until the battery is completely empty. --- modules/services/monitoring/apcupsd.nix | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/modules/services/monitoring/apcupsd.nix b/modules/services/monitoring/apcupsd.nix index 017c896cf4d..163ae3ceff6 100644 --- a/modules/services/monitoring/apcupsd.nix +++ b/modules/services/monitoring/apcupsd.nix @@ -156,6 +156,28 @@ in }; }; + # A special service to tell the UPS to power down/hibernate just before the + # computer shuts down. (The UPS has a built in delay before it actually + # shuts off power.) Copied from here: + # http://forums.opensuse.org/english/get-technical-help-here/applications/479499-apcupsd-systemd-killpower-issues.html + systemd.services.apcupsd-killpower = { + after = [ "shutdown.target" ]; # append umount.target? + before = [ "final.target" ]; + wantedBy = [ "shutdown.target" ]; + unitConfig = { + Description = "APC UPS killpower"; + ConditionPathExists = "/run/apcupsd/powerfail"; + DefaultDependencies = "no"; + }; + serviceConfig = { + Type = "oneshot"; + ExecStart = "${pkgs.apcupsd}/bin/apcupsd --killpower -f ${configFile}"; + TimeoutSec = 0; + StandardOutput = "tty"; + RemainAfterExit = "yes"; + }; + }; + }; }