New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restart node every 1 hour? #1076
Comments
Look at the {
"name": "NAME",
"script": "./path/to/app.ks",
"cron_restart": "01 01 * * * *"
} |
Hmm! Thanks. Doesn't seem to work though. I actually waited for it using the time log. My processes.json looks like this:
Does it work for fork_mode? |
It only works in {
"apps" : [{
"name" : "app",
"script": "./app.js",
"watch" : true,
"exec_mode": "cluster_mode",
"cron_restart": "01 01 * * * *",
"log_date_format" : "YYYY-MM-DD HH:mm Z"
}]
} |
You can also use pm2 programmatically : var pm2 = require('pm2');
pm2.connect(function(err) {
if (err) throw err;
setTimeout(function worker() {
pm2.restart('app', function() {});
setTimeout(worker, 60 * 60 * 1000);
});
}, 60 * 60 * 1000);
}); |
Thanks I put the above code in pm2.js and started it with
I ran |
cron_restart doesn't work for me too. pid doesn't change at minites.
|
This is what I ended up using:
Works perfectly. |
The solution provided by @jshkurti works great but has a syntax error. Bugfix:
|
PM2 can restart an exited process automatically: pm2 start nodeapp.js --watch In the app exit the process every hour: setTimeout(function(){ |
I am using node-cron to achieve this with a slightly modified version of honato11's code:
var pm2 = require('pm2');
var cron = require('node-cron');
const restartListener = () => {
pm2.connect(function(err) {
if (err) throw err;
pm2.restart(process.env.LISTENER_PROCESS_NAME, () => {
pm2.disconnect()
});
});
}
const scheduledListenerRestart = cron.schedule(process.env.RESTART_LISTENER_SCHEDULE, () => {
console.log('Restarting listener')
restartListener.default()
})
scheduledListenerRestart.start()
console.log(`${new Date()} Initialised listener restart schedule`) |
pm2 3.0.0 (not tested with earlier versions) can be configured with |
crontab -e |
Is there a configuration or flag to restart the node process every hour?
The text was updated successfully, but these errors were encountered: