diff --git a/modules/autoupgrade.nix b/modules/autoupgrade.nix index 62de703..45fca95 100644 --- a/modules/autoupgrade.nix +++ b/modules/autoupgrade.nix @@ -9,9 +9,9 @@ system.autoUpgrade.dates = "daily"; system.autoUpgrade.persistent = true; - systemctl.service."nixos-upgrade" = { - onFailure = [ "healthchecks-monitor@nixos-upgrade-${config.networking.hostName}:failure" ] - onSuccess = [ "healthchecks-monitor@nixos-upgrade-${config.networking.hostName}:success" ] - wants = [ "multi-user.target" "healthchecks-monitor@nixos-upgrade-${config.networking.hostName}:start" ]; - } + systemd.services."nixos-upgrade" = { + onFailure = [ "healthchecks-monitor@nixos-upgrade-${config.networking.hostName}:failure.service" ]; + onSuccess = [ "healthchecks-monitor@nixos-upgrade-${config.networking.hostName}:success.service" ]; + wants = [ "multi-user.target" "healthchecks-monitor@nixos-upgrade-${config.networking.hostName}:start.service" ]; + }; } diff --git a/modules/healthchecks-io-monitor.nix b/modules/healthchecks-io-monitor.nix index 46ad639..584c4dd 100644 --- a/modules/healthchecks-io-monitor.nix +++ b/modules/healthchecks-io-monitor.nix @@ -1,7 +1,7 @@ { config, pkgs, ... }: { - age.secrets.monitoring-healthchecks-url.file = ../secrets/monitoring-healthchecks-url.age; + config.age.secrets.monitoring-healthchecks-url.file = ../secrets/monitoring-healthchecks-url.age; # [Unit] @@ -10,25 +10,31 @@ # OnSuccess=healthcheck-monitor@deda567a-21e0-4744-ba9e-603c51e258b0:success.service # Wants=healthcheck-monitor@deda567a-21e0-4744-ba9e-603c51e258b0:start.service - systemd.services.healthchecks-monitor = { + config.systemd.services."healthchecks-monitor@" = { description = "Pings healthchecks (%i)"; wantedBy = [ "multi-user.target" ]; - path = [ pkgs.curl ]; - scriptArgs = "%i"; - script = '' - HC_URL=$(cat ${age.secrets.monitoring-healthchecks-url.file}) - IFS=: read -r SLUG ACTION <<< "%i" - if [ "$ACTION" = "start" ]; then - LOGS="" - EXIT_CODE="start" - else - LOGS=$(journalctl --no-pager -n 50 -u $MONITOR_UNIT) - EXIT_CODE=$MONITOR_EXIT_STATUS - fi - curl -fSs -m 10 --retry 3 --data-raw "$LOGS" "$HC_URL/$SLUG/$EXIT_CODE?create=1" - ''; + path = [ pkgs.bash pkgs.curl ]; +# Scripts did not work because the special systemd variables were not getting passed in. I had to collapse it to a single line for ExecStart +# scriptArgs = "%i"; +# script = '' +# HC_URL=$(cat ${config.age.secrets.monitoring-healthchecks-url.path}) +# IFS=: read -r SLUG ACTION <<< "%i" +# if [ "$ACTION" = "start" ]; then +# LOGS="" +# EXIT_CODE="start" +# else +# #LOGS=$(journalctl --no-pager -n 50 -u $MONITOR_UNIT) +# LOGS="" +# EXIT_CODE=$MONITOR_EXIT_STATUS +# fi +# echo "curl -fSs -m 10 --retry 3 --data-raw \"$LOGS\" \"$HC_URL/$SLUG/$EXIT_CODE?create=1\"" +# curl -fSs -m 10 --retry 3 --data-raw "$LOGS" "$HC_URL/$SLUG/$EXIT_CODE?create=1" +# ''; serviceConfig = { Type = "oneshot"; + ExecStart = '' + ${pkgs.bash}/bin/bash -c 'HC_URL=$(cat ${config.age.secrets.monitoring-healthchecks-url.path}); IFS=: read -r SLUG ACTION <<< "%i"; if [ "$ACTION" = "start" ]; then LOGS="" && EXIT_CODE="start"; else LOGS=$(journalctl --no-pager -n 50 -u $MONITOR_UNIT) && EXIT_CODE=$MONITOR_EXIT_STATUS; fi && echo "curl -fSs -m 10 --retry 3 --data-raw \"$LOGS\" \"$HC_URL/$SLUG/$EXIT_CODE?create=1\"" && curl -fSs -m 10 --retry 3 --data-raw "$LOGS" "$HC_URL/$SLUG/$EXIT_CODE?create=1"' + ''; }; };