3
0
Fork 0
forked from mirrors/nixpkgs

Merge pull request #83301 from evils/tuptime

Tuptime: Init Package, Module and Test
This commit is contained in:
Florian Klink 2020-04-19 23:38:53 +02:00 committed by GitHub
commit a88d17bc69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 152 additions and 0 deletions

View file

@ -546,6 +546,7 @@
./services/monitoring/teamviewer.nix
./services/monitoring/telegraf.nix
./services/monitoring/thanos.nix
./services/monitoring/tuptime.nix
./services/monitoring/ups.nix
./services/monitoring/uptime.nix
./services/monitoring/vnstat.nix

View file

@ -0,0 +1,84 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.tuptime;
in {
options.services.tuptime = {
enable = mkEnableOption "the total uptime service";
timer = {
enable = mkOption {
type = types.bool;
default = true;
description = "Whether to regularly log uptime to detect bad shutdowns.";
};
period = mkOption {
type = types.str;
default = "*:0/5";
description = "systemd calendar event";
};
};
};
config = mkIf cfg.enable {
environment.systemPackages = [ pkgs.tuptime ];
users.users.tuptime.description = "tuptime database owner";
systemd = {
services = {
tuptime = {
description = "the total uptime service";
documentation = [ "man:tuptime(1)" ];
after = [ "time-sync.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
StateDirectory = "tuptime";
Type = "oneshot";
User = "tuptime";
RemainAfterExit = true;
ExecStart = "${pkgs.tuptime}/bin/tuptime -x";
ExecStop = "${pkgs.tuptime}/bin/tuptime -xg";
};
};
tuptime-oneshot = mkIf cfg.timer.enable {
description = "the tuptime scheduled execution unit";
serviceConfig = {
StateDirectory = "tuptime";
Type = "oneshot";
User = "tuptime";
ExecStart = "${pkgs.tuptime}/bin/tuptime -x";
};
};
};
timers.tuptime = mkIf cfg.timer.enable {
description = "the tuptime scheduled execution timer";
# 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-oneshot.service";
};
};
};
};
meta.maintainers = [ maintainers.evils ];
}

View file

@ -313,6 +313,7 @@ in
trilium-server = handleTestOn ["x86_64-linux"] ./trilium-server.nix {};
trezord = handleTest ./trezord.nix {};
trickster = handleTest ./trickster.nix {};
tuptime = handleTest ./tuptime.nix {};
udisks2 = handleTest ./udisks2.nix {};
upnp = handleTest ./upnp.nix {};
uwsgi = handleTest ./uwsgi.nix {};

29
nixos/tests/tuptime.nix Normal file
View file

@ -0,0 +1,29 @@
import ./make-test-python.nix ({ pkgs, ...} : {
name = "tuptime";
meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ evils ];
};
machine = { pkgs, ... }: {
imports = [ ../modules/profiles/minimal.nix ];
services.tuptime.enable = true;
};
testScript =
''
# see if it starts
start_all()
machine.wait_for_unit("multi-user.target")
machine.succeed("tuptime | grep 'System startups:[[:blank:]]*1'")
machine.succeed("tuptime | grep 'System uptime:[[:blank:]]*100.0%'")
machine.shutdown()
# restart machine and see if it correctly reports the reboot
machine.start()
machine.wait_for_unit("multi-user.target")
machine.succeed("tuptime | grep 'System startups:[[:blank:]]*2'")
machine.succeed("tuptime | grep 'System shutdowns:[[:blank:]]*1 ok'")
machine.shutdown()
'';
})

View file

@ -0,0 +1,35 @@
{ stdenv, fetchFromGitHub, python3 }:
stdenv.mkDerivation rec {
pname = "tuptime";
version = "4.1.0";
src = fetchFromGitHub {
owner = "rfrail3";
repo = "tuptime";
rev = version;
sha256 = "0p5v1jp6bl0hjv04q3gh11q6dx9z0x61h6svcbvwp5ni0h1bkz1a";
};
buildInputs = [ python3 ];
installPhase = ''
mkdir -p $out/bin
install -m 755 src/tuptime $out/bin/
mkdir -p $out/share/man/man1
cp src/man/tuptime.1 $out/share/man/man1/
# upstream only ships this, there are more scripts there...
mkdir -p $out/usr/share/doc/tuptime/contrib
cp misc/scripts/uptimed-to-tuptime.py $out/usr/share/doc/tuptime/contrib/
'';
meta = with stdenv.lib; {
description = "Total uptime & downtime statistics utility";
homepage = "https://github.com/rfrail3/tuptime";
license = licenses.gpl2;
platforms = platforms.all;
maintainers = [ maintainers.evils ];
};
}

View file

@ -7114,6 +7114,8 @@ in
tuir = callPackage ../applications/misc/tuir { };
tuptime = callPackage ../tools/system/tuptime { };
turses = callPackage ../applications/networking/instant-messengers/turses { };
oysttyer = callPackage ../applications/networking/instant-messengers/oysttyer { };