Skip to content

Instantly share code, notes, and snippets.

@inokappa
Last active August 29, 2015 14:24
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 inokappa/1e505e2dbf24cc1a621f to your computer and use it in GitHub Desktop.
Save inokappa/1e505e2dbf24cc1a621f to your computer and use it in GitHub Desktop.
MySQL の show slave status の結果を HTTP で返却する雑なスクリプト
#!/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
@inokappa
Copy link
Author

inokappa commented Jul 9, 2015

show slave status が実行可能な権限 REPLICATION CLIENT が利用出来るユーザーを作成しておく。

GRANT REPLICATION CLIENT ON *.* TO 'your_user'@'%' IDENTIFIED BY 'your_pass';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment