forked from DGNum/stateless-uptime-kuma
feat: Add auto deployment service
This commit is contained in:
parent
b5f06dc7ef
commit
8e32135aaa
2 changed files with 50 additions and 19 deletions
|
@ -37,9 +37,11 @@ rec {
|
|||
fromHive {
|
||||
builder = (
|
||||
node: module: {
|
||||
monitors = let
|
||||
monitors =
|
||||
let
|
||||
hostname = mkHost node module.config;
|
||||
in {
|
||||
in
|
||||
{
|
||||
${prefix + hostname} = {
|
||||
type = "ping";
|
||||
inherit tags hostname;
|
||||
|
|
|
@ -14,10 +14,18 @@ in
|
|||
json = lib.mkOption { type = lib.types.package; };
|
||||
script = lib.mkOption { type = lib.types.package; };
|
||||
};
|
||||
enableService = lib.mkEnableOption "the auto-deployment systemd unit";
|
||||
host = lib.mkOption {
|
||||
default = null;
|
||||
type = with lib.types; nullOr str;
|
||||
};
|
||||
username = lib.mkOption {
|
||||
default = null;
|
||||
type = with lib.types; nullOr str;
|
||||
};
|
||||
passwordFile = lib.mkOption {
|
||||
type = with lib.types; nullOr path;
|
||||
};
|
||||
extraFlags = lib.mkOption {
|
||||
default = [ ];
|
||||
example = [ "--scrape-http-keywords" ];
|
||||
|
@ -46,9 +54,12 @@ in
|
|||
};
|
||||
};
|
||||
};
|
||||
config.statelessUptimeKuma = {
|
||||
config = {
|
||||
statelessUptimeKuma = {
|
||||
lib = import ../lib { inherit lib; };
|
||||
extraFlags = lib.optional (cfg.host != null) "--host ${cfg.host}";
|
||||
extraFlags =
|
||||
lib.optional (cfg.host != null) "--host ${cfg.host}"
|
||||
++ lib.optional (cfg.username != null) "--username ${cfg.username}";
|
||||
build = {
|
||||
json = probesFormat.generate "probes.json" cfg.probesConfig;
|
||||
script = pkgs.writeShellApplication {
|
||||
|
@ -61,4 +72,22 @@ in
|
|||
};
|
||||
};
|
||||
};
|
||||
systemd.services.stateless-uptime-kuma = lib.mkIf cfg.enableService {
|
||||
description = "Uptime-kuma probes deployment";
|
||||
|
||||
wants = [ "uptime-kuma.service" ];
|
||||
after = [ "uptime-kuma.service" ];
|
||||
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
|
||||
script = ''
|
||||
UPTIME_KUMA_PASSWORD=$(cat $CREDENTIALS_DIRECTORY/password) ${lib.getExe config.statelessUptimeKuma.build.script}
|
||||
'';
|
||||
|
||||
serviceConfig = {
|
||||
LoadCredential = "password:${cfg.passwordFile}";
|
||||
Type = "oneshot";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue