我正在尝试使用一个非常简单的nodejs应用程序来完成我的设置(BitBucket到AWS(,我可以使用默认示例:
https://github.com/awslabs/aws-codedeploy-samples/tree/master/applications/SampleApp_Linux
但这个例子是在apache,httpd中,所以当我试图更改nodejs的appspec.yml时,设置会停止。这是我的appspec.yml:
version: 0.0
os: linux
files:
- source: /
destination: /var/www/app
hooks:
BeforeInstall:
- location: scripts/install_dependencies
timeout: 300
runas: root
- location: scripts/start_server
timeout: 300
runas: root
install_dependences:
#!/bin/bash
yum install -y nodejs npm
npm install
start_server:
#!/bin/bash
node server.js
我从ec2事件日志和其他地方了解到了这一点。这是我所拥有的:
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_dependences:
#!/bin/bash
cd /tmp/
curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
yum install -y gcc-c++ make
yum install -y nodejs npm
npm install -g pm2
npm install
对于start_server,请停止并删除httpd。然后启动pm2。"node-server.js"的问题是它永远无法解决。
start_server:
#!/bin/bash
cd /tmp/
isExistApp = `pgrep httpd`
if [[ -n $isExistApp ]]; then
service httpd stop
fi
yum remove -y httpd
pm2 delete all
pm2 start server.js
对于基于ubuntu/debian的发行版,我在这里和这里找到了几个注册表,它们确实帮助我实现了这一点。
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
ValidateService:
- location: scripts/test
timeout: 100
runas: root
install_dependences:
#!/bin/bash
cd /tmp/
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo apt-get install -y build-essential
npm install -g pm2
npm install
start_server:
#!/bin/bash
cd /tmp/
# set any env variables
export NODE_ENV=staging
pm2 delete all
pm2 start dist/server/index.js --name MyAPI
测试:
#!/bin/bash
sleep 10
nc -zv 127.0.0.1 80