diff --git a/hidden_server/agent_watchdog.py b/hidden_server/agent_watchdog.py deleted file mode 100644 index 80e1146..0000000 --- a/hidden_server/agent_watchdog.py +++ /dev/null @@ -1,85 +0,0 @@ -#!/usr/bin/env python3 - -import argparse -import os -import subprocess -import sys - - -def run_output(command): - return subprocess.check_output(command, text=True, stderr=subprocess.STDOUT).strip() - - -def service_main_pid(service_name): - output = run_output(["systemctl", "show", "-p", "MainPID", "--value", service_name]) - pid = int(output or "0") - return pid if pid > 1 else 0 - - -def service_active_state(service_name): - return run_output(["systemctl", "is-active", service_name]) - - -def fd_count(pid): - return len(os.listdir("/proc/%d/fd" % int(pid))) - - -def close_wait_count(pid): - try: - output = run_output(["ss", "-tanp"]) - except subprocess.CalledProcessError as error: - output = error.output or "" - target = "pid=%d," % int(pid) - return sum(1 for line in output.splitlines() if "CLOSE-WAIT" in line and target in line) - - -def restart_service(service_name, reason, details): - sys.stderr.write("[watchdog] restart %s reason=%s details=%s\n" % (service_name, reason, details)) - sys.stderr.flush() - subprocess.check_call(["systemctl", "restart", service_name]) - - -def main(): - parser = argparse.ArgumentParser(description="Twoman agent watchdog") - parser.add_argument("--service", default="twoman-agent.service") - parser.add_argument( - "--fd-threshold", - type=int, - default=int(os.environ.get("TWOMAN_WATCHDOG_FD_THRESHOLD", "16384")), - ) - parser.add_argument( - "--close-wait-threshold", - type=int, - default=int(os.environ.get("TWOMAN_WATCHDOG_CLOSE_WAIT_THRESHOLD", "256")), - ) - args = parser.parse_args() - - state = service_active_state(args.service) - if state != "active": - restart_service(args.service, "inactive", state) - return - - pid = service_main_pid(args.service) - if pid < 2: - restart_service(args.service, "missing-pid", pid) - return - - current_fd_count = fd_count(pid) - if current_fd_count >= args.fd_threshold: - restart_service(args.service, "fd-threshold", current_fd_count) - return - - current_close_wait_count = close_wait_count(pid) - if current_close_wait_count >= args.close_wait_threshold: - restart_service(args.service, "close-wait-threshold", current_close_wait_count) - return - - sys.stderr.write( - "[watchdog] ok service=%s pid=%s open_fds=%s close_wait=%s\n" - % (args.service, pid, current_fd_count, current_close_wait_count) - ) - sys.stderr.flush() - - -if __name__ == "__main__": - main() diff --git a/hidden_server/config.sample.json b/hidden_server/config.sample.json deleted file mode 100644 index da8c62d..0000000 --- a/hidden_server/config.sample.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "broker_base_url": "https://host.example.com/parvaneh", - "upstream_proxy_url": "", - "outbound_proxy_url": "", - "outbound_proxy_label": "", - "agent_token": "replace-with-agent-token", - "auth_mode": "bearer", - "binary_media_type": "image/webp", - "route_template": "/{lane}/{direction}", - "health_template": "/health", - "http_timeout_seconds": 30, - "heartbeat_interval_seconds": 15, - "down_read_timeout_seconds": 10, - "down_stream_max_session_seconds": 60, - "interval_jitter_ratio": 0.2, - "backoff_initial_delay_seconds": 0.1, - "backoff_max_delay_seconds": 5, - "flush_delay_seconds": 0.01, - "max_batch_bytes": 65536, - "max_frame_payload_bytes": 2097152, - "send_queue_timeout_seconds": 5, - "verify_tls": true, - "peer_id": "agent-main", - "open_connect_timeout_seconds": 12, - "prefer_ipv4": true, - "disable_ipv6_origin": true, - "happy_eyeballs_delay_seconds": 0.25, - "upload_profiles": { - "data": { - "max_batch_bytes": 524288, - "flush_delay_seconds": 0.006 - } - }, - "up_workers": { - "data": 8 - }, - "idle_repoll_delay_seconds": { - "ctl": 0.05, - "data": 0.1 - }, - "http2_enabled": { - "ctl": false, - "data": false - } -} diff --git a/hidden_server/install_watchdog.sh b/hidden_server/install_watchdog.sh deleted file mode 100755 index 3bffb0f..0000000 --- a/hidden_server/install_watchdog.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" -SERVICE_PATH="/etc/systemd/system/twoman-agent-watchdog.service" -TIMER_PATH="/etc/systemd/system/twoman-agent-watchdog.timer" -TARGET_DIR="/opt/twoman" - -install -m 0755 "${SCRIPT_DIR}/agent_watchdog.py" "${TARGET_DIR}/agent_watchdog.py" -install -m 0644 "${SCRIPT_DIR}/systemd/twoman-agent-watchdog.service" "${SERVICE_PATH}" -install -m 0644 "${SCRIPT_DIR}/systemd/twoman-agent-watchdog.timer" "${TIMER_PATH}" - -systemctl daemon-reload -systemctl enable --now twoman-agent-watchdog.timer -systemctl start twoman-agent-watchdog.service -systemctl status --no-pager twoman-agent-watchdog.timer diff --git a/hidden_server/systemd/twoman-agent-watchdog.service b/hidden_server/systemd/twoman-agent-watchdog.service deleted file mode 100644 index 45f26f4..0000000 --- a/hidden_server/systemd/twoman-agent-watchdog.service +++ /dev/null @@ -1,7 +0,0 @@ -[Unit] -Description=Twoman agent watchdog -After=network-online.target - -[Service] -Type=oneshot -ExecStart=/usr/bin/python3 /opt/twoman/agent_watchdog.py --service twoman-agent.service --fd-threshold 16384 --close-wait-threshold 256 diff --git a/hidden_server/systemd/twoman-agent-watchdog.timer b/hidden_server/systemd/twoman-agent-watchdog.timer deleted file mode 100644 index b6ffd5c..0000000 --- a/hidden_server/systemd/twoman-agent-watchdog.timer +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=Run Twoman agent watchdog every minute - -[Timer] -OnBootSec=1min -OnUnitActiveSec=1min -Unit=twoman-agent-watchdog.service - -[Install] -WantedBy=timers.target