Fix rmm-agent procd shutdown

This commit is contained in:
benya
2026-06-05 02:19:05 +03:00
parent da58781505
commit 08e43e726a
4 changed files with 55 additions and 4 deletions

View File

@@ -11,10 +11,14 @@ start_service() {
procd_open_instance
procd_set_param command /bin/sh "$PROG"
procd_set_param env CONFIG_FILE="$CONFIG_FILE"
procd_set_param stdout 1
procd_set_param stderr 1
procd_set_param term_timeout 15
procd_set_param respawn 3600 5 5
procd_close_instance
}
stop_service() {
service_stop "$PROG"
rm -rf /tmp/rmm-agent.lock
}

View File

@@ -12,6 +12,7 @@ SPOOL_DIR="${SPOOL_DIR:-/tmp/rmm-agent-results}"
BACKUP_DIR="${BACKUP_DIR:-/tmp/rmm-agent-backups}"
CHECK_TARGETS="${CHECK_TARGETS:-1.1.1.1 8.8.8.8}"
TUNNEL_IDENTITY_FILE="${TUNNEL_IDENTITY_FILE:-/etc/rmm-agent/tunnel_key}"
TUNNEL_STATE_DIR="${TUNNEL_STATE_DIR:-/tmp/rmm-agent-tunnels}"
if [ -f "$CONFIG_FILE" ]; then
# shellcheck disable=SC1090
@@ -22,15 +23,36 @@ log() {
printf '%s %s\n' "$(date -u '+%Y-%m-%dT%H:%M:%SZ')" "$*" >&2
}
cleanup() {
if [ -n "${SLEEP_PID:-}" ]; then
kill "$SLEEP_PID" 2>/dev/null || true
fi
rm -rf "$LOCK_FILE"
}
stop_agent() {
cleanup
exit 0
}
acquire_lock() {
if mkdir "$LOCK_FILE" 2>/dev/null; then
trap 'rm -rf "$LOCK_FILE"' EXIT INT TERM
trap cleanup EXIT
trap stop_agent INT TERM
return 0
fi
log "another rmm-agent instance is running"
return 1
}
interruptible_sleep() {
SLEEP_PID=""
sleep "$1" &
SLEEP_PID="$!"
wait "$SLEEP_PID" 2>/dev/null || true
SLEEP_PID=""
}
json_escape() {
printf '%s' "$1" | awk '
BEGIN { ORS = "" }
@@ -879,7 +901,7 @@ main() {
backoff=$((backoff * 2))
[ "$backoff" -le 300 ] || backoff=300
fi
sleep "$backoff"
interruptible_sleep "$backoff"
done
}