Search code examples
.netlinuxbashamazon-web-servicesaws-code-deploy

How to keep application running after CodeDeploy finishes deployment


I'm trying to automate the deployment process for my application, however I can't seem to figure out how to not have CodeDeploy terminate my application after it finishes setting it up. I think this is an issue with how I'm launching my application in appstart.sh, best I've found was using nohup which shouldn't terminate an application even after logout but it doesn't seem to have been successful either.

The current scripts are:
appstart.sh:

#!/bin/bash
/scripts/start_server.sh > /dev/null 2> /dev/null < /dev/null &  

start_server.sh:

#!/bin/bash
nohup dotnet run --project /var/project/WebServer/WebServer.fsproj &  

appspec.yml hook:

hooks:
  ApplicationStart:
    - location: scripts/appstart.sh
      timeout: 300
      runas: root  

I have tried half a dozen ways of launching the application but it always seems to shut down after CodeDeploy finishes the deployment. If I SSH into the instance after deployment and launch the application manually with nohup then it runs fine even after logout, so it seems like it's some interaction of CodeDeploy that I don't understand.


Solution

  • One way to keep the WebServer running after deployment is to use the deployment to turn it into a service with systemd. This is generally a better design due to increased application resilience with automatic restarting and also Syslog control.