3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/nixos/modules/services/monitoring/tuptime.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

91 lines
2.2 KiB
Nix
Raw Normal View History

2020-03-24 22:45:20 +00:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.tuptime;
in {
options.services.tuptime = {
enable = mkEnableOption (lib.mdDoc "the total uptime service");
2020-03-24 22:45:20 +00:00
timer = {
enable = mkOption {
type = types.bool;
default = true;
description = lib.mdDoc "Whether to regularly log uptime to detect bad shutdowns.";
2020-03-24 22:45:20 +00:00
};
period = mkOption {
type = types.str;
default = "*:0/5";
description = lib.mdDoc "systemd calendar event";
2020-03-24 22:45:20 +00:00
};
};
};
config = mkIf cfg.enable {
environment.systemPackages = [ pkgs.tuptime ];
users = {
groups._tuptime.members = [ "_tuptime" ];
users._tuptime = {
isSystemUser = true;
group = "_tuptime";
description = "tuptime database owner";
};
};
2020-03-24 22:45:20 +00:00
systemd = {
services = {
tuptime = {
description = "The total uptime service";
2020-03-24 22:45:20 +00:00
documentation = [ "man:tuptime(1)" ];
after = [ "time-sync.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
StateDirectory = "tuptime";
Type = "oneshot";
User = "_tuptime";
2020-03-24 22:45:20 +00:00
RemainAfterExit = true;
ExecStart = "${pkgs.tuptime}/bin/tuptime -x";
ExecStop = "${pkgs.tuptime}/bin/tuptime -xg";
};
};
tuptime-sync = mkIf cfg.timer.enable {
description = "Tuptime scheduled sync service";
2020-03-24 22:45:20 +00:00
serviceConfig = {
Type = "oneshot";
User = "_tuptime";
2020-03-24 22:45:20 +00:00
ExecStart = "${pkgs.tuptime}/bin/tuptime -x";
};
};
};
timers.tuptime-sync = mkIf cfg.timer.enable {
description = "Tuptime scheduled sync timer";
2020-03-24 22:45:20 +00:00
# this timer should be started if the service is started
# even if the timer was previously stopped
wantedBy = [ "tuptime.service" "timers.target" ];
# this timer should be stopped if the service is stopped
partOf = [ "tuptime.service" ];
timerConfig = {
OnBootSec = "1min";
OnCalendar = cfg.timer.period;
Unit = "tuptime-sync.service";
2020-03-24 22:45:20 +00:00
};
};
};
};
meta.maintainers = [ maintainers.evils ];
}