我在AWS Elastic Beanstalk中构建了NodeJs环境。我正在使用pm2监控上传到环境的两个不同的NodeJS应用程序。关键是我需要确保在gateway
应用程序启动之前local
应用程序已经启动。我正在使用npm-run-all
同步地以特定的顺序启动应用程序。
这是我的package.json:
"start": "npm-run-all -s start:local start:gateway",
"start:local": "pm2 start ./ecosystem.config.js --only local-service --env production",
"start:gateway": "pm2 start ./ecosystem.config.js --only gateway-service --env production",
这是我的ecosystem.config文件:
module.exports =
{
apps:
[
{
name: 'local-service',
script: './dist/services/local.js',
watch: false,
interpreter: 'node',
interpreter_args: '--require ts-node/register --require tsconfig-paths/register',
autorestart: false
},
{
name: 'gateway-service',
script: './dist/server.js',
watch: false,
interpreter: 'node',
interpreter_args: '--require ts-node/register --require tsconfig-paths/register',
wait_ready: true,
listen_timeout: 5000,
autorestart: false
}
]
};
弹性beanstalk日志指示package.json中的start
正在被持续调用。我已经将每个应用程序配置为不重启,但似乎还有其他原因导致连续重启。当我试图访问网关服务本身时,我得到了502 Bad Gateway
错误。
发布于 2020-07-20 17:52:28
请尝试只使用没有npm-run-all
的pm2生态系统,即只使用pm2 start ecosystem.config.js
,并允许任何(重新)启动序列,因为在现实生活中,您的gateway
和local
应用程序可能会以不同的顺序重新启动。
因此,不要使用start scheduling逻辑-请考虑将该逻辑移动到您的local
应用程序-来监控并在gateway
应用程序连接失败时重新连接。
如果您仍然想使用启动计划逻辑,请查看pm2 process actions并添加到gateway
应用程序代码以触发启动您的local
应用程序。
https://stackoverflow.com/questions/62804842
复制相似问题