有人在特定时间在生产环境中干净地启动和停止MERN应用程序有经验吗,比如说从上午9点开始到下午5点停止?该应用程序由虚拟环境中的客户端服务器部分托管。 TIA。
答案 0 :(得分:0)
您可以使用cron作业。调用cron作业时,您可以杀死该应用程序或重新启动它。
const cron = require('cron')
const nrc = require('node-run-cmd')
cron.schedule('* * 9 * *', () => {
nrc.run('npm start')
});
cron.schedule('* * 17 * *', () => {
nrc.run('pkill -f node')
});
如果您不想杀死所有节点应用程序,请先获取pid并使用适当的pkill命令