Check Service MYSQL using Xinet.d , Telnet Service MYSQL


[root@svrrepo html]# vim /opt/mysqlchk

#!/bin/bash
MYSQL_HOST=”localhost”
MYSQL_PORT=”3306″
MYSQL_USERNAME=”root”
MYSQL_PASSWORD=”passowordku”

TMP_FILE=”/tmp/mysqlchk.out”
ERR_FILE=”/tmp/mysqlchk.err”

/usr/bin/mysql –host=$MYSQL_HOST –port=$MYSQL_PORT –user=$MYSQL_USERNAME \
–password=$MYSQL_PASSWORD -e”show databases;” > /dev/null
RETVAL=$?

if [ “${RETVAL}” -eq “0” ]
then
# mysql is fine, return http 200
/bin/echo -e “HTTP/1.1 200 OK\r\n”
/bin/echo -e “Content-Type: Content-Type: text/plain\r\n”
/bin/echo -e “\r\n”
/bin/echo -e “MySQL is running.\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: Content-Type: text/plain\r\n”
/bin/echo -e “\r\n”
/bin/echo -e “MySQL is *down*.\r\n”
/bin/echo -e “\r\n”
fi

save wq!

[root@svrrepo html]# vim /etc/xinetd.d/mysqlchk

# /etc/xinetd.d/mysqlchk
# default: on
# description: mysqlchk
service mysqlchk
{
flags = REUSE
socket_type = stream
port = 9200
wait = no
user = nobody
server = /opt/mysqlchk
log_on_failure += USERID
disable = no
only_from = 0.0.0.0/0 # recommended to put the IPs that need
# to connect exclusively (security purposes)
per_source = UNLIMITED # Recently added (May 20, 2010)
# Prevents the system from complaining
# about having too many connections open from
# the same IP. More info:
# http://www.linuxfocus.org/English/November2000/article175.shtml
}

save wq!

[root@svrrepo html]# vim /etc/services
#wap-wsp 9200/tcp # WAP connectionless session service
mysqlchk 9200/tcp
wap-wsp 9200/udp # WAP connectionless session service

save wq!

[root@svrrepo html]# /etc/init.d/xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]

[root@svrrepo html]# telnet 192.168.0.253 9022
Trying 192.168.0.253…
telnet: connect to address 192.168.0.253: Connection refused
[root@svrrepo html]# telnet 192.168.0.253 9200
Trying 192.168.0.253…
Connected to 192.168.0.253.
Escape character is ‘^]’.
HTTP/1.1 200 OK

Content-Type: Content-Type: text/plain

MySQL is running.

Connection closed by foreign host.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

shisdew

Listens until think alike

moses.spaceku@yahoo.com / voip ipbx

Hosted PBX, IP-PBX SOHO/ CALL CENTER, VOICE GATEWAY, VOICE CARD, COST EFECTIVE SOLUTIONS (LCR), GSM/CDMA GATEWAY

%d bloggers like this: