Every qualified Linux operation and maintenance personnel should be proficient or proficient in shell script programming, because shell scripting language is almost the simplest language in all programming languages. If shell script fails, it means that the operation and maintenance road may be coming to an end before it starts. ——Old boy teacher
#!/bin/bash
#Self configuration
# description: A very fast and reliable SQL database engine.
##############################################################
# File Name: mysqld
# Version: V1.0
# Author: oldboy
# Organization: www.oldboyedu.com
# Created Time : 2018-06-05 08:58:19
##############################################################
#Introducing system function library
. /etc/init.d/functions
#Basic path definition
basedir='/application/mysql'
bindir='/application/mysql/bin'
lockdir='/var/lock/subsys'
lock_file_path="$lockdir/mysql"
mysqld_pid_file_path='$basedir/data/`uname -n`.pid'
#Success prompt function
log_success_msg(){
#The @ is the prompt for all special functions.
action "SUCCESS! [email protected]" /bin/true
}
#Failure prompt function
log_failure_msg(){
action "ERROR! [email protected]" /bin/false
}
#Mysql start function
start(){
echo $"Starting MySQL"
#Test mysqld_ Is safe executable
if test -x $bindir/mysqld_safe
then
#Execute the start MySQL command in the background
$bindir/mysqld_safe &>/dev/null &
#Get return value
retval=$?
#Judge whether the return value is 0
if [ $retval -eq 0 ]
then
#Call success prompt function.
log_success_msg "mysql Startup"
If test - W "$lockdir" ා determines whether the lock directory is writable.
then
touch "$lock_ file_ Path "ා create a lock file.
fi
Return $return ා the return value is a professional performance.
else
log_ failure_ MSG "MySQL startup" ා call failure function prompt.
return $retval
fi
else
log_failure_msg "Couldn't find MySQL server ($bindir/mysqld_safe)"
fi
}
#Stop the MySQL function.
stop(){
#Determine whether the MySQL PID file size is 0.
if test -s "$mysqld_pid_file_path"
then
#Read pidfile
mysqld_pid=`cat "$mysqld_pid_file_path"`
#Determine whether the process corresponding to MySQL PID exists.
if (kill -0 $mysqld_pid 2>/dev/null)
then
echo $"Shutting down MySQL"
kill $mysqld_ PID ා stops MySQL command.
retval=$?
if [ $retval -eq 0 ]
then
log_ success_ MSG "MySQL stop" ා call the stop success function.
if test -f "$lock_file_path"
then
rm -f "$lock_ file_ Path "ා delete the lock file.
fi
return $retval
else
log_failure_msg "MySQL Stop."
return $retval
fi
else
log_failure_msg "MySQL server process mysqld_pid is not running!"
rm "$mysqld_pid_file_path"
fi
else
log_failure_msg "MySQL server PID file is null or not exist!"
fi
}
#Receive the parameter transfer judgment and execute the corresponding function.
case "$1" in
start)
start
retval=$?
;;
stop)
stop
retval=$?
;;
restart)
stop
Sleep 2 ා it's very important here to have a rest.
start
retval=$?
;;
*)
echo $"Usage:$0 {start|stop|restart}"
exit 2
esac
Exit $retval ා after executing the script, it is more professional to have a return value.
The above is the whole content of this article, I hope to help you in your study, and I hope you can support developeppaer more.