From 07a7baeb6bf21ce2018fc558fb849ba17669fb89 Mon Sep 17 00:00:00 2001 From: Joe Mou Date: Fri, 26 Apr 2024 23:51:10 -0400 Subject: elmo: E-mail on certain systemd failures --- hostnix/elmo/system.nix | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'hostnix/elmo/system.nix') diff --git a/hostnix/elmo/system.nix b/hostnix/elmo/system.nix index 4f6ddb7..407ca42 100644 --- a/hostnix/elmo/system.nix +++ b/hostnix/elmo/system.nix @@ -34,11 +34,30 @@ # https://nixos.wiki/wiki/Hardware/Apple#Auto_Restart systemd.services.enable-autorestart = { description = "Boot after power failure (server mode)"; - wantedBy = [ "default.target" ]; + wantedBy = [ "multi-user.target" ]; serviceConfig = { Type = "oneshot"; }; # https://superuser.com/a/1051137 script = "${pkgs.pciutils}/bin/setpci -s 00:1f.0 0xa4.b=0"; }; + + # https://wiki.archlinux.org/index.php/Systemd/Timers#MAILTO + systemd.services."status-email@" = { + description = "Status email for %i"; + serviceConfig = { + Type = "oneshot"; + }; + scriptArgs = "%i"; + script = '' + ${pkgs.mailutils}/bin/mail -s "$1 status" root < + Subject: $1 status + Content-Transfer-Encoding: 8bit + Content-Type: text/plain; charset=UTF-8 + + $(systemctl status --full "$1") + EOF + ''; + }; } -- cgit v1.3.1