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/2411801ab9f76f01b54b to your computer and use it in GitHub Desktop.
Save inokappa/2411801ab9f76f01b54b to your computer and use it in GitHub Desktop.
MySQL の show 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 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
@inokappa
Copy link
Author

inokappa commented Jul 9, 2015

show status が実行可能な権限を事前に用意しておくが、 REPLICATION CLIENT でも show status が実行出来た。

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