Loading nixos/modules/services/databases/postgresql.nix +24 −4 Original line number Diff line number Diff line Loading @@ -769,7 +769,7 @@ in systemd.targets.postgresql = { description = "PostgreSQL"; wantedBy = [ "multi-user.target" ]; bindsTo = [ requires = [ "postgresql.service" "postgresql-setup.service" ]; Loading @@ -780,8 +780,13 @@ in after = [ "network.target" ]; # To trigger the .target also on "systemctl start postgresql". bindsTo = [ "postgresql.target" ]; # To trigger the .target also on "systemctl start postgresql" as well as on # restarts & stops. # Please note that postgresql.service & postgresql.target binding to # each other makes the Restart=always rule racy and results # in sometimes the service not being restarted. wants = [ "postgresql.target" ]; partOf = [ "postgresql.target" ]; environment.PGDATA = cfg.dataDir; Loading Loading @@ -821,6 +826,8 @@ in ExecStart = "${cfg.finalPackage}/bin/postgres"; Restart = "always"; # Hardening CapabilityBoundingSet = [ "" ]; DevicePolicy = "closed"; Loading Loading @@ -872,7 +879,20 @@ in }) ]; unitConfig.RequiresMountsFor = "${cfg.dataDir}"; unitConfig = let inherit (config.systemd.services.postgresql.serviceConfig) TimeoutSec; maxTries = 5; bufferSec = 5; in { RequiresMountsFor = "${cfg.dataDir}"; # The max. time needed to perform `maxTries` start attempts of systemd # plus a bit of buffer time (bufferSec) on top. StartLimitIntervalSec = TimeoutSec * maxTries + bufferSec; StartLimitBurst = maxTries; }; }; systemd.services.postgresql-setup = { Loading nixos/tests/postgresql/postgresql.nix +6 −0 Original line number Diff line number Diff line Loading @@ -101,6 +101,12 @@ let machine.fail(check_count("SELECT * FROM sth;", 4)) machine.succeed(check_count("SELECT xpath('/test/text()', doc) FROM xmltest;", 1)) with subtest("killing postgres process should trigger an automatic restart"): machine.succeed("systemctl kill -s KILL postgresql") machine.wait_until_succeeds("systemctl is-active postgresql.service") machine.wait_until_succeeds("systemctl is-active postgresql.target") with subtest("Backup service works"): machine.succeed( "systemctl start ${backupService}.service", Loading Loading
nixos/modules/services/databases/postgresql.nix +24 −4 Original line number Diff line number Diff line Loading @@ -769,7 +769,7 @@ in systemd.targets.postgresql = { description = "PostgreSQL"; wantedBy = [ "multi-user.target" ]; bindsTo = [ requires = [ "postgresql.service" "postgresql-setup.service" ]; Loading @@ -780,8 +780,13 @@ in after = [ "network.target" ]; # To trigger the .target also on "systemctl start postgresql". bindsTo = [ "postgresql.target" ]; # To trigger the .target also on "systemctl start postgresql" as well as on # restarts & stops. # Please note that postgresql.service & postgresql.target binding to # each other makes the Restart=always rule racy and results # in sometimes the service not being restarted. wants = [ "postgresql.target" ]; partOf = [ "postgresql.target" ]; environment.PGDATA = cfg.dataDir; Loading Loading @@ -821,6 +826,8 @@ in ExecStart = "${cfg.finalPackage}/bin/postgres"; Restart = "always"; # Hardening CapabilityBoundingSet = [ "" ]; DevicePolicy = "closed"; Loading Loading @@ -872,7 +879,20 @@ in }) ]; unitConfig.RequiresMountsFor = "${cfg.dataDir}"; unitConfig = let inherit (config.systemd.services.postgresql.serviceConfig) TimeoutSec; maxTries = 5; bufferSec = 5; in { RequiresMountsFor = "${cfg.dataDir}"; # The max. time needed to perform `maxTries` start attempts of systemd # plus a bit of buffer time (bufferSec) on top. StartLimitIntervalSec = TimeoutSec * maxTries + bufferSec; StartLimitBurst = maxTries; }; }; systemd.services.postgresql-setup = { Loading
nixos/tests/postgresql/postgresql.nix +6 −0 Original line number Diff line number Diff line Loading @@ -101,6 +101,12 @@ let machine.fail(check_count("SELECT * FROM sth;", 4)) machine.succeed(check_count("SELECT xpath('/test/text()', doc) FROM xmltest;", 1)) with subtest("killing postgres process should trigger an automatic restart"): machine.succeed("systemctl kill -s KILL postgresql") machine.wait_until_succeeds("systemctl is-active postgresql.service") machine.wait_until_succeeds("systemctl is-active postgresql.target") with subtest("Backup service works"): machine.succeed( "systemctl start ${backupService}.service", Loading