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/configuration.nix | 2 ++ hostnix/elmo/dyndns.nix | 1 + hostnix/elmo/email.nix | 3 +++ hostnix/elmo/system.nix | 21 ++++++++++++++++++++- 4 files changed, 26 insertions(+), 1 deletion(-) (limited to 'hostnix') diff --git a/hostnix/elmo/configuration.nix b/hostnix/elmo/configuration.nix index 6945fa5..444dc5b 100644 --- a/hostnix/elmo/configuration.nix +++ b/hostnix/elmo/configuration.nix @@ -39,6 +39,8 @@ dig file gitFull + openssl + psmisc tmux tree ]; diff --git a/hostnix/elmo/dyndns.nix b/hostnix/elmo/dyndns.nix index aea6776..5bfde47 100644 --- a/hostnix/elmo/dyndns.nix +++ b/hostnix/elmo/dyndns.nix @@ -30,6 +30,7 @@ # Defer errors for ~45min, throttle e-mails to ~hourly. StartLimitIntervalSec = "1hr"; StartLimitBurst = "45"; + OnFailure = "status-email@%n.service"; }; serviceConfig = { Type = "oneshot"; diff --git a/hostnix/elmo/email.nix b/hostnix/elmo/email.nix index 462a3d7..1ea4000 100644 --- a/hostnix/elmo/email.nix +++ b/hostnix/elmo/email.nix @@ -17,6 +17,9 @@ systemd.services.postfix-tls-rotate = { requires = [ "network-online.target" ]; after = [ "network-online.target" ]; + unitConfig = { + OnFailure = "status-email@%n.service"; + }; serviceConfig = { Type = "oneshot"; # Not really necessary indirection but interesting to try out. Note we 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