diff --git a/gateway/run.py b/gateway/run.py index 4946a7e6c1ee..7ed282f10e4a 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -8742,7 +8742,17 @@ async def _handle_restart_command(self, event: MessageEvent) -> Union[str, Ephem # restarts us. The detached subprocess approach (setsid + bash) # doesn't work under systemd because KillMode=mixed kills all # processes in the cgroup, including the detached helper. - _under_service = bool(os.environ.get("INVOCATION_ID")) # systemd sets this + # Detect service-managed environments: systemd (INVOCATION_ID), + # Docker (/.dockerenv), or Podman (/run/.containerenv). In these + # environments the detached-subprocess restart approach doesn't work + # because the container/service kills all child processes when the + # main process exits. Use the service restart path (exit code 75) + # instead, letting the supervisor handle the restart. + _under_service = bool( + os.environ.get("INVOCATION_ID") # systemd + or os.path.isfile("/.dockerenv") # Docker + or os.path.isfile("/run/.containerenv") # Podman + ) if _under_service: self.request_restart(detached=False, via_service=True) else: