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 of all programming languages. If Shell script is not good, it means that the operation and maintenance road may end before it even begins. ——Old boy teacher #!/bin/bash # chkconfig: 2345 64 36 #Configure system auto-start# 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 ############################################################## #Introduce the 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(){ #action is a special prompt function, $@ is all parameters. action "SUCCESS! $@" /bin/true } #Failure prompt function log_failure_msg(){ action "ERROR! $@" /bin/false } #mysql start function start(){ echo $"Starting MySQL" #Test whether mysqld_safe is executable if test -x $bindir/mysqld_safe then #Background execution starts mysql command $bindir/mysqld_safe &>/dev/null & #Get the return value retval=$? # Check if the return value is 0 if [ $retval -eq 0 ] then #Call the success prompt function. log_success_msg "mysql Startup" if test -w "$lockdir" #Judge whether the lock directory is writable. then touch "$lock_file_path" #Create a lock file. fi return $retval #Giving a return value is a professional gesture. else log_failure_msg "MySQL Startup" #Prompt of failed function call. return $retval fi else log_failure_msg "Couldn't find MySQL server ($bindir/mysqld_safe)" fi } #Stop the MySQL function. stop(){ #Judge 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"` #Judge whether the process corresponding to mysql pid exists. if (kill -0 $mysqld_pid 2>/dev/null) then echo $"Shutting down MySQL" kill $mysqld_pid #Stop the 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 does not exist!" fi } #Receive the passed parameters and execute the corresponding function. case "$1" in start) start retval=$? ;; stop) stop retval=$? ;; restart) stop sleep 2 #This is very important, take 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 full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: jQuery implements nested tab function
>>: Use of Linux relative and absolute paths
When the Docker container exits, the file system ...
Table of contents 1 Master-slave read-write separ...
1. HBase Overview 1.1 What is HBase HBase is a No...
Quickly modify the table structure of a MySQL tab...
As shown below: name describe character varying(n...
1. Design source code Copy code The code is as fol...
What is the purpose of creating your own website u...
Table of contents What is the Linux system that w...
Preface Normally, if we want to delete certain li...
Modify the IP address of the virtual machine: Ent...
hint This plug-in can only be accessed under the ...
Table of contents Preface Motivation for Fragment...
Dependence on knowledge Go cross-compilation basi...
Intersection Selector The intersection selector i...
Event response refresh: refresh only when request...