#!/bin/bash # Forgejo Runner healthcheck — managed by Ansible (roles/forgejo_runner) # # Answers "is forgejo-runner healthy" and records it two ways: this log, and the # exit code. The exit code is the durable artefact — systemd keeps it, so # systemctl is-failed {{ healthcheck_service_name }}.service # answers the question with no monitoring system involved. # # Reporting is optional and generic: if a push URL is configured it also pings # it. Nothing here knows or cares which monitoring product is on the other end. LOG_FILE="{{ healthcheck_log_file }}" PUSH_URL="{{ healthcheck_push_url }}" log_message() { echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$LOG_FILE" } main() { if ! systemctl is-active --quiet forgejo-runner; then log_message "ERROR: forgejo-runner is not active" exit 1 fi if [ -z "$PUSH_URL" ]; then # Healthy, and nothing to report to. Not an error: the exit code below # is still a complete answer for anything reading unit state. log_message "forgejo-runner is active (no push URL configured)" exit 0 fi log_message "forgejo-runner is active, sending ping" response=$(curl -s -w "\n%{http_code}" "$PUSH_URL?status=up&msg=forgejo-runner%20is%20active" 2>&1) http_code=$(echo "$response" | tail -n1) if [ "$http_code" = "200" ] || [ "$http_code" = "201" ]; then log_message "Ping sent successfully (HTTP $http_code)" else log_message "ERROR: Failed to send ping (HTTP $http_code)" exit 1 fi } main