简体   繁体   English

如何使用PM2运行多个应用程序?

[英]How to run multiple app using PM2?

I want to run my angular4 app using PM2 it will run but when I am close the terminal it will stop. 我想使用PM2运行我的angular4应用,它将运行,但是当我关闭终端时 ,它将停止。

  1. On this server already run one application, it is working properly, but in my app it will work when I am open the terminal, otherwise it will stop 在这台服务器上已经运行了一个应用程序,它可以正常运行, 但是在我的应用程序中,当我打开终端时它将运行,否则它将停止

    pm2 start server.js pm2启动server.js

I am using this command to run my app but when I am Close the Terminal immediately it will stop, so how can I run this app Forever using PM2. 我正在使用此命令运行我的应用程序,但是当我立即关闭终端时,它将停止,因此如何使用PM2永久运行此应用程序。

If you are using PM2 properly, your applications should not be turning off after terminal exit. 如果您正确使用PM2,则退出终端后不应关闭应用程序。 It is very likely that your application is failing. 您的应用程序很可能失败。 Run pm2 logs to diagnose. 运行pm2 logs

You can specify multiple applications in a process.json file like this: 您可以在process.json文件中指定多个应用程序,如下所示:

{
    "apps" : [{
        "name"        : "worker",
        "script"      : "./worker.js",
        "watch"       : true,
        "env": {
            "NODE_ENV": "development"
        },
        "env_production" : {
            "NODE_ENV": "production"
        }
    },{
        "name"       : "api-app",
        "script"     : "./api.js",
        "instances"  : 4,
        "exec_mode"  : "cluster"
    }]
}

Documentation Here 这里的文件

Started like this: 像这样开始:

pm2 start process.json

And can monitor/view your applications by running pm2 monit or pm2 ls 并且可以通过运行pm2 monitpm2 ls监视/查看您的应用程序

You can start any NodeJs server using pm2 start ****.js --name "Project Name" . 您可以使用pm2 pm2 start ****.js --name "Project Name"启动任何NodeJs服务器。 在此处输入图片说明

You can check that server is online or not. 您可以检查服务器是否在线。

Everything is fine just run below command from ROOT 一切都很好,只需在ROOT的命令下运行

1) first go to your Project Directory and run below from from ROOT. 1)首先转到您的项目目录,然后从ROOT下运行。

pm2 start server.js

it will work fine. 它将正常工作。

If you are running the same script multiple times, with different parameters for instance, just give them different names. 如果您多次运行相同的脚本(例如,使用不同的参数),则给它们指定不同的名称。

ie

PM2 Start Engage.js --name Warp1 PM2启动Engage.js --name Warp1

PM2 Start Engage.js --name Warp2 PM2启动Engage.js --name Warp2

PM2 Start Engage.js --name Impulse PM2启动Engage.js --name脉冲

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

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