fix: Kuma has no /start or /fail path — push ?status=up|down instead
A request to /api/push/<token>/start or /fail answers 200 but records no heartbeat, so a failed run left the push monitor green until its 24h interval expired. Verified against Uptime Kuma 1.23.17: only the query string form writes a heartbeat.
This commit is contained in:
1 parent
dc6a2f4794
commit
313db934e4
2 files changed
+22
-13
No files matched your search
@@ -15,7 +15,8 @@ pre-upgrade snapshots. It is off by default and needs `/var/run/docker.sock`.
|
|||||||
## What a run does
|
## What a run does
|
||||||
|
|
||||||
1. Takes an exclusive lock (a second run exits immediately).
|
1. Takes an exclusive lock (a second run exits immediately).
|
||||||
2. Pings the Uptime Kuma push monitor with `/start`.
|
2. Pings the Uptime Kuma push monitor with `?status=up` so the monitor stays
|
||||||
|
green while the run is in progress.
|
||||||
3. Dumps `ccnet_db`, `seafile_db` and `seahub_db` into one consistent
|
3. Dumps `ccnet_db`, `seafile_db` and `seahub_db` into one consistent
|
||||||
`--databases` dump under `/config/db/<timestamp>/`, reading the credentials
|
`--databases` dump under `/config/db/<timestamp>/`, reading the credentials
|
||||||
from the Seafile `conf/.env`.
|
from the Seafile `conf/.env`.
|
||||||
@@ -27,7 +28,9 @@ pre-upgrade snapshots. It is off by default and needs `/var/run/docker.sock`.
|
|||||||
7. Deletes dump directories older than `DB_DUMP_KEEP`.
|
7. Deletes dump directories older than `DB_DUMP_KEEP`.
|
||||||
8. Pings Kuma with the result and sends an Apprise notification.
|
8. Pings Kuma with the result and sends an Apprise notification.
|
||||||
|
|
||||||
Any failure exits non-zero, pings `/fail` and sends a failure notification.
|
Any failure exits non-zero, pushes `?status=down` to Kuma and sends a failure
|
||||||
|
notification. Kuma has no `/start` or `/fail` path — those forms answer 200 but
|
||||||
|
record nothing, which is why the query string is the only form used here.
|
||||||
|
|
||||||
## Environment
|
## Environment
|
||||||
|
|
||||||
|
|||||||
+17
-11
@@ -10,8 +10,8 @@ Design
|
|||||||
default.
|
default.
|
||||||
* restic is the only backup engine. rclone is gone: it cannot write to the
|
* restic is the only backup engine. rclone is gone: it cannot write to the
|
||||||
RustFS buckets and ``sync`` is the wrong semantics for a backup.
|
RustFS buckets and ``sync`` is the wrong semantics for a backup.
|
||||||
* Every step is checked. Any failure exits non-zero, pings the Kuma push
|
* Every step is checked. Any failure exits non-zero, pushes `status=down` to
|
||||||
monitor with ``/fail`` and sends a failure notification. The 2023 prototype
|
the Kuma push monitor and sends a failure notification. The 2023 prototype
|
||||||
discarded every exit code, which is why it reported success while doing
|
discarded every exit code, which is why it reported success while doing
|
||||||
nothing.
|
nothing.
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ import urllib.request
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
VERSION = "2.0.0"
|
VERSION = "2.0.1"
|
||||||
LOG_MAX_BYTES = 10 * 1024 * 1024
|
LOG_MAX_BYTES = 10 * 1024 * 1024
|
||||||
|
|
||||||
|
|
||||||
@@ -263,16 +263,21 @@ def http_post_json(url: str, payload: dict, timeout: int = 20) -> int:
|
|||||||
return response.status
|
return response.status
|
||||||
|
|
||||||
|
|
||||||
def kuma_ping(cfg: Config, suffix: str = "", params: dict | None = None) -> None:
|
def kuma_ping(cfg: Config, params: dict) -> None:
|
||||||
|
"""Push one heartbeat to the Kuma push monitor.
|
||||||
|
|
||||||
|
Kuma only reads ``?status=up|down&msg=&ping=``. There is no ``/start`` or
|
||||||
|
``/fail`` path suffix: a request to one of those still answers 200 but
|
||||||
|
records nothing, so a failed run used to leave the monitor green until its
|
||||||
|
interval expired.
|
||||||
|
"""
|
||||||
if not cfg.kuma_url:
|
if not cfg.kuma_url:
|
||||||
return
|
return
|
||||||
url = cfg.kuma_url.rstrip("/") + suffix
|
|
||||||
if params:
|
|
||||||
query = urllib.parse.urlencode(params)
|
query = urllib.parse.urlencode(params)
|
||||||
url = f"{url}?{query}"
|
url = f"{cfg.kuma_url.rstrip('/')}?{query}"
|
||||||
try:
|
try:
|
||||||
status = http_get(url)
|
status = http_get(url)
|
||||||
log(f"kuma ping {url} -> {status}")
|
log(f"kuma ping {params.get('status', 'up')} -> {status}")
|
||||||
except (urllib.error.URLError, OSError) as exc:
|
except (urllib.error.URLError, OSError) as exc:
|
||||||
log(f"WARNING: kuma ping failed: {exc}")
|
log(f"WARNING: kuma ping failed: {exc}")
|
||||||
|
|
||||||
@@ -585,7 +590,8 @@ def main() -> int:
|
|||||||
stopped = False
|
stopped = False
|
||||||
|
|
||||||
log(f"seafile-backup {VERSION} starting (run {stamp})")
|
log(f"seafile-backup {VERSION} starting (run {stamp})")
|
||||||
kuma_ping(cfg, "/start")
|
# A mid-run up-ping keeps the push monitor green while the run is working.
|
||||||
|
kuma_ping(cfg, {"status": "up", "msg": "backup running"})
|
||||||
|
|
||||||
try:
|
try:
|
||||||
preflight(cfg)
|
preflight(cfg)
|
||||||
@@ -621,12 +627,12 @@ def main() -> int:
|
|||||||
body = build_body(cfg, result["ok"], result, elapsed)
|
body = build_body(cfg, result["ok"], result, elapsed)
|
||||||
|
|
||||||
if result["ok"]:
|
if result["ok"]:
|
||||||
kuma_ping(cfg, "", {"status": "up", "msg": "OK", "ping": int(elapsed * 1000)})
|
kuma_ping(cfg, {"status": "up", "msg": "OK", "ping": int(elapsed * 1000)})
|
||||||
log(f"finished OK in {duration(elapsed)}")
|
log(f"finished OK in {duration(elapsed)}")
|
||||||
notify(cfg, True, body)
|
notify(cfg, True, body)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
kuma_ping(cfg, "/fail", {"msg": (result.get("error") or "failed")[:200]})
|
kuma_ping(cfg, {"status": "down", "msg": (result.get("error") or "failed")[:200]})
|
||||||
log(f"finished FAILED in {duration(elapsed)}")
|
log(f"finished FAILED in {duration(elapsed)}")
|
||||||
notify(cfg, False, body)
|
notify(cfg, False, body)
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
Reference in new issue
Block a user