@@ -22,13 +22,24 @@ export const SUPERVISOR_HINT_ENV_VARS = [
2222/** Supported supervisor families that can respawn the gateway after update/restart handoff. */
2323export type RespawnSupervisor = "launchd" | "systemd" | "schtasks" ;
2424
25+ export interface DetectRespawnSupervisorOptions {
26+ includeLinuxOpenClawGatewayServiceMarker ?: boolean ;
27+ }
28+
2529function hasAnyHint ( env : NodeJS . ProcessEnv , keys : readonly string [ ] ) : boolean {
2630 return keys . some ( ( key ) => {
2731 const value = env [ key ] ;
2832 return typeof value === "string" && value . trim ( ) . length > 0 ;
2933 } ) ;
3034}
3135
36+ function hasOpenClawGatewayServiceMarker ( env : NodeJS . ProcessEnv ) : boolean {
37+ return (
38+ env . OPENCLAW_SERVICE_MARKER ?. trim ( ) === "openclaw" &&
39+ env . OPENCLAW_SERVICE_KIND ?. trim ( ) === "gateway"
40+ ) ;
41+ }
42+
3243function isCurrentGatewayLaunchdJob ( env : NodeJS . ProcessEnv ) : boolean {
3344 const expectedLabel = resolveGatewayLaunchAgentLabel ( env . OPENCLAW_PROFILE ) ;
3445 if (
@@ -43,14 +54,19 @@ function isCurrentGatewayLaunchdJob(env: NodeJS.ProcessEnv): boolean {
4354export function detectRespawnSupervisor (
4455 env : NodeJS . ProcessEnv = process . env ,
4556 platform : NodeJS . Platform = process . platform ,
57+ options : DetectRespawnSupervisorOptions = { } ,
4658) : RespawnSupervisor | null {
4759 if ( platform === "darwin" ) {
4860 return hasAnyHint ( env , SUPERVISOR_HINTS . launchd ) || isCurrentGatewayLaunchdJob ( env )
4961 ? "launchd"
5062 : null ;
5163 }
5264 if ( platform === "linux" ) {
53- return hasAnyHint ( env , SUPERVISOR_HINTS . systemd ) ? "systemd" : null ;
65+ return hasAnyHint ( env , SUPERVISOR_HINTS . systemd ) ||
66+ ( options . includeLinuxOpenClawGatewayServiceMarker === true &&
67+ hasOpenClawGatewayServiceMarker ( env ) )
68+ ? "systemd"
69+ : null ;
5470 }
5571 if ( platform === "win32" ) {
5672 if ( hasAnyHint ( env , SUPERVISOR_HINTS . schtasks ) ) {
0 commit comments