Last active
August 29, 2015 14:24
-
-
Save inokappa/1e505e2dbf24cc1a621f to your computer and use it in GitHub Desktop.
MySQL の show slave 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 slave status\G" | grep Running | grep Yes | wc -l` | |
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 slave status
が実行可能な権限REPLICATION CLIENT
が利用出来るユーザーを作成しておく。