You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reacted by Kalpa Manamendra, Nadeem Ramsing and Mert Doğu
Reacted by Robin Goupil, jiangliwu, brenfwd, Findlay Richardson, Rostyslav Khrinovskyi, pohuj, Ammar Elshabrawy, Dariusz Filipiak, Tom Kenny, Joe Scott and 77 more
I need to restart it internaly from itself...i have app with buttons restart stop and shutdown...so when user click stop if i use nodemon it will restart not kill app....so do you have idea how can i use to restart internally using javascript code?
Best thing to do is to launch a process which launches your app as a child process. The parent process can kill and restart the child process at will. I wrote a simple nodemon alternative, the source is here:
Thanks ORESoftware...but i have node application that check if node isMaster process and i need to restart master process not child process..because i do node process clustering and i im using node clustering to do heavy stuff there so master process is what i need to restart using console...i read that best aproach is using terminal command like above but not using child process and using spawn but i try few spawn commands but none works
I thought I'd share how I did this in hopes it might help someone else searching how to do the same thing. This issue was the first result on google when I was searching for how to do this.
I'm using rabbitmq to manage scalable puppeteer worker processes for PDF generation of HTML pages. I'm using a rabbitmq exchange to send messages to all the workers to restart or shutdown themselves. Here is the relevant code I am using to have the worker processes restart themselves:
Just an FYI in case others seeking possible solutions come across this thread, here's a potentially useful mechanism:
If you are running under a process manager w/ auto-restart, (e.g. PM2),
You can send yourself a sigint, or sigterm:
process.kill(process.pid, 'SIGINT')
or process.kill(process.pid, 'SIGTERM')
Activity
Knighton910 commentedon Oct 26, 2017
Have you tried nodemon: https://nodemon.io/
ronovar commentedon Oct 26, 2017
I need to restart it internaly from itself...i have app with buttons restart stop and shutdown...so when user click stop if i use nodemon it will restart not kill app....so do you have idea how can i use to restart internally using javascript code?
MM422 commentedon Oct 27, 2017
Hi, I am not quite sure whether I have fully understand about your use case but could you try this: https://github.com/foreverjs/forever
ORESoftware commentedon Oct 27, 2017
Best thing to do is to launch a process which launches your app as a child process. The parent process can kill and restart the child process at will. I wrote a simple nodemon alternative, the source is here:
https://medium.com/@the1mills/diy-nodemon-5176fdcc1cfb
ronovar commentedon Oct 28, 2017
Thanks ORESoftware...but i have node application that check if node isMaster process and i need to restart master process not child process..because i do node process clustering and i im using node clustering to do heavy stuff there so master process is what i need to restart using console...i read that best aproach is using terminal command like above but not using child process and using spawn but i try few spawn commands but none works
gireeshpunathil commentedon Mar 26, 2018
@ronovar - is this still outstanding?
gireeshpunathil commentedon Mar 27, 2018
closing due to inactivity, please re-open if it is still outstanding.
rockyjvec commentedon Sep 24, 2018
I thought I'd share how I did this in hopes it might help someone else searching how to do the same thing. This issue was the first result on google when I was searching for how to do this.
I'm using rabbitmq to manage scalable puppeteer worker processes for PDF generation of HTML pages. I'm using a rabbitmq exchange to send messages to all the workers to restart or shutdown themselves. Here is the relevant code I am using to have the worker processes restart themselves:
Depending on how you originally start the process, you may need to change argv[1] and slice(2) to argv[0] and slice(1).
Hope that helps.
twome commentedon Mar 27, 2019
Single-statement version of @rockyjvec's incredibly useful answer:
ChiweenieDijon commentedon Nov 20, 2019
Just an FYI in case others seeking possible solutions come across this thread, here's a potentially useful mechanism:
If you are running under a process manager w/ auto-restart, (e.g. PM2),
You can send yourself a sigint, or sigterm:
process.kill(process.pid, 'SIGINT')or
process.kill(process.pid, 'SIGTERM')(although i think it's not as simple on windows)
LingleDev commentedon Sep 8, 2021
If you're using pm2, you could simply run this bit of code to restart your process:
true-goniss commentedon May 3, 2024
Solution for windows (none of the posted solutions worked):
create restart_script.bat at the same folder as the script with the following content (replace the name):
then you can restart the script from itself: