Uninterruptible power supply: Difference between revisions

Tie-ling (talk | contribs)
Delay UPS Shutdown: fix attrset
Tie-ling (talk | contribs)
Delay UPS Shutdown: do not use slice
 
Line 246: Line 246:
   # copied from ConfigExamples 3.0 book, Appendix B.2.
   # copied from ConfigExamples 3.0 book, Appendix B.2.
   systemd.services.nut-delayed-ups-shutdown = {
   systemd.services.nut-delayed-ups-shutdown = {
     environment = config.systemd.services.upsd.environment;
    enable = true;
     unitConfig = {
     environment = config.systemd.services.upsmon.environment;
      Description = "Initiate delayed UPS shutdown";
     description = "Initiate delayed UPS shutdown";
      Before = "umount.target";
    before = [ "umount.target" ];
      DefaultDependencies = false;
    wantedBy = [ "final.target" ];
    };
     serviceConfig = {
     serviceConfig = {
       Type = "oneshot";
       Type = "oneshot";
       ExecStart = ''${pkgs.bash}/bin/bash -c\
      # need to use '-u root', or else permission denied
      "${pkgs.util-linux}/bin/logger -t\
       ExecStart = ''${pkgs.nut}/bin/upsdrvctl -u root shutdown'';
        nut-delayed-ups-shutdown 'upsdrvctl shutting down UPS';\
      # must not use slice: if used, upsdrvctl will not run as a late
        ${pkgs.nut}/bin/upsdrvctl shutdown"'';
      # shutdown service
      # Slice = "";
    };
    unitConfig = {
      ConditionPathExists = config.power.ups.upsmon.settings.POWERDOWNFLAG;
      DefaultDependencies = "no";
     };
     };
    wantedBy = [ "final.target" ];
   };
   };
</syntaxhighlight>
</syntaxhighlight>