【问题标题】:PM2 - cannot start my node app using custom cwd in ecosystem.jsonPM2 - 无法在生态系统.json 中使用自定义 cwd 启动我的节点应用程序
【发布时间】:2016-11-29 23:11:48
【问题描述】:

我的节点应用部署在 /opt/hello/current 但是当我使用以下生态系统.json 启动 PM2(pm2 startOrReload 生态系统.json --env 生产)时,它似乎没有考虑给定的参数......

  "apps" : [
    {
      "name": "hello",
      "cwd": "/opt/hello/current",  // the directory from which your app will be launched
      "script": "./hello.js", // script path relative to pm2 start
      "args": "",
      "watch": false,
      "node_args": "",
      "merge_logs": true,
      "env" : {
        "NODE_ENV": "development"
      },
      "env_staging" : {
        "NODE_ENV": "staging"
      },
      "env_production" : {
        "NODE_ENV": "production"
      }
    }]

它应该从“cwd”(/opt/hello/current)相对地启动脚本(./hello.js)......我错了吗?

目前以路径 /opt/hello/hello.js 开头

【问题讨论】:

    标签: node.js pm2


    【解决方案1】:

    您需要为 cwd 指定一个目录路径,在这种情况下,只需在末尾添加 / 即可:

     "apps" : [
        {
          "name": "hello",
          "cwd": "/opt/hello/current/",  // / added here
          "script": "./hello.js",
          "args": "",
          "watch": false,
          "node_args": "",
          "merge_logs": true,
          "env" : {
            "NODE_ENV": "development"
          },
          "env_staging" : {
            "NODE_ENV": "staging"
          },
          "env_production" : {
            "NODE_ENV": "production"
          }
        }]
    

    【讨论】:

    • 非常感谢......它现在运行良好......我注意到我必须删除以前运行的 'hello' 应用程序路径错误,才能让新的应用程序运行良好......
    • 如果它解决了您的问题,也许您应该考虑接受它作为答案。
    猜你喜欢
    • 2017-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-24
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多