From 82f364ffd1d7f85cb4faa0fbfd2095ada0a78f84 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Tue, 14 Apr 2026 20:52:18 -0700 Subject: [PATCH] feat: add --all flag to gateway start and restart commands (#10043) - gateway start --all: kills all stale gateway processes across all profiles before starting the current profile's service - gateway restart --all: stops all gateway processes across all profiles, then starts the current profile's service fresh - gateway stop --all: already existed, unchanged The --all flag was only available on 'stop' but not on 'start' or 'restart', causing 'unrecognized arguments' errors for users. --- hermes_cli/gateway.py | 41 +++++++++++++++++++++++++++++++++++++++++ hermes_cli/main.py | 2 ++ 2 files changed, 43 insertions(+) diff --git a/hermes_cli/gateway.py b/hermes_cli/gateway.py index 4b13bc70f..58d9f92ed 100644 --- a/hermes_cli/gateway.py +++ b/hermes_cli/gateway.py @@ -2919,6 +2919,15 @@ def gateway_command(args): elif subcmd == "start": system = getattr(args, 'system', False) + start_all = getattr(args, 'all', False) + + if start_all: + # Kill all stale gateway processes across all profiles before starting + killed = kill_gateway_processes(all_profiles=True) + if killed: + print(f"✓ Killed {killed} stale gateway process(es) across all profiles") + _wait_for_gateway_exit(timeout=10.0, force_after=5.0) + if is_termux(): print("Gateway service start is not supported on Termux because there is no system service manager.") print("Run manually: hermes gateway") @@ -3004,7 +3013,39 @@ def gateway_command(args): # Try service first, fall back to killing and restarting service_available = False system = getattr(args, 'system', False) + restart_all = getattr(args, 'all', False) service_configured = False + + if restart_all: + # --all: stop every gateway process across all profiles, then start fresh + service_stopped = False + if supports_systemd_services() and (get_systemd_unit_path(system=False).exists() or get_systemd_unit_path(system=True).exists()): + try: + systemd_stop(system=system) + service_stopped = True + except subprocess.CalledProcessError: + pass + elif is_macos() and get_launchd_plist_path().exists(): + try: + launchd_stop() + service_stopped = True + except subprocess.CalledProcessError: + pass + killed = kill_gateway_processes(all_profiles=True) + total = killed + (1 if service_stopped else 0) + if total: + print(f"✓ Stopped {total} gateway process(es) across all profiles") + _wait_for_gateway_exit(timeout=10.0, force_after=5.0) + + # Start the current profile's service fresh + print("Starting gateway...") + if supports_systemd_services() and (get_systemd_unit_path(system=False).exists() or get_systemd_unit_path(system=True).exists()): + systemd_start(system=system) + elif is_macos() and get_launchd_plist_path().exists(): + launchd_start() + else: + run_gateway(verbose=0) + return if supports_systemd_services() and (get_systemd_unit_path(system=False).exists() or get_systemd_unit_path(system=True).exists()): service_configured = True diff --git a/hermes_cli/main.py b/hermes_cli/main.py index c73344be4..017280184 100644 --- a/hermes_cli/main.py +++ b/hermes_cli/main.py @@ -4749,6 +4749,7 @@ For more help on a command: # gateway start gateway_start = gateway_subparsers.add_parser("start", help="Start the installed systemd/launchd background service") gateway_start.add_argument("--system", action="store_true", help="Target the Linux system-level gateway service") + gateway_start.add_argument("--all", action="store_true", help="Kill ALL stale gateway processes across all profiles before starting") # gateway stop gateway_stop = gateway_subparsers.add_parser("stop", help="Stop gateway service") @@ -4758,6 +4759,7 @@ For more help on a command: # gateway restart gateway_restart = gateway_subparsers.add_parser("restart", help="Restart gateway service") gateway_restart.add_argument("--system", action="store_true", help="Target the Linux system-level gateway service") + gateway_restart.add_argument("--all", action="store_true", help="Kill ALL gateway processes across all profiles before restarting") # gateway status gateway_status = gateway_subparsers.add_parser("status", help="Show gateway status")