如何解决无论配置文件如何,pm2 --watch 每 3 秒记录一次
我们有以下 pm2 的配置文件:
module.exports = {
apps: [
{
script: 'index.js',// ------------------------------------ watch options - begin
watch: ['/testing'],watch_delay: 10000,ignore_watch: ['node_modules','logs'],watch_options: {
followSymlinks: false,},// ------------------------------------ watch options - end
error_file: 'logs/err.log',out_file: 'logs/out.log',log_file: 'logs/combined.log',time: true,],deploy: {
production: {
user: 'SSH_USERNAME',host: 'SSH_HOSTMACHINE',ref: 'origin/master',repo: 'GIT_REPOSITORY',path: 'DESTINATION_PATH','pre-deploy-local': '','post-deploy':
'npm install && pm2 reload ecosystem.config.js --env production','pre-setup': '',};
console.log(`testing`);
我们每 3 秒就会将 'testing 打印到日志文件中;
2021-05-31T12:02:39: testing
2021-05-31T12:02:42: testing
2021-05-31T12:02:45: testing
2021-05-31T12:02:48: testing
2021-05-31T12:02:51: testing
2021-05-31T12:02:55: testing
文件没有更改,这不是 logs
目录或被监视的文件,因为它们已被 ignore_watch: ['node_modules',
排除。
为什么 --watch
不是只监视文件更改,而是每 3 秒记录一次?
解决方法
PM2 检测到您的应用正在退出并重新启动您的应用。
您可以choose what PM2 should do when it detects when your app exists,例如--no-autorestart
。
示例日志输出:
$ pm2 --watch --no-autorestart --ignore-watch=node_modules start index.js
$ pm2 logs -f
PM2 | App name:index id:0 online
0|index | testing
PM2 | App [index] with id [0] and pid [48907],exited with code [0] via signal [SIGINT]
# Modify index.js to log `testing 2`.
PM2 | Change detected on path index.js for app index - restarting
PM2 | App name:index id:0 online
0|index | testing 2
PM2 | App [index] with id [0] and pid [48910],exited with code [0] via signal [SIGINT]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。