@@ -7,10 +7,11 @@ import {
77} from "../daemon/constants.js" ;
88import { createSubsystemLogger } from "../logging/subsystem.js" ;
99import { cleanStaleGatewayProcessesSync , findGatewayPidsOnPortSync } from "./restart-stale-pids.js" ;
10+ import { relaunchGatewayScheduledTask } from "./windows-task-restart.js" ;
1011
1112export type RestartAttempt = {
1213 ok : boolean ;
13- method : "launchctl" | "systemd" | "supervisor" ;
14+ method : "launchctl" | "systemd" | "schtasks" | " supervisor";
1415 detail ?: string ;
1516 tried ?: string [ ] ;
1617} ;
@@ -296,36 +297,41 @@ export function triggerOpenClawRestart(): RestartAttempt {
296297 cleanStaleGatewayProcessesSync ( ) ;
297298
298299 const tried : string [ ] = [ ] ;
299- if ( process . platform !== "darwin" ) {
300- if ( process . platform === "linux" ) {
301- const unit = normalizeSystemdUnit (
302- process . env . OPENCLAW_SYSTEMD_UNIT ,
303- process . env . OPENCLAW_PROFILE ,
304- ) ;
305- const userArgs = [ "--user" , "restart" , unit ] ;
306- tried . push ( `systemctl ${ userArgs . join ( " " ) } ` ) ;
307- const userRestart = spawnSync ( "systemctl" , userArgs , {
308- encoding : "utf8" ,
309- timeout : SPAWN_TIMEOUT_MS ,
310- } ) ;
311- if ( ! userRestart . error && userRestart . status === 0 ) {
312- return { ok : true , method : "systemd" , tried } ;
313- }
314- const systemArgs = [ "restart" , unit ] ;
315- tried . push ( `systemctl ${ systemArgs . join ( " " ) } ` ) ;
316- const systemRestart = spawnSync ( "systemctl" , systemArgs , {
317- encoding : "utf8" ,
318- timeout : SPAWN_TIMEOUT_MS ,
319- } ) ;
320- if ( ! systemRestart . error && systemRestart . status === 0 ) {
321- return { ok : true , method : "systemd" , tried } ;
322- }
323- const detail = [
324- `user: ${ formatSpawnDetail ( userRestart ) } ` ,
325- `system: ${ formatSpawnDetail ( systemRestart ) } ` ,
326- ] . join ( "; " ) ;
327- return { ok : false , method : "systemd" , detail, tried } ;
300+ if ( process . platform === "linux" ) {
301+ const unit = normalizeSystemdUnit (
302+ process . env . OPENCLAW_SYSTEMD_UNIT ,
303+ process . env . OPENCLAW_PROFILE ,
304+ ) ;
305+ const userArgs = [ "--user" , "restart" , unit ] ;
306+ tried . push ( `systemctl ${ userArgs . join ( " " ) } ` ) ;
307+ const userRestart = spawnSync ( "systemctl" , userArgs , {
308+ encoding : "utf8" ,
309+ timeout : SPAWN_TIMEOUT_MS ,
310+ } ) ;
311+ if ( ! userRestart . error && userRestart . status === 0 ) {
312+ return { ok : true , method : "systemd" , tried } ;
313+ }
314+ const systemArgs = [ "restart" , unit ] ;
315+ tried . push ( `systemctl ${ systemArgs . join ( " " ) } ` ) ;
316+ const systemRestart = spawnSync ( "systemctl" , systemArgs , {
317+ encoding : "utf8" ,
318+ timeout : SPAWN_TIMEOUT_MS ,
319+ } ) ;
320+ if ( ! systemRestart . error && systemRestart . status === 0 ) {
321+ return { ok : true , method : "systemd" , tried } ;
328322 }
323+ const detail = [
324+ `user: ${ formatSpawnDetail ( userRestart ) } ` ,
325+ `system: ${ formatSpawnDetail ( systemRestart ) } ` ,
326+ ] . join ( "; " ) ;
327+ return { ok : false , method : "systemd" , detail, tried } ;
328+ }
329+
330+ if ( process . platform === "win32" ) {
331+ return relaunchGatewayScheduledTask ( process . env ) ;
332+ }
333+
334+ if ( process . platform !== "darwin" ) {
329335 return {
330336 ok : false ,
331337 method : "supervisor" ,
0 commit comments