本文主要給大家介紹企業(yè)級(jí)使用shell是如何開發(fā)MySQL啟動(dòng)腳本的,文章內(nèi)容都是筆者用心摘選和編輯的,具有一定的針對(duì)性,對(duì)大家的參考意義還是比較大的,下面跟筆者一起了解下企業(yè)級(jí)使用shell是如何開發(fā)MySQL啟動(dòng)腳本的吧。
創(chuàng)新互聯(lián)公司是一家集網(wǎng)站建設(shè),遜克企業(yè)網(wǎng)站建設(shè),遜克品牌網(wǎng)站建設(shè),網(wǎng)站定制,遜克網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,遜克網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競爭力。可充分滿足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。說明
MySQL啟動(dòng)命令為:
/bin/sh mysqld_safe --pid-file=$mysqld_pid_file_path 2>&1 > /dev/null &
停止命令為:
mysqld_pid=`cat "$mysqld_pid_file_path"`
if (kill -0 $mysqld_pid 2>/dev/null)
then
kill $mysqld_pid
sleep 2
fi
請完成MySQL啟動(dòng)腳本的編寫
要求:用函數(shù),case語句、if語句等實(shí)現(xiàn)。
解答:
[root@db02 scripts]# cat /etc/init.d/oldgirl
#!/bin/bash
# chkconfig: 2345 64 36
# description: MySQL startup
#Author:oldboy
#Blog:http://oldboy.blog.51cto.com
#Time:2017-07-07 09:24:34
#Name:mysqld.sh
#Version:V1.0
#Description:This is a test script.
[ -f /etc/init.d/functions ] && source /etc/init.d/functions
Port=3306
User="root"
Bindir="/application/mysql/bin"
Datadir="/application/mysql/data"
mysqld_pid_file_path="/application/mysql/`hostname`.pid"
PATH="/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin"
export PATH
return_value=
# Lock directory.
lockdir='/var/lock/subsys'
lock_file_path="$lockdir/mysql"
log_success_msg(){
echo " SUCCESS! $@"
}
log_failure_msg(){
echo " ERROR! $@"
}
case "$1" in
start)
# Start daemon
echo "Starting MySQL"
if test -x $Bindir/mysqld_safe
then
$Bindir/mysqld_safe --datadir="$Datadir" --pid-file="$mysqld_pid_file_path" >/dev/null &
return_value=$?
sleep 2
# Make lock for CentOS
if test -w "$lockdir"
then
touch "$lock_file_path"
fi
exit $return_value
else
log_failure_msg "Couldn't find MySQL server ($bindir/mysqld_safe)"
fi
;;
stop)
if test -s "$mysqld_pid_file_path"
then
mysqld_pid=`cat "$mysqld_pid_file_path"`
if (kill -0 $mysqld_pid 2>/dev/null)
then
echo "Shutting down MySQL"
kill $mysqld_pid
return_value=$?
sleep 2
else
log_failure_msg "MySQL server process #$mysqld_pid is not running!"
rm -f "$mysqld_pid_file_path"
fi
# Delete lock for CentOS
if test -f "$lock_file_path"
then
rm -f "$lock_file_path"
fi
exit $return_value
else
log_failure_msg "MySQL server PID file could not be found!"
fi
;;
restart)
if $0 stop; then
$0 start
else
log_failure_msg "Failed to stop running server, so refusing to try to start."
exit 1
fi
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit $return_value
函數(shù)版:
#!/bin/bash
# chkconfig: 2345 64 36
# description: MySQL startup
#Author:oldboy
#Blog:http://oldboy.blog.51cto.com
#Time:2017-07-07 09:24:34
#Name:mysqld.sh
#Version:V1.0
#Description:This is a test script.
[ -f /etc/init.d/functions ] && source /etc/init.d/functions
port=3306
user="root"
bindir="/application/mysql/bin"
datadir="/application/mysql/data"
mysqld_pid_file_path="/application/mysql/`hostname`.pid"
PATH="/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin"
export PATH
return_value=
# Lock directory.
lockdir='/var/lock/subsys'
lock_file_path="$lockdir/mysql"
log_success_msg(){
echo " SUCCESS! $@"
}
log_failure_msg(){
echo " ERROR! $@"
}
start(){
# Start daemon
echo "Starting MySQL"
if test -x $bindir/mysqld_safe
then
$bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" >/dev/null &
return_value=$?
sleep 2
# Make lock for CentOS
if test -w "$lockdir"
then
touch "$lock_file_path"
fi
exit $return_value
else
log_failure_msg "Couldn't find MySQL server ($bindir/mysqld_safe)"
fi
}
stop(){
if test -s "$mysqld_pid_file_path"
then
mysqld_pid=`cat "$mysqld_pid_file_path"`
if (kill -0 $mysqld_pid 2>/dev/null)
then
echo "Shutting down MySQL"
kill $mysqld_pid
return_value=$?
sleep 2
else
log_failure_msg "MySQL server process #$mysqld_pid is not running!"
rm -f "$mysqld_pid_file_path"
fi
# Delete lock for CentOS
if test -f "$lock_file_path"
then
rm -f "$lock_file_path"
fi
exit $return_value
else
log_failure_msg "MySQL server PID file could not be found!"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
if $0 stop; then
$0 start
else
log_failure_msg "Failed to stop running server, so refusing to try to start."
exit 1
fi
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit $return_value
看完以上關(guān)于企業(yè)級(jí)使用shell是如何開發(fā)MySQL啟動(dòng)腳本的,很多讀者朋友肯定多少有一定的了解,如需獲取更多的行業(yè)知識(shí)信息 ,可以持續(xù)關(guān)注我們的行業(yè)資訊欄目的。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。