简体   繁体   English

如何在 PM2 中运行 2 个独立的应用程序?

[英]How to run 2 separate apps in PM2?

Right now I am using pm2 to run a node server app.现在我正在使用 pm2 运行节点服务器应用程序。 I do that with pm2 start npm .我用pm2 start npm做到这一点。 This seems to be independent of the current directory.这似乎与当前目录无关。

I found some mentions online to use pm2 start npm --name "app_name" -- start .我在网上发现一些提到使用pm2 start npm --name "app_name" -- start However, no matter what name I specify and directory I am inside, it always starts the same app.但是,无论我指定什么名称和我所在的目录,它总是启动同一个应用程序。

Due to the nature of node, I don't run a single .js file and just type npm start in the current directory.由于节点的性质,我不运行单个 .js 文件,只在当前目录中键入npm start

Edit: From my understanding, the problem seems to be that pm2 always starts /usr/bin/npm (Starting /usr/bin/npm in fork_mode (1 instance). So the --name flag doesn't matter much, ie. I can get a list of the same app with different names, and this app is node app A and sometimes node app B. I am kinda lost编辑:根据我的理解,问题似乎是 pm2 总是启动 /usr/bin/npm (在 fork_mode 中启动 /usr/bin/npm (1 个实例)。所以 --name 标志并不重要,即。我可以得到一个名称不同的同一个应用程序的列表,这个应用程序是节点应用程序 A,有时是节点应用程序 B。我有点迷茫

What is happening is you have a PM2 app named npm , thus the confusion.发生的事情是您有一个名为npm的 PM2 应用npm ,因此很混乱。 You can list pm2 apps with pm2 ls您可以使用pm2 ls列出 pm2 应用程序

First, remove it using :首先,使用以下方法删除它:

pm2 del npm

Then, start a new app, naming it :然后,启动一个新应用程序,命名为:

pm2 start npm --name "app_name" -- start

Then, the second app (in the other directory) with :然后,第二个应用程序(在另一个目录中):

pm2 start npm --name "app_name2" -- start

You can run Multiple apps using PM2 just follow below steps:您可以使用 PM2 运行多个应用程序,只需按照以下步骤操作:

Firstly enter into directory A and start it on PM2 pm2 start server.js --name app-name首先进入A目录在PM2上pm2 start server.js --name app-name

Save this in PM2 using pm2 save使用pm2 save保存在 PM2 中

Now to run other app you need enter into directory B and start app using pm2 start server.js --name app-name现在要运行其他应用程序,您需要进入目录B并使用pm2 start server.js --name app-name

Save this process as well, and now check PM2 list using pm2 ls也保存这个过程,现在使用pm2 ls检查 PM2 列表

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

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