Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add healthcheck URL to protect against silent failures #160

Open
wants to merge 6 commits into
base: testing
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions conf/backup-with-borg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions config_panel.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "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"

[main.content]
name = "What should be backed up?"
Expand Down
8 changes: 8 additions & 0 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ ram.runtime = "50M"
choices = ["always", "errors_only", "never"]
default = "errors_only"

[install.healthcheck_url]
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

[resources]
[resources.sources.main]
url = "https://github.com/borgbackup/borg/archive/refs/tags/1.4.0.tar.gz"
Expand All @@ -96,6 +103,7 @@ ram.runtime = "50M"

[resources.apt]
packages = [
"curl",
"python3-pip",
"python3-dev",
"python3-jinja2",
Expand Down