![](/img/trans.png)
[英]run node.js by pm2,but often restart:exited with code [0] via signal [SIGINT]
[英]PM2 error occurred => exited with code [1] via signal [SIGINT]
Nodejs 在 PM2 上運行了很長時間。 還有每天清除 PM2 原木的玉米
0 0 * * * find /home/user/.pm2/logs* -mtime +2 -exec rm -rf {} \;
您正在嘗試僅使用rm
來清理日志文件。 你不能那樣做™。 在 Linux 和其他 UNIX 派生的操作系統上,即使您從目錄中rm
它,寫入日志文件的程序也會保持它處於打開狀態。 該文件實際上不會消失,直到編寫它的程序關閉它(或終止)。 這適用於各種軟件,而不僅僅是 pm2。
如果您只想清除日志文件並重新開始,那么命令pm2 flush
適合您。
如果你想在有限的時間內保存舊日志,你應該調查pm2 的日志輪換插件。
像這樣的命令可能對你有用
# install the pm2 addon ... notice it says pm2 install, not npm install
pm2 install pm2-logrotate
# rotate when a logfile fills to ten megabytes
pm2 set pm2-logrotate:max_size 10M
# gzip compress the rotated logs to save space
pm2 set pm2-logrotate:compress true
# force rotation at 00:00 each day even if logfile is not full
pm2 set pm2-logrotate:rotateInterval '0 0 * * *'
你可以說pm2 config pm2-logrotate
讓它顯示你當前的設置。
您可以嘗試以下兩個步驟並檢查它是否有效。
pm2 start bin/www -i 0 // this will start a cluster and the main app
pm2 stop 0 // this will allow the cluster to keep running
添加
out_file: "/dev/null",
error_file: "/dev/null"
到為我工作的生態系統.config.json文件。 它基本上是禁用日志。 這對於測試原因是否在日志記錄功能中很有用。
這是一種解決方法。 如果它有效,@O.Jones 的答案中建議的日志輪換也應該有效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.