简体   繁体   English

禁止在 PM2 中重新启动

[英]Disable restarting in PM2

I need to stop my nodejs app for some conditions.So I have used process.exit() method.我需要在某些情况下停止我的 nodejs 应用程序。所以我使用了process.exit()方法。 I am running my app with PM2.我正在使用 PM2 运行我的应用程序。 But PM2 is restarting the app whenever it was stopped.但是无论何时停止,PM2 都会重新启动应用程序。 So is there any possibility to disable restarting in PM2.那么是否有可能在 PM2.2 中禁用重启?

I think you need the --no-autorestart flag.我认为您需要--no-autorestart标志。

"do not automatically restart apps" “不要自动重启应用程序”

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

If you are using pm2 using config json file eg pm2.config.json or whatever then need to specify similar option "autorestart" to false in your json file.如果您使用pm2使用配置 json 文件,例如pm2.config.json或其他任何内容,则需要在您的 json 文件中将类似选项“autorestart”指定为false

"autorestart" : false

Eg例如

I am using pm2 to run a java application using below json config file我正在使用 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
  } 
  ]
}

Simply --no-autorestart works like charm.简单地--no-autorestart就像魅力一样。 Usage example : pm2 start script.js --no-autorestart用法示例: pm2 start script.js --no-autorestart

If you are using the pm2 config file, use如果您使用的是 pm2 配置文件,请使用

"autorestart" : false

As suggested by @WitVault BUT make sure you don't have the watch option set to true like so:正如@WitVault 所建议的,但请确保您没有像这样将watch选项设置为true

"watch": true   // This field should NOT be present, otherwise "autorestart" : false is ignored

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM