「批处理」守护NodeJS进程

背景:

日常进行CI过程中,使用NodeJs方式:GIT更新->检测是否需要编译->调用IncrediBuilder编译->读取编译日志判断是否通过->调用7z打包

问题:

持续进行一天(约18)小时候,会报错:JavaScript heap out of memory

尝试方式:

1、使用 --max-memory-restart 

cmd /c pm2 start demo.js --max-memory-restart 4096M

2、启动检测批处理,并定时杀死NodeJs进程

:next
tasklist|find /i "node.exe" && (goto save)
echo %date%%time%"重启"
pm2 resurrect
echo %date%%time%"等待10分钟"
ping 127.0.0.1 -n 600 >1.txt
del 1.txt
:save
echo %date%%time%"正常"
pm2 save
ping 127.0.0.1 -n 600 >1.txt
del 1.txt
goto next
taskkill /F /IM node.exe

 

注意事项:

1、出现:connect EPERM //./pipe/rpc.sock,解决方案:杀死进程,删除pm2.log 重启pm2

猜你喜欢

转载自www.cnblogs.com/loveclumsybaby/p/10612749.html