#!/bin/sh -x
##### 2019-04-16 ######
PUSER=mysql #ÇÁ·Î¼¼½º ¼ÒÀ¯ÀÚ
SERVICE=mysql #ÇÁ·Î¼¼½º À̸§
FORCE_SHUTDOWN=yes
#Stop Á¤»óÀûÀ¸·Î µÇÁö ¾ÊÀ»½Ã °Á¦ Kill »ç¿ë ¿©ºÎ ¼Ò¹®ÀÚ yes or no
SLEEP_TIME=3
#Start,stop ½Ã ÇØ´ç ½Ã°£ ÀÌÈÄ¿¡ Á¤»ó ¿©ºÎ(monitor ÇÔ¼ö »ç¿ë) üũ
show_procs() {
ps -U $PUSER -o pid,user,args | grep $SERVICE | grep -v grep
}
get_pid() {
show_procs | awk '{print $1}'
}
status() {
PSNUM=$(show_procs | wc -l)
if [ $PSNUM -eq 0 ]; then
return 1
else
return 0
fi
}
process_kill() {
kill -9 $(get_pid)
}
service_start() {
systemctl start mariadb.service
#su -c 'sh -x /etc/init.d/mysqld start' -l mysql
## ¿ÜºÎ ½ºÅ©¸³Æ® ¿¬µ¿½Ã¿¡´Â DebugÀ» À§ÇØ -x »ç¿ëÇÏ¿© logÀ» ³²±ä´Ù.
}
service_stop() {
systemctl stop mariadb.service
#su -c 'sh -x /etc/init.d/mysqld stop' -l mysql
}
case $1 in
start)
if status; then
echo "$SERVICE is already running"
exit 0
fi
service_start
sleep $SLEEP_TIME
if status; then
echo "$SERVICE started"
exit 0
else
echo "$SERVICE start failed"
exit 1
fi
;;
stop)
if ! status; then
echo "$SERVICE already stopped"
exit 0
fi
service_stop
sleep $SLEEP_TIME
if ! status; then
echo "$SERVICE stopped"
exit 0
else
echo "$SERVICE stop failed"
if [ $FORCE_SHUTDOWN = yes ] ;then
echo "$SERVICE is killed by cluster PID: " $(get_pid)
process_kill
sleep $SLEEP_TIME
if ! status; then
exit 0
fi
fi
exit 1
fi
;;
status)
if status; then
echo "$SERVICE is running PID: "$(get_pid)
exit 0
else
echo "$SERVICE is not running"
exit 1
fi
;;
esac