Last active
June 10, 2019 22:05
-
-
Save ndbroadbent/e7ba848ffed5846ae93ee1a037392893 to your computer and use it in GitHub Desktop.
Puma sanity check, for CI / Docker builds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# When running on a local machine, we need to kill the Spring loader. | |
if [ -f .env ]; then spring stop; fi | |
# Ensures that the Rails app can boot and pass a simple health check. | |
export RAILS_ENV=production | |
export PORT=4123 | |
export DATABASE_URL=postgresql:does_not_exist | |
PUMA_PID_FILE="tmp/puma.pid" | |
HEALTH_CHECK_PATH="localhost:${PORT}/health/site" | |
echo "Starting Puma..." | |
puma -C config/puma.rb --pidfile "$PUMA_PID_FILE" -d | |
sleep 0.5 | |
printf "GET $HEALTH_CHECK_PATH: " | |
RESPONSE=$(curl -s "$HEALTH_CHECK_PATH") | |
echo "$RESPONSE" | |
if [ "$RESPONSE" != "success" ]; then | |
echo "Health check failed!" | |
fi | |
if [ -f "$PUMA_PID_FILE" ]; then | |
PUMA_PID=$(cat "$PUMA_PID_FILE") | |
if [ -z "$PUMA_PID" ]; then | |
echo "$PUMA_PID_FILE was empty. Please manually kill puma." | |
fi | |
else | |
echo "Could not find PID file at $PUMA_PID_FILE. Please manually kill puma." | |
fi | |
if [ -z "$PUMA_PID" ]; then exit 1; fi | |
echo "Shutting down Puma ($PUMA_PID)..." | |
kill -HUP "$PUMA_PID" | |
if [ "$RESPONSE" != "success" ]; then exit 1; fi | |
if [ -f .env ]; then spring stop; fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment