Skip to content

Instantly share code, notes, and snippets.

@stevenscg
Last active August 7, 2017 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevenscg/a30138f7483eedb20c59d1588bf837b2 to your computer and use it in GitHub Desktop.
Save stevenscg/a30138f7483eedb20c59d1588bf837b2 to your computer and use it in GitHub Desktop.
PHP-FPM FastCGI Health Check
#!/bin/sh
#
# Health Check - php-fpm
#
# Usage:
# ./fcgi.sh host:port|path/to/socket /path/to/file
#
# Examples:
# ./fcgi.sh ip:port /status?json
#
if [ "$#" -ne 2 ]; then
echo "Usage: $0 host:port|path/to/socket /path/to/file"
exit 1
fi
# Extremely naive url and query string separation
URI="`echo $2 | grep / | cut -d '?' -f 1`"
QUERY="`echo $2 | grep / | cut -d '?' -f 2`"
# @TODO capture the response, split at the blank, return the payload
SCRIPT_NAME=$URI \
SCRIPT_FILENAME=$URI \
QUERY_STRING=$QUERY \
REQUEST_METHOD=GET \
cgi-fcgi -bind -connect $1 || exit 1
# the check stanza for this check script
check {
name = "php-fpm-fcgi"
type = "script"
interval = "30s"
timeout = "5s"
command = "/health/fcgi.sh"
args = [
"${NOMAD_ADDR_fpm}", "/health"
]
}
/var/www/html # /bin/sh /health/fcgi.sh <IP>:<PORT> /health
X-Powered-By: PHP/7.0.21
Content-type: text/plain;charset=UTF-8
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Cache-Control: no-cache, no-store, must-revalidate, max-age=0
OK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment