From 8b0968b2054d3bb8d90b5ac056727f7c2ebeaed3 Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Tue, 11 Dec 2018 18:10:48 +0300 Subject: (* HUGE *) Use nixpkgs overlays --- pkgs/check_systemd/check_systemd | 20 ++++++++++++++++++++ pkgs/check_systemd/default.nix | 25 +++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100755 pkgs/check_systemd/check_systemd create mode 100644 pkgs/check_systemd/default.nix (limited to 'pkgs/check_systemd') diff --git a/pkgs/check_systemd/check_systemd b/pkgs/check_systemd/check_systemd new file mode 100755 index 0000000..e668331 --- /dev/null +++ b/pkgs/check_systemd/check_systemd @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +set -euo pipefail + +readarray -t failed < <( systemctl show '*.service' \ + --state=failed --property=Names \ + | sed -r -n 's,Names=(.+)\.service,\1,p' \ + | sort + ) + +if [ ${#failed[@]} -ne 0 ]; then + printf -v list ', %s' "${failed[@]}" + printf 'WARNING: %s failed\n' "${list:2}" + exit 1 +else + echo "OK: no failed services" + exit 0 +fi + + diff --git a/pkgs/check_systemd/default.nix b/pkgs/check_systemd/default.nix new file mode 100644 index 0000000..da92a64 --- /dev/null +++ b/pkgs/check_systemd/default.nix @@ -0,0 +1,25 @@ +{ stdenv, gnused }: + +stdenv.mkDerivation { + name = "check_systemd"; + src = ./check_systemd; + outputs = [ "out" "conf" ]; + unpackPhase = ":"; + installPhase = '' + mkdir -p $out/bin + + cp "$src" $out/bin/check_systemd + + substituteInPlace "$out/bin/"* \ + --replace sed '${gnused}/bin/sed' + + chmod +x "$out/bin/"* + + cat < $conf + object CheckCommand "systemd" { + import "plugin-check-command" + command = [ "$out/bin/check_systemd" ] + } + CONF + ''; +} -- cgit v1.2.3