Node JS 应用程序在 AWS EC2 实例上崩溃 [英] Node JS app is crashing on AWS EC2 instance
问题描述
我已使用 codedeploy 服务在 ec2 上部署应用程序,但应用程序崩溃并显示以下错误消息:
I have deployed app on ec2 using codedeploy service but app is crashing and showing below error message:
Script at specified location: scripts/start_server failed to complete in 100 seconds
以下是我的 appspec.yml 文件:
version: 0.0
os: linux
files:
- source: /
destination: /tmp/
hooks:
AfterInstall:
- location: scripts/install_dependencies
timeout: 100
runas: root
ApplicationStart:
- location: scripts/start_server
timeout: 100
runas: root
install_dependencies
cd /tmp/
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
. ~/.nvm/nvm.sh
nvm install node
npm install
start_server
cd /tmp/
node server.js
有人告诉我我做错了什么.
Someone let me know what I am doing wrong.
推荐答案
你的部署因为这个 node server.js
挂起.这将启动您的应用程序,仅此而已.它永远不会完成,因此 CodeDeploy 超时等待它完成.
Your deployment hangs because of this node server.js
. This will start your app and that's it. It will never finish, so CodeDeploy timeouts waiting for that to finish.
解决该问题的一种方法是通过 systemd
启动您的应用.因此,您必须创建一个 systemd
单元文件.有很多例子:
One way to overcome the problem is to start your app through systemd
. Thus you have to create a systemd
unit file. There are many examples for that:
Other ways could involve running your app using pm2 or forever.
这篇关于Node JS 应用程序在 AWS EC2 实例上崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!