How to start a long running process using AWS CodeDeploy hooks?

0

I have an appspec file where I am trying to start a long running Java service in an EC2 instance using AWS Code Deploy. But it seems the code deploy agent expects the script to eventually exit which won't happen for such a service unless I kill the service or perform a redeploy. And not exiting the command eventually fails the deployment.

Here is what my appspec.yml looks like

version: 0.0
os: linux
files:
  - source: /
    destination: /home/ubuntu/app
hooks:
  ApplicationStart:
    - location: bin/start-service.sh
      runas: ubuntu

And the contents of my start-service.sh looks like:

java -jar /home/ubuntu/app/target/app.jar 

which will not exit until I redeploy. How do I make the deployment succeed for such a service?

asked 2 years ago744 views
1 Answer
0

Hello,

To be able to make a long process run is by configuring something like this

-->java -jar /home/ubuntu/app/target/app.jar > /dev/null 2> /dev/null < /dev/null &[1]

The reason for this being CodeDeploy doesn't like if process run in background and this will send it to null giving some code and CodeDeploy will pass the script

Reference:

[1]https://docs.aws.amazon.com/codedeploy/latest/userguide/troubleshooting-deployments.html#troubleshooting-long-running-processes

AWS
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions