I have run into a problem when trying to setup an AWS Codepipline. My ApplicationStart script makes a call to start the express server listening on port 60900, but because the express.listen() holds the command line up while it listens the ApplicationStart script times out and my deployment fails.
I've tried moving it to a background process with an & at the end of the command that starts the server, but I'm still getting the error at the ApplicationStart hook.
When I run the my start_server.sh script manually it almost instantly starts the server up and give me back control of the command line.
appspec.yml
version: 0.0
os: linux
files:
- source: /
destination: /var/www/mbmbam.app/
hooks:
BeforeInstall:
- location: scripts/stop_server.sh
timeout: 300
runas: root
- location: scripts/remove_previous.sh
timeout: 300
runas: root
AfterInstall:
- location: scripts/change_permissions.sh
timeout: 300
runas: root
- location: scripts/install_app.sh
timeout: 300
runas: root
- location: scripts/install_db.sh
timeout: 300
runas: root
ApplicationStart:
- location: scripts/start_server.sh
timeout: 300
runas: ubuntu
scripts/start_server.sh
#!/usr/bin/env bash
NODE_ENV=production npm start --prefix /var/www/mbmbam.app/app
Script assigned to the npm start command
app/start_app.sh
#!/bin/sh
if [ "$NODE_ENV" = "production" ]; then
node server.js &
else
nodemon --ignore './sessions' server.js;
fi
AWS Codedeploy error
LifecycleEvent - ApplicationStart
Script - scripts/start_server.sh
[stdout]
[stdout]> mbmbam-search-app@1.0.0 start /var/www/mbmbam.app/app
[stdout]> ./start_app.sh
[stdout]
Any help would be appreciated. I've been stuck on this for a day or so.