【问题标题】:PM2 start script with multiple arguments (serve)带有多个参数的 PM2 启动脚本(服务)
【发布时间】:2019-08-14 07:38:42
【问题描述】:

我正在尝试从 PM2 运行 serve frontend/dist -l 4000。这应该在端口 4000 上为 Vue 应用程序提供服务。

在我的生态系统.config.js 中,我有:

    {
      name: 'parker-frontend',
      max_restarts: 5,
      script: 'serve',
      args: 'frontend/dist -l 4000',
      instances: 1,
    },

但是当我执行pm2 start 时,在日志中我有以下消息:

Exposing /var/lib/jenkins/workspace/parker/frontend/dist directory on port NaN

而如果我运行相同的命令:serve frontend/dist -l 4000,它在端口 4000 上运行得很好。

【问题讨论】:

    标签: pm2 serve


    【解决方案1】:

    在运行serve frontend/dist -l 5000 后,我在 PM2 日志中遇到了错误。

    在我找到的调用堆栈中:

    at Object.<anonymous> (/usr/lib/node_modules/pm2/lib/API/Serve.js:242:4)
    

    注意路径:/usr/lib/node_modules/pm2/lib/API/Serve.js

    在 pm2 本身中有一个名为 serve另一个 命令被运行,而不是正确的命令。这不是我之前安装的npm i -g serve。这是由于 Node 包解析的工作原理 - 它首先优先考虑本地模块。

    要使用全局安装的版本(正确的版本),您需要指定全局serve 的确切路径。

    要找出路径 - 在 Linux 上,您可以这样做:

    $ which serve
    /usr/local/bin/serve
    

    然后将路径放在您的生态系统.config.js script 属性中。

    最终工作的生态系统.config.js:

        {
          name: 'parker-frontend',
          script: '/usr/local/bin/serve', //pm2 has it's own 'serve' which doesn't work, make sure to use global
          args: 'frontend/dist -l 5000',
          instances: 1,
        },
        ```
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-18
      • 1970-01-01
      • 2017-09-04
      • 1970-01-01
      相关资源
      最近更新 更多