Uninterruptible power supply: Difference between revisions

Tie-ling (talk | contribs)
Delay UPS Shutdown: use nut statepath
m Added a comment to explain what the contents of passwordFile should contain. Paths to internal nix resources will throw an error, modified passwordFile to be to an absolute path instead.
 
(5 intermediate revisions by 3 users not shown)
Line 25: Line 25:
needs a new battery every four years, under optimal operating
needs a new battery every four years, under optimal operating
conditions.
conditions.
The end of ConfigExample book says:
Joe's server will still be allright
if power drops off in the night.
  That 8 year old pack
  of battery backup
will easily handle th connection lost


= Components of NUT Software =
= Components of NUT Software =
Line 140: Line 132:
     # declarations. upsd.users
     # declarations. upsd.users
     users."nut-admin" = {
     users."nut-admin" = {
       passwordFile = "${../resources/ups-passwd.txt}";
      # A file that contains just the password.
       passwordFile = "/etc/nixos/ups-passwd.txt";
       upsmon = "primary";
       upsmon = "primary";
     };
     };
Line 155: Line 148:
       powerValue = 1;
       powerValue = 1;
       user = "nut-admin";
       user = "nut-admin";
       passwordFile = "${../resources/ups-passwd.txt}";
       passwordFile = "/etc/nixos/ups-passwd.txt";
       type = "primary";
       type = "primary";
     };
     };
Line 246: Line 239:
   # 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 = {
     enable = true;
       # taken from output of $(systemctl cat upsd.service)
    environment = config.systemd.services.upsmon.environment;
       NUT_CONFPATH = "/etc/nut";
    description = "Initiate delayed UPS shutdown";
       NUT_STATEPATH = "/var/lib/nut";
    before = [ "umount.target" ];
    wantedBy = [ "final.target" ];
    serviceConfig = {
      Type = "oneshot";
       # need to use '-u root', or else permission denied
       ExecStart = ''${pkgs.nut}/bin/upsdrvctl -u root shutdown'';
       # must not use slice: if used, upsdrvctl will not run as a late
      # shutdown service
      # Slice = "";
     };
     };
     unitConfig = {
     unitConfig = {
       Description = "Initiate delayed UPS shutdown";
       ConditionPathExists = config.power.ups.upsmon.settings.POWERDOWNFLAG;
      Before = "umount.target";
       DefaultDependencies = "no";
       DefaultDependencies = false;
    };
    serviceConfig = {
      Type = "oneshot";
      ExecStart = ''${pkgs.bash}/bin/bash -c\
      "${pkgs.util-linux}/bin/logger -t\
        nut-delayed-ups-shutdown 'upsdrvctl shutting down UPS';\
        ${pkgs.nut}/bin/upsdrvctl shutdown"'';
     };
     };
    wantedBy = [ "final.target" ];
   };
   };
</syntaxhighlight>
</syntaxhighlight>
[[Category:Hardware]]