Last active
October 28, 2015 14:18
-
-
Save damncabbage/0586e4cf9d9243982441 to your computer and use it in GitHub Desktop.
Monit, Nginx and multiple check types.
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
# /etc/monit/conf.d/nginx | |
check program nginx-http with path "/etc/monit/bin/nginx-check.sh" | |
group www | |
group nginx | |
start program = "/bin/true" # Prevent duplicate service starts. | |
stop program = "/usr/sbin/service nginx stop" # We don't care if it tries to kill nginx multiple times. :) | |
if status != 0 then restart # or alert, or whatever | |
depends on nginx-pid # Don't even try to run until the pidfile is there. | |
check process nginx-pid with pidfile "/run/nginx.pid" | |
group www | |
group nginx | |
start program = "/usr/sbin/service nginx start" | |
stop program = "/usr/sbin/service nginx stop" |
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 -e | |
URL="http://127.0.0.1/some/status-check/path" | |
# Hit the above URL: | |
# - Follow redirects | |
# - Hide output, except for the HTTP status code | |
CODE=$(/usr/bin/curl -sL -w "%{http_code}" -o /dev/null "$URL") | |
# Two "success" status codes: | |
# 200: Success all the way through to the Ruby app server. | |
# 502: We're up, but the backend is down; nothing Nginx can do about that. | |
[[ "$CODE" == "200" || "$CODE" == "502" ]] && exit 0 || exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment