add shell option and no dynamics user can controle update easy gatus annoucement

perseverance
Lewis7Lewis 2026-11-12 01:25:55 +01:00
parent 585ab398f8
commit 41c9fbf57b
1 changed files with 57 additions and 1 deletions

View File

@ -35,8 +35,51 @@ let
) allHosts; ) allHosts;
gatus-announce = pkgs.writeShellScriptBin "gatus-announce" ''
set -euo pipefail
FILE="/var/lib/gatus/config/99-announcements.yaml"
if [ "$#" -lt 1 ]; then
echo "Usage:"
echo " sudo gatus-announce <type> \"<message>\" (types: outage, warning, information, operational)"
echo " sudo gatus-announce clear (archive l'annonce en cours)"
exit 1
fi
if [ "$1" = "clear" ]; then
if [ -f "$FILE" ]; then
sed -i 's/archived: false/archived: true/g' "$FILE"
echo "Annonce archivée."
fi
exit 0
fi
TYPE="$1"
MESSAGE="''${2:-}"
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
if [ -z "$MESSAGE" ]; then
echo "Erreur : le message est vide."
exit 1
fi
cat <<EOF > "$FILE"
announcements:
- timestamp: "$TIMESTAMP"
type: $TYPE
message: "$MESSAGE"
archived: false
EOF
chmod 644 "$FILE"
echo "Annonce publiée ($TYPE) : $MESSAGE"
'';
in in
{ {
environment.systemPackages = [ gatus-announce ];
services.openssh.settings.AcceptEnv = [ "GIT_PROTOCOL" ]; services.openssh.settings.AcceptEnv = [ "GIT_PROTOCOL" ];
services.forgejo = { services.forgejo = {
@ -58,6 +101,7 @@ in
services.gatus = { services.gatus = {
enable = true; enable = true;
openFirewall = false; openFirewall = false;
skip-invalid-config-update = true;
settings = { settings = {
web.port = 8080; web.port = 8080;
ui.title = "Page Status Crans"; ui.title = "Page Status Crans";
@ -73,6 +117,15 @@ in
endpoints = endpointsFromInfos; endpoints = endpointsFromInfos;
}; };
};
users.users.gatus = {
isSystemUser = true;
group = "gatus";
};
users.groups.gatus = {};
systemd.services.gatus.serviceConfig = {
}; };
# Override the systemd service to watch a directory instead of the single /nix/store file # Override the systemd service to watch a directory instead of the single /nix/store file
systemd.services.gatus = { systemd.services.gatus = {
@ -92,6 +145,9 @@ in
message: "Investigating elevated latency on EU servers." message: "Investigating elevated latency on EU servers."
archived: false" >> /var/lib/gatus/config/99-announcements.yaml archived: false" >> /var/lib/gatus/config/99-announcements.yaml
''; '';
DynamicUser = lib.mkForce false;
User = "gatus";
Group = "gatus";
}; };
}; };
} }