Reputation: 119
I wrote a simple function that restarts/shuts down application. Restart doesn't work and i can't figure out why. Child process starts and then instantly shuts down. I tried catching errors from the child but there was no errors.
async function Shutdown(message,restart){
if(message) console.log(message)
await Logout()
if(restart){
let proc = childprocess.spawn(process.argv[0],process.argv.splice(1),{
"detached": true,
})
}
process.exit(0)
}
Upvotes: 3
Views: 751
Reputation: 2600
From the documentation:
When using the detached option to start a long-running process, the process will not stay running in the background after the parent exits unless it is provided with a stdio configuration that is not connected to the parent.
So add stdio: 'ignore'
or other methods to make child process stays alive
let proc = childprocess.spawn(process.argv[0],process.argv.splice(1),{
detached: true,
stdio: 'ignore'
})
proc.unref();
Upvotes: 1