Last active
August 29, 2015 14:24
-
-
Save inokappa/2411801ab9f76f01b54b to your computer and use it in GitHub Desktop.
MySQL の show status の結果を HTTP で返却する雑なスクリプト
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 | |
MYSQL_HOST="$1" | |
MYSQL_PORT="3306" | |
MYSQL_USERNAME="your_user" | |
MYSQL_PASSWORD="your_pass" | |
MSG=`/usr/bin/mysql --connect_timeout=1 -h ${MYSQL_HOST} -P ${MYSQL_PORT} -u${MYSQL_USERNAME} -p${MYSQL_PASSWORD} -e 'show status like "Slave_running"' | awk '{print $2}'` | |
if [ "$MSG" = "2" ] | |
then | |
# mysql is fine, return http 200 | |
/bin/echo -e "HTTP/1.1 200 OK\r\n" | |
/bin/echo -e "Content-Type: text/plain\r\n" | |
/bin/echo -e "\r\n" | |
/bin/echo -e "up\r\n" | |
/bin/echo -e "\r\n" | |
else | |
# mysql is fine, return http 503 | |
/bin/echo -e "HTTP/1.1 503 Service Unavailable\r\n" | |
/bin/echo -e "Content-Type: text/plain\r\n" | |
/bin/echo -e "\r\n" | |
/bin/echo -e "drain\r\n" | |
/bin/echo -e "\r\n" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
show status
が実行可能な権限を事前に用意しておくが、REPLICATION CLIENT
でもshow status
が実行出来た。