Reputation: 3925
Is it possible to restart a running single-threaded node process entirely from within itself?
I imagine the steps to take for a server would be something like this:
child_process.fork
or child_process.spawn
, handing over process.argv to the child.Could this work or am I totally wrong?
Upvotes: 1
Views: 2196
Reputation: 161467
This is possible, but generally people just use existing solutions that start a single master process and N server processes. Then when a server process dies or stops, it just starts a new one. One example is pm2
.
That said, your example sounds correct to me as long as you use the detached: true
argument for .spawn
Upvotes: 2