1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| [root@10 mysql-5.6.35] #!/bin/bash
if [ $# != 1 ];then echo "Please input: /etc/init.d/$0 start /etc/init.d/$0 stop /etc/init.d/$0 status " exit 0 fi
STATUS=$1 ROLE='mysql' SQLAPP="/mnt/app/${ROLE}/bin/mysqld_safe" SQLSHT="/mnt/app/${ROLE}/bin/mysqladmin" SOCKET="/mnt/data/${ROLE}/mysql.sock" COFIG="/mnt/app/${ROLE}/conf/my.cnf"
if [ $STATUS == "start" ];then ${SQLAPP} --defaults-file=${COFIG} & if [ $? == 0 ];then echo "$ROLE start success." else echo "$ROLE start fail." fi fi
if [ $STATUS == "stop" ];then ${SQLSHT} -S ${SOCKET} shutdown if [ $? == 0 ];then echo "$ROLE stoped success." else echo "$ROLE stoped fail." fi fi
if [ $STATUS == "kill" ];then PID=$(ps -ef|grep -w ${ROLE}|grep -v grep|grep -v bash|awk '{print $2}'|tr '\n' ' ') kill -9 $PID if [ $? == 0 ];then echo "$ROLE killed success." else echo "$ROLE killed fail." fi fi
if [ $STATUS == "status" ];then NUM=$(ps -ef|grep -w ${ROLE}|grep root|grep -v grep|grep -v bash|awk '{print $2}'|wc -l)
if [ $NUM == 0 ];then echo "$ROLE is stopped." exit 0 fi
if [ $NUM != 1 ];then echo "Please check $ROLE, There are $NUM processes." fi
PID=$(ps -ef|grep -w ${ROLE}|grep -v grep|grep -v bash|awk '{print $2}'|tr '\n' ' ') echo "$ROLE is running. PID: $PID" fi EOF
[root@10 mysql-5.6.35] [root@10 mysql-5.6.35]
[root@10 mysql-5.6.35] [root@10 mysql-5.6.35]
|