node.js - pm2 --watch 每隔 3 秒记录一次,与配置文件无关

标签 node.js ubuntu digital-ocean pm2

我们有以下 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 秒将 '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', 'logs'], 排除在外.
为什么不是 --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]

关于node.js - pm2 --watch 每隔 3 秒记录一次,与配置文件无关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67774159/

相关文章:

linux - 尝试安装 HUE 但没有成功

python - Theano GPU 内存不足错误

ruby-on-rails - NGINX + rails + dokku 上的错误 502 Bad Gateway

javascript - 在node.js中构建socket.io/express应用程序时我需要http吗?

javascript - fs.readFile 非常慢,我是否发出了太多请求?

docker - 为基本 http 配置 traefik,以便仪表板使用端口 80 -- 找不到页面 404

php - 如何将 Laravel 应用程序部署到 digital ocean 数据库和服务器?

node.js - 托管多个 Node JS 应用程序的 digital ocean ubuntu 14.04

javascript - 正则表达式表示仅重复我提供的字符的单词?

node.js - 使用 http 基本身份验证从应用程序获取请求 (node.js)