禁用在PM2中重新启动

kam*_*esh 5 node.js pm2

我需要在某些条件下停止我的nodejs应用程序.所以我使用了process.exit()方法.我正在用PM2运行我的应用程序.但PM2在停止时会重新启动应用程序.那么有没有可能在PM2中禁用重启.

小智 22

我想你需要这面--no-autorestart旗帜.

"不要自动重启应用"

http://pm2.keymetrics.io/docs/usage/quick-start/


小智 8

--no-autorestart就像魅力一样简单。使用示例:pm2 start script.js --no-autorestart


Wit*_*ult 5

如果您使用pm2使用 config json 文件,例如pm2.config.json或其他需要在 json 文件中将类似选项“autorestart”指定为false

"autorestart" : false
Run Code Online (Sandbox Code Playgroud)

例如

我正在使用 pm2 使用下面的 json 配置文件运行 java 应用程序

{
  "apps" : [
    {
      "name":"JAVA-Pm2",
      "cwd":".",
      "script":"/usr/bin/java",
      "args":[
        "-jar",
        "/dir/my-java-app/build/libs/my-java-app-all.jar"
    ],
    "node_args":[],
    "exec_interpreter":"",
    "exec_mode":"fork",
    "autorestart" : false
  } 
  ]
}
Run Code Online (Sandbox Code Playgroud)