如何让 Jelastic 启动 PM2 以启动 'npm' 命令而不是文件?
How can I make Jelastic start PM2 to launch an 'npm' command instead of a file?
我使用的是 Jelastic Node.js PM2 环境,我希望我的应用程序以如下方式启动:
pm2 start npm --name "app name" -- start
(我的服务器是不是 JS 文件)。
如果我使用 Jelastic 'npm' 环境,该命令运行良好,但我更愿意享受 PM2 的好处。
我尝试设置各种 APP_FILE
(start
、npm start
、pm2 配置文件路径)、入口点和 PROCESS_MANAGER_FILE
,但没有成功。我通常会收到此错误:
Node ID : 53209
-----------------------
result 1 Failed to start
Stopping nodejs server[ OK ] Starting nodejs server [FAILED]
@Jelastic 的评论有效!确实使用 PM2 'ecosystem file' 在 Jelastic 中有效。
将APP_FILE
(或可能PROCESS_MANAGER_FILE
)设置为ecosystem.config.js
(相对于ROOT_DIR
)
此文件的内容应如下所示:
module.exports = {
apps: [
{
script: "yarn",
args: "--cwd myserver1 start",
name: "myserver1",
},
// You can use this setup to start multiple processes too.
{
script: "yarn",
args: "--cwd myserver2 start",
name: "myserver2",
},
],
};
--cwd
告诉 yarn 切换当前工作目录。如果你使用 npm,你可以使用 --prefix
代替。
阅读更多关于 PM2 生态系统文件的信息:https://pm2.keymetrics.io/docs/usage/application-declaration/
我使用的是 Jelastic Node.js PM2 环境,我希望我的应用程序以如下方式启动:
pm2 start npm --name "app name" -- start
(我的服务器是不是 JS 文件)。
如果我使用 Jelastic 'npm' 环境,该命令运行良好,但我更愿意享受 PM2 的好处。
我尝试设置各种 APP_FILE
(start
、npm start
、pm2 配置文件路径)、入口点和 PROCESS_MANAGER_FILE
,但没有成功。我通常会收到此错误:
Node ID : 53209
-----------------------
result 1 Failed to start
Stopping nodejs server[ OK ] Starting nodejs server [FAILED]
@Jelastic 的评论有效!确实使用 PM2 'ecosystem file' 在 Jelastic 中有效。
将APP_FILE
(或可能PROCESS_MANAGER_FILE
)设置为ecosystem.config.js
(相对于ROOT_DIR
)
此文件的内容应如下所示:
module.exports = {
apps: [
{
script: "yarn",
args: "--cwd myserver1 start",
name: "myserver1",
},
// You can use this setup to start multiple processes too.
{
script: "yarn",
args: "--cwd myserver2 start",
name: "myserver2",
},
],
};
--cwd
告诉 yarn 切换当前工作目录。如果你使用 npm,你可以使用 --prefix
代替。
阅读更多关于 PM2 生态系统文件的信息:https://pm2.keymetrics.io/docs/usage/application-declaration/