From bf270cde7573b6cc70be7e3e0cee31a28f44fd00 Mon Sep 17 00:00:00 2001 From: shukon <> Date: Sun, 9 Jun 2024 09:11:15 +0200 Subject: [PATCH 1/6] Add healthcheck URL to borg install --- conf/backup-with-borg | 11 +++++++++++ config_panel.toml | 6 ++++++ scripts/config | 5 +++++ 3 files changed, 22 insertions(+) diff --git a/conf/backup-with-borg b/conf/backup-with-borg index d9d6a9d..0a67467 100644 --- a/conf/backup-with-borg +++ b/conf/backup-with-borg @@ -17,12 +17,21 @@ filter_hooks() { sudo ls /usr/share/yunohost/hooks/backup/ /etc/yunohost/hooks.d/backup/ | grep "\-$1_" | cut -d"-" -f2 | uniq 2>> "$err_file" } +healthcheck_url="$(sudo yunohost app setting "${borg_id}" healthcheck_url)" +healthcheck() { + if [[ -n "$healthcheck_url" ]]; then + curl -s -m 10 -o /dev/null --data-raw "$(echo $2 | tail --bytes=10000)" "$healthcheck_url/$1" + fi +} + fail_if_partially_failed() { grep Skipped|Error } sudo yunohost app setting "${borg_id}" last_run -v "${current_date}" sudo yunohost app setting "${borg_id}" state -v "ongoing" +healthcheck "start" + # Backup system part conf conf=$(sudo yunohost app setting "${borg_id}" conf) if [[ "$conf" = "1" ]]; then @@ -74,8 +83,10 @@ repository="$(sudo yunohost app setting "${borg_id}" repository)" mailalert="$(sudo yunohost app setting "${borg_id}" mailalert)" if [[ -n "$errors" ]]; then sudo yunohost app setting "${borg_id}" state -v "failed" + healthcheck "fail" "$errors" else sudo yunohost app setting "${borg_id}" state -v "successful" + healthcheck fi if [[ -n "$errors" && $mailalert != "never" ]]; then diff --git a/config_panel.toml b/config_panel.toml index 888f261..72e0966 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -46,6 +46,12 @@ services = [] choices.errors_only = "Only if an error occured" choices.never = "Never alert me" help = "Alerts are sent to the first user of this server" + + [main.general.healthcheck_url] + ask.en = "Healthcheck URL" + type = "string" + help = "Use a healthcheck to detect silent failures. It's optional, if you don't know what it is, just leave it blank or look it up: https://healthchecks.io" + optional = "true" [main.content] name = "What should be backed up?" diff --git a/scripts/config b/scripts/config index edb17a7..36399d7 100644 --- a/scripts/config +++ b/scripts/config @@ -66,6 +66,11 @@ validate__on_calendar() { echo 'Please follow systemd OnCalendar format: https://man.archlinux.org/man/systemd.time.7#CALENDAR_EVENTS' } +validate__healthcheck_url() { + [[ $healthcheck_url =~ ^https?://[^/]+(/.*)?$ ]] || + echo 'Please enter a valid URL' +} + #================================================= # SPECIFIC SETTERS FOR TOML SHORT KEYS #================================================= From 0d12630183399e4ff48e71e0bed5b8869f648ecd Mon Sep 17 00:00:00 2001 From: shukon <> Date: Sun, 9 Jun 2024 09:18:40 +0200 Subject: [PATCH 2/6] Add manifest install option and curl as apt dependency --- manifest.toml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/manifest.toml b/manifest.toml index c76c02b..2b756c9 100644 --- a/manifest.toml +++ b/manifest.toml @@ -78,6 +78,13 @@ ram.runtime = "50M" choices = ["always", "errors_only", "never"] default = "errors_only" + [install.healthcheck_url] + ask.en = "Do you want to enable the healthcheck URL to check against silent failures ?" + ask.fr = "Souhaitez-vous activer l'URL de vérification de l'état pour vérifier les pannes silenci + type = "string" + default = "" + optional = true + [resources] [resources.sources.main] url = "https://github.com/borgbackup/borg/archive/refs/tags/1.4.0.tar.gz" @@ -96,6 +103,7 @@ ram.runtime = "50M" [resources.apt] packages = [ + "curl", "python3-pip", "python3-dev", "python3-jinja2", From d8dac9d7c3ace021c458333a26f93d3df1723167 Mon Sep 17 00:00:00 2001 From: shukon <> Date: Sun, 9 Jun 2024 09:18:40 +0200 Subject: [PATCH 3/6] Add manifest install option and curl as apt dependency --- manifest.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.toml b/manifest.toml index 2b756c9..8e19b29 100644 --- a/manifest.toml +++ b/manifest.toml @@ -80,7 +80,7 @@ ram.runtime = "50M" [install.healthcheck_url] ask.en = "Do you want to enable the healthcheck URL to check against silent failures ?" - ask.fr = "Souhaitez-vous activer l'URL de vérification de l'état pour vérifier les pannes silenci + ask.fr = "Souhaitez-vous activer l'URL de vérification de l'état pour vérifier les pannes silencieuses ?" type = "string" default = "" optional = true From a6ab3353b2eaf7240bbe3d53ef40f08c66a411b8 Mon Sep 17 00:00:00 2001 From: shukon <> Date: Sun, 9 Jun 2024 16:13:17 +0200 Subject: [PATCH 4/6] Improve help displayed on install --- manifest.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifest.toml b/manifest.toml index 8e19b29..d4c82be 100644 --- a/manifest.toml +++ b/manifest.toml @@ -79,8 +79,8 @@ ram.runtime = "50M" default = "errors_only" [install.healthcheck_url] - ask.en = "Do you want to enable the healthcheck URL to check against silent failures ?" - ask.fr = "Souhaitez-vous activer l'URL de vérification de l'état pour vérifier les pannes silencieuses ?" + ask.en = "Optional - you may specify a healthcheck URL to check against silent failures." + ask.fr = "Optionnel - vous pouvez spécifier une URL de vérification de l'état pour vérifier les pannes silencieuses." type = "string" default = "" optional = true From 2733b8cc81557b1d22e02c2bfbded719f0d8342d Mon Sep 17 00:00:00 2001 From: "ljf (zamentur)" Date: Wed, 20 Nov 2024 16:45:23 +0100 Subject: [PATCH 5/6] String to url type --- config_panel.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config_panel.toml b/config_panel.toml index 72e0966..431abd8 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -49,7 +49,7 @@ services = [] [main.general.healthcheck_url] ask.en = "Healthcheck URL" - type = "string" + type = "url" help = "Use a healthcheck to detect silent failures. It's optional, if you don't know what it is, just leave it blank or look it up: https://healthchecks.io" optional = "true" From a86972146636ced7ec5c9680bb977b8e2ac27a8e Mon Sep 17 00:00:00 2001 From: "ljf (zamentur)" Date: Wed, 20 Nov 2024 16:45:58 +0100 Subject: [PATCH 6/6] [fix] Redundant validators --- scripts/config | 5 ----- 1 file changed, 5 deletions(-) diff --git a/scripts/config b/scripts/config index 36399d7..edb17a7 100644 --- a/scripts/config +++ b/scripts/config @@ -66,11 +66,6 @@ validate__on_calendar() { echo 'Please follow systemd OnCalendar format: https://man.archlinux.org/man/systemd.time.7#CALENDAR_EVENTS' } -validate__healthcheck_url() { - [[ $healthcheck_url =~ ^https?://[^/]+(/.*)?$ ]] || - echo 'Please enter a valid URL' -} - #================================================= # SPECIFIC SETTERS FOR TOML SHORT KEYS #=================================================