-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #160 from flyingcircusio/FC-35378-httpwatchdog
[FC-35378] Init HTTPServiceWatchdog component
- Loading branch information
Showing
5 changed files
with
447 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
* Added component `batou_ext.http.HTTPServiceWatchdog` that adds a check to a systemd unit | ||
whether a given URL is reachable (e.g. a `/health` endpoint). If the URL cannot be reached within | ||
a certain interval, the service will be restarted. Further details are documented in the | ||
docstring. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ config, lib, pkgs, ... }: | ||
|
||
let | ||
script = | ||
# {% if component.predefined_service %} | ||
(pkgs.writeShellScript | ||
"{{ component.service }}-start" | ||
config.systemd.services."{{ component.service }}".script) | ||
# {% else %} | ||
"{{ component.script }}" | ||
# {% endif %} | ||
; | ||
in { | ||
# {% if component.predefined_service %} | ||
assertions = [ | ||
{ assertion = config.systemd.services."{{ component.service }}".script != ""; | ||
message = "Service {{ component.service }} needs to have `script` set!"; | ||
} | ||
]; | ||
# {% endif %} | ||
|
||
systemd.services."{{ component.service }}" = { | ||
path = [ | ||
config.systemd.package | ||
# interpreter for the watchdog script | ||
(pkgs.python3.withPackages (ps: with ps; [ | ||
requests | ||
])) | ||
]; | ||
serviceConfig = { | ||
Type = "notify"; | ||
# Allow child processes of ExecStart | ||
# to do `sd_notify(3)`. | ||
NotifyAccess = "all"; | ||
Restart = "always"; | ||
TimeoutStartSec = lib.mkForce "{{ component.start_timeout }}"; | ||
WatchdogSec = "{{ component.watchdog_interval }}"; | ||
|
||
ExecStart = lib.mkForce (pkgs.writeShellScript "watchdog-{{ component.service }}" '' | ||
exec {{ component.watchdog_script_path }} \ | ||
--healthcheck-url {{ component.healthcheck_url }} \ | ||
--healthcheck-timeout {{ component.healthcheck_timeout }} \ | ||
--watcher-loglevel info \ | ||
--startup-check-interval {{ component.startup_check_interval }} \ | ||
--check-interval {{ component.check_interval }} \ | ||
-- ${script} | ||
''); | ||
}; | ||
}; | ||
} |
Oops, something went wrong.