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.
This commit is contained in:
Teknium
2026-04-14 20:52:18 -07:00
committed by GitHub
parent 31d0620663
commit 82f364ffd1
2 changed files with 43 additions and 0 deletions

View File

@@ -2919,6 +2919,15 @@ def gateway_command(args):
elif subcmd == "start": elif subcmd == "start":
system = getattr(args, 'system', False) 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(): if is_termux():
print("Gateway service start is not supported on Termux because there is no system service manager.") print("Gateway service start is not supported on Termux because there is no system service manager.")
print("Run manually: hermes gateway") print("Run manually: hermes gateway")
@@ -3004,7 +3013,39 @@ def gateway_command(args):
# Try service first, fall back to killing and restarting # Try service first, fall back to killing and restarting
service_available = False service_available = False
system = getattr(args, 'system', False) system = getattr(args, 'system', False)
restart_all = getattr(args, 'all', False)
service_configured = 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()): if supports_systemd_services() and (get_systemd_unit_path(system=False).exists() or get_systemd_unit_path(system=True).exists()):
service_configured = True service_configured = True

View File

@@ -4749,6 +4749,7 @@ For more help on a command:
# gateway start # gateway start
gateway_start = gateway_subparsers.add_parser("start", help="Start the installed systemd/launchd background service") 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("--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_stop = gateway_subparsers.add_parser("stop", help="Stop gateway service") 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_restart = gateway_subparsers.add_parser("restart", help="Restart gateway service") 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("--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_status = gateway_subparsers.add_parser("status", help="Show gateway status") gateway_status = gateway_subparsers.add_parser("status", help="Show gateway status")