We have a NodeJS Cloud Foundry application with a DevOps Delivery Pipeline enabled. We are attempting to update our deploy script to allow us to deploy app updates without any downtime. We now have a script that mostly works (see below).
However, we realize that during the deployment, our app will start twice. What do we need to change in the script so only one server initialization will occur? Here is the script:
#!/bin/bash
# Push app
if ! cf app $CF_APP; then
cf set-env "${CF_APP}" NODE_ENV development
cf set-env "${CF_APP}" HOST_NAME bluemix
cf push $CF_APP
else
OLD_CF_APP=${CF_APP}-OLD-$(date +"%s")
rollback() {
set +e
if cf app $OLD_CF_APP; then
cf logs $CF_APP --recent
cf delete $CF_APP -f
cf rename $OLD_CF_APP $CF_APP
fi
exit 1
}
set -e
trap rollback ERR
cf rename $CF_APP $OLD_CF_APP
cf push $CF_APP
cf set-env "${CF_APP}" NODE_ENV development
cf set-env "${CF_APP}" HOST_NAME bluemix
cf restage ${CF_APP}
cf delete $OLD_CF_APP -f
fi