Last active
August 7, 2017 13:00
-
-
Save stevenscg/a30138f7483eedb20c59d1588bf837b2 to your computer and use it in GitHub Desktop.
PHP-FPM FastCGI Health Check
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/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 |
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
# 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" | |
] | |
} |
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
/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