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': '',
},
},
};

有了这个,再加上一个index.js文件:

console.log(`testing`);

我们每隔3秒就会将"测试"打印到日志文件中;

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', 'logs'],排除在外。

为什么--watch不只监视文件更改,而是每3秒记录一次?

PM2检测到您的应用程序正在退出并重新启动您的应用。

当PM2检测到你的应用程序存在时,你可以选择它应该做什么,比如--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]

最新更新