英文:
create appspec.yml file for ec2 deployment
问题
我已经创建了一个Spring Boot应用程序,可以在AWS EC2实例上启动,它运行良好。然而,我现在想使用CodeDeploy自动化这个过程,这样我就不必使用puTTy连接到实例,手动下载新的jar文件并运行它。
我的问题是,我不知道在appspec.yml文件中应该写什么内容,以便实现以下操作:
- 停止应用程序
- 下载位于我的S3存储桶中.zip文件内的新的.jar文件(相当于# wget -N jarlink)
- 运行应用程序(相当于# java -jar jarname)
我知道我需要一些脚本来实现这些操作,但是我不知道从哪里获取合适的脚本。
谢谢,
Kris
英文:
I have created a spring boot app that I can launch on AWS EC2 instance and it works fine, however, I would now like to automate the process using CodeDeploy, so I wouldn't have to use puTTy to connect to the instance, download the new jar file and run it manually.
My issue is that I don't know what to write in the appspec.yml file in order to:
- Stop the application
- Download the new .jar file that sits inside of .zip file in my S3 bucket (equivalent to # wget -N jarlink)
- Run the application (equivalent to # java -jar jarname)
I am aware that I need some scripts for this, however, I don't where to get the right ones.
Cheers,
Kris
答案1
得分: 1
已解决,我的appspec.yml文件如下所示:
version: 0.0
os: linux
files:
- source: /artifact_name.jar
destination: /tmp
hooks:
ApplicationStop:
- location: stop-process.sh
timeout: 180
runas: root
ApplicationStart:
- location: start-process.sh
timeout: 180
runas: root
stop-process.sh:
#!/bin/bash
ps -ef | grep artifact_name.jar | grep -v grep | awk '{print $2}' | xargs kill
start-process.sh:
#!/bin/bash
java -jar /tmp/artifact_name.jar > /dev/null 2>&1 < /dev/null &
还在buildspec.yml中包括了这两个脚本artifact:
version: 0.2
phases:
build:
commands:
- mvn clean install
artifacts:
files:
- target/artifact_name.jar
- appspec.yml
- scripts/start-process.sh
- scripts/stop-process.sh
discard-paths: yes
英文:
Figured it out, my appspec.yml file looks as follows:
version: 0.0
os: linux
files:
- source: /artifact_name.jar
destination: /tmp
hooks:
ApplicationStop:
- location: stop-process.sh
timeout: 180
runas: root
ApplicationStart:
- location: start-process.sh
timeout: 180
runas: root
stop-process.sh:
#!/bin/bash
ps -ef | grep artifact_name.jar | grep -v grep | awk '{print $2}' | xargs kill
start-process.sh:
#!/bin/bash
java -jar /tmp/artifact_name.jar > /dev/null 2> /dev/null < /dev/null &
also included both script artifacts in buildspec.yml:
version: 0.2
phases:
build:
commands:
- mvn clean install
artifacts:
files:
- target/artifact_name.jar
- appspec.yml
- scripts/start-process.sh
- scripts/stop-process.sh
discard-paths: yes
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论