Skip to content

Instantly share code, notes, and snippets.

@anfleene
Last active April 4, 2020 18:54
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save anfleene/6718088 to your computer and use it in GitHub Desktop.
Save anfleene/6718088 to your computer and use it in GitHub Desktop.
#!/bin/bash
# This script assumes you have an app running on 2 ports 4040 and 4041
# and that you can restart your app with a single command
APP_RESTART_COMMAND="/your/app/control restart"
# Find out if the app is running
function app_up {
port=$1
# Give the app a minute to boot
for i in {1..60}
do
# Use the app health check url
curl -fsI 127.0.0.1:$port/okcomputer
status=$?
if test "$status" != "0"
then
sleep 1
else
break
fi
done
return $status
}
# Uncomment any failed attempts at a hot-swap
sudo sed -i -r 's/#+(server 127.0.0.1)/server 127.0.0.1/g' /etc/nginx/nginx.conf
sudo sed -i -r 's/(server 127.0.0.1:4040)/#&/g' /etc/nginx/nginx.conf
sudo /etc/init.d/nginx reload
# Restart the process and let it spin back up
$APP_RESTART_COMMAND 4040
# If the app fails to boot exit this script non-zero
app_up 4040
status=$?
if test "$status" != "0"
then
exit 1
fi
sudo sed -i -r 's/#(server 127.0.0.1:4040)/server 127.0.0.1:4040/g' /etc/nginx/nginx.conf
sudo /etc/init.d/nginx reload
sudo sed -i -r 's/(server 127.0.0.1:4041)/#&/g' /etc/nginx/nginx.conf
sudo /etc/init.d/nginx reload
# Restart the process and let it spin back up
$APP_RESTART_COMMAND 4041
# If the app fails to boot exit this script non-zero
app_up 4041
status=$?
if test "$status" != "0"
then
exit 1
fi
sudo sed -i -r 's/#(server 127.0.0.1:4041)/server 127.0.0.1:4041/g' /etc/nginx/nginx.conf
sudo /etc/init.d/nginx reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment