In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
< "$mysqld_pid_file_path" kill -HUP $mysqld_pid && log_success_msg "Reloading service MySQL" touch "$mysqld_pid_file_path" else log_failure_msg "MySQL PID file could not be found!" exit 1 fi ;; 'status') # First, check to see if pid file exists if test -s "$mysqld_pid_file_path" ; then read mysqld_pid < "$mysqld_pid_file_path" if kill -0 $mysqld_pid 2>/ dev/null; then log_success_msg "MySQL running ($mysqld_pid)" exit 0 else log_failure_msg "MySQL is not running, but PID file exists" exit 1 fi else # Try to find appropriate mysqld process mysqld_pid= `pidof $libexecdir/ mysqld` # test if multiple pids exist pid_count= `echo $mysqld_pid | wc-w`if test $pid_count-gt 1; then log_failure_msg "Multiple MySQL running but PID file could not be found ($mysqld_pid)" exit 5 elif test-z $mysqld_pid Then if test-f "$lock_file_path"; then log_failure_msg "MySQL is not running, but lock file ($lock_file_path) exists" exit 2 fi log_failure_msg "MySQL is not running" exit 3 else log_failure_msg "MySQL is running but PID file could not be found" exit 4 fi fi; *) # usage basename= `basename "$0" `echo "Usage: $basename {start | stop | restart | reload | force-reload | status} [MySQL server options]" exit 1;; esacexit 0
First, define the relevant parameters
Basedir=datadir=# Default value, in seconds, afterwhich the script should timeout waiting# for server start. # Value here is overriden by value in my.cnf. # 0 means don't wait at all# Negative numbers mean to wait indefinitelyservice_startup_timeout=900# Lock directory for RedHat / SuSE.lockdir='/var/lock/subsys'lock_file_path= "$lockdir/mysql"
Among them
Basedir refers to the directory where the binary package is unzipped, such as / usr/local/mysql.
Datadir refers to the data directory
Service_startup_timeout=900 defines the time limit for the mysql service to start, and if the startup is not successful in 900s, the script exits.
Lockdir='/var/lock/subsys'
With regard to / var/lock/subsys, the online explanation is as follows, which will be used later.
In general, the process of shutting down the system (the process that signals the shutdown and calls the service itself) checks the files under / var/lock/subsys and shuts down each service one by one, if a running service does not have the corresponding option under / var/lock/subsys. When the system shuts down, it kills the service as if it were a normal process.
By looking at the script under / etc/rc.d/init.d, you can see that each service will check the corresponding service under / var/lock/subsys when it manipulates itself.
Many programs need to determine whether there is already an instance running. This directory is the flag that allows the program to determine whether there is an instance running, such as xinetd. If this file exists, it means that there is already xinetd running, otherwise there is no such thing. Of course, there should be corresponding judgment measures in the program to determine whether there is an instance running. This directory is usually accompanied by the / var/run directory, which is used to store the PID of the corresponding instance. If you write a script, you will find that the combination of these two directories can easily determine whether many services are running, related information, and so on.
Judge basedir and datadir
# Set some defaultsmysqld_pid_file_path=if test-z "$basedir" then basedir=/usr/local/mysql bindir=/usr/local/mysql/bin if test-z "$datadir" then datadir=/usr/local/mysql/data fi sbindir=/usr/local/mysql/bin libexecdir=/usr/local/mysql/binelse bindir= "$basedir/bin" if test-z "$datadir" then datadir= "$basedir/data" fi sbindir= "$basedir/sbin" libexecdir= "$basedir/libexec" fi
Among them
Mysqld_pid_file_path specifies the path to the pid file
-z string determines whether the string is empty
If basedir does not display settings, the default is / usr/local/mysql, which is why many mysql installation tutorials recommend putting mysql-related files under / usr/local/mysql.
If datadir does not have a display setting, the default is $basedir/data.
Define the log_success_msg () and log_failure_msg () functions
First, determine whether the / lib/lsb/init-functions file exists, and if so, make all shell functions defined in the init-functions file take effect in the current script.
If not, two functions are defined, one for printing the success log and one for printing the error log.
In RHCS 6.7, the file does not exist and has been replaced by / etc/init.d/functions.
# # Use LSB init script functions for printing messages, if possible#lsb_functions= "/ lib/lsb/init-functions" if test-f $lsb_functions; then. $lsb_functionselse log_success_msg () {echo "SUCCESS! $@"} log_failure_msg () {echo "ERROR! $@"} fi
Transfer parameters
Pass the first parameter to mode and the remaining parameters to other_args
PATH= "/ sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin" export PATHmode=$1 # start or stop [$#-ge 1] & & shiftother_args= "$*" # uncommon, but needed when called from an RPM upgrade action # Expected: "--skip-networking-- skip-grant-tables" # They are not checked here, intentionally, as it is the resposibility # of the "spec" file author to give correct arguments only.case `echo "testing\ c" `, `echo-n testing` in * c * -n *) echo_n= echo_c= ; * clockwork *) echo_n=-n echo_c=; *) echo_n= echo_c='\ c';; esac
Parsing parameters in the configuration file
This function is referred to later in the script.
It mainly involves the following parameters:-- basedir,--datadir,--pid-file,--service-startup-timeout.
Parse_server_arguments () {for arg do case "$arg" in-- basedir=*) basedir= `echo "$arg" | sed-e's / ^ [^ =] * = / / '`bindir= "$basedir/bin" if test-z "$datadir_set"; then datadir= "$basedir/data" fi sbindir= "$basedir/sbin" libexecdir= "$basedir/libexec";;-- datadir=*) datadir= `echo "$arg" | sed-e's / ^ [^ =] * / /' `datadir_set=1 -- pid-file=*) mysqld_pid_file_path= `echo "$arg" | sed-e's / ^ [^ =] * = / /'`;;-- service-startup-timeout=*) service_startup_timeout= `echo "$arg" | sed-e's / ^ [^ =] * = / /'`;; esac done}
Determine the location of the my_print_defaults
First, it determines whether the executable exists in the bin directory under the current path, and if not, it determines whether it exists in the $bindir (usually $basedir/bin) directory.
If not, it is determined whether / etc/my.cnf exists and is readable, and if so, whether the basedir parameter is specified in the configuration file
If specified, take out the value of the parameter and determine whether there is a bin/my_print_defaults executable file in the directory corresponding to the value
Finally, if the my_print_defaults file is not found in the above directory
Simply set print_defaults to "my_print_defaults", hoping that the command is in the current PATH environment.
# Get arguments from the my.cnf file,# the only group Which is read from now on is [mysqld] if test-x. / bin/my_print_defaultsthen print_defaults= ". / bin/my_print_defaults" elif test-x $bindir/my_print_defaultsthen print_defaults= "$bindir/my_print_defaults" elif test-x $bindir/mysql_print_defaultsthen print_defaults= "$bindir/mysql_print_defaults" else # Try to find basedir in/ etc/my.cnf conf=/etc/my.cnf print_defaults= if test-r $conf then subpat=' ^ [^ =] * basedir [^ =] * =\ (. *\) $'dirs= `sed-e "/ $subpatpacpacpacer print d"-e's for d in /\ 1Accord' $conf` for d in $print d = `echo $d | sed-e's / [] / / g '`if test-x "$d/bin/my_print_defaults" then print_defaults= "$d/bin/my_print_defaults" break fi if test-x "$d/bin/mysql_print_defaults" then print_defaults= "$dbinqlprint _ Defaults "break fi done fi # Hope it's in the PATH... But I doubt it test-z "$print_defaults" & & print_defaults= "my_print_defaults" fi
Find the default profile
-r file true if the file is readable
# # Read defaults file from 'basedir'. If there is no defaults file there# check if it's in the old (depricated) place (datadir) and read it from there#extra_args= "" if test-r "$basedir/my.cnf" then extra_args= "- e $basedir/my.cnf" else if test-r "$datadir/my.cnf" then extra_args= "- e $datadir/my.cnf" fifi
Parsing parameters in the configuration file
The usage of my_print_defaults is as follows:
My_print_defaults-defaults-file=example.cnf client mysql
That is, to read the parameter configuration in the client and mysql sections of the configuration file
Specifically in this script, the configuration parameters of the four parts of mysqld,server,mysql_server,mysql.server are read.
Parse_server_arguments `$print_defaults $extra_args mysqld server mysql_server mysql.server`
Set the path of pid file
-z string determines whether the string is empty
If-- pid-file is not set in the read configuration file or the mysqld_pid_file_path parameter at the beginning of the script is not set
Then pid file is set under datadir by default and is named after the hostname .pid.
If this parameter is set, further judgment is needed.
If there is a slash in the parameter, it represents the given value with a path and can be used directly.
If there is no path in this parameter, it means that the given value is just the file name of pid, which can be set under datadir.
# # Set pid file if not given#if test-z "$mysqld_pid_file_path" then mysqld_pid_file_path=$datadir/ `hostname`.pidelse case "$mysqld_pid_file_path" in / *); *) mysqld_pid_file_path= "$datadir/$mysqld_pid_file_path";; esacfi
Service script start option
First, switch to $basedir
Second, determine whether the mysqld_safe in $basedir/bin is an executable file, if so, start the mysqld instance, and if not, report an error to exit.
So how is the startup process implemented?
First, start the mysqld instance by executing the $bindir/mysqld_safe-- datadir= "$datadir"-- pid-file= "$mysqld_pid_file_path" $other_args > / dev/null 2 > & 1 & command.
Notice that mysqld_safe is actually executed in basedir, including the mysql initialization script mysql_install_db. It is also recommended to execute in basedir. For more information, please see:
Analyze the MariaDB initialization script mysql_install_db
Then it is judged by the wait_for_pid function, which can be seen in the following analysis of the wait_for_pid function
After the judgment is finished
Check to see if the $lockdir directory is writable, and if so, create a file on the directory.
Case "$mode" in 'start') # Start daemon # Safeguard (relative paths, core dumps..) Cd $basedir echo $echo_n "Starting MySQL" if test-x $bindir/mysqld_safe then # Give extra arguments to mysqld with the my.cnf file. This script # may be overwritten at next upgrade. $bindir/mysqld_safe-datadir= "$datadir"-pid-file= "$mysqld_pid_file_path" $other_args > / dev/null 2 > & 1 & wait_for_pid created "$!"$mysqld_pid_file_path"; return_value=$? # Make lock for RedHat / SuSE 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
Wait_for_pid function
This parameter is called after the mysql instance is started with mysqld_safe
Wait_for_pid created "$!"$mysqld_pid_file_path"; return_value=$?
Of which $! The PID used in shell to get the last running background Process, specifically, in this case, the pid of the mysqld_safe process.
Because the first argument is created, the test-s "$pid_file_path" & & break command is executed.
-s file true if the length of the file is not zero
This command means that if the pid file exists, set the variable I to empty and exit the while loop.
Then perform the following judgment
If test-z "$I"; then log_success_msg return 0 else log_failure_msg return 1 fi
If $I is empty, the success log is printed and the script exits, obviously setting the variable I to empty if the pid file exists.
Let's take a look at the situation where the pid file does not exist.
First, it determines whether $pid is not empty (that is, if test-n "$pid")
If it is not empty, it means that the pid of the process has been captured after executing the mysqld_safe.
In this case, further confirm the existence of the process through kill-0 "$pid".
Kill-0 does not send any signal, but the system will check for errors, so it is often used to check whether a process exists. When a process does not exist, kill-0 pid will return an error.
If the process exists, do nothing but skip to the following
Echo $echo_n ". $echo_c" I = `expr $I + 1`sleep 1
Add the variable I to 1 and sleep 1s.
Then, continue the while loop, considering that mysqld_safe has been executed, but the mysqld instance is still in the process of starting, and the pid file has not yet been created.
Until $1 reaches the time defined by $service_startup_timeout.
If you judge that the process no longer exists through kill-0 "$pid" during the while loop
It will be judged again, and if the result of this judgment is that pid file does not exist and the process does not exist, it will be executed
Log_failure_msg "The server quit without updating PID file ($pid_file_path)."
This is the origin of the famous "The server quit without updating PID file".
Wait_for_pid () {verb= "$1" # created | removed pid= "$2" # process ID of the program operating on the pid-file pid_file_path= "$3" # path to the PID file. Do case 0 avoid_race_condition= "by checking again" while test $I-ne $service_startup_timeout; do case "$verb" in 'created') # wait for a PID-file to pop into existence. Test-s "$pid_file_path" & & iTunes'& & break;; 'removed') # wait for this PID-file to disappear test!-s "$pid_file_path" & break;; *) echo "wait_for_pid () usage: wait_for_pid created | removed pid pid_file_path" exit 1;; esac # if server isn't running, then pid-file will never be updated if test-n "$pid" Then if kill-0 "$pid" 2 > / dev/null; then: # the server still runs else # The server may have exited between the last pid-file check and now. If test-n "$avoid_race_condition"; then avoid_race_condition= "" continue # Check again. Fi # there's nothing that will affect the file. Log_failure_msg "The server quit without updating PID file ($pid_file_path)." Return 1 # not waiting any more. Fi fi echo $echo_n ".$ echo_c" I = `expr $I + 1`expr 1 done if test-z "$I"; then log_success_msg return 0 else log_failure_msg return 1 fi}
Service script stop option
First, determine whether the length of the pid file is not zero.
-s file true if the length of the file is not zero
At this point, the pid of the mysqld process will be obtained through the pid file. Note that it is not the pid of the mysqld_safe process.
Then, determine whether the mysqld process is running properly
If so, shut down the mysqld process by kill $mysqld_pid
The safest way to kill a process is to simply use the kill command without modifiers or flags.
The standard kill command usually terminates the problematic process and releases the process's resources to the system. However, if the process starts the child process, only the parent process is killed, and the child process is still running, thus still consuming resources. To prevent these so-called "zombie processes", be sure to kill all of the parent's child processes before killing them.
Then, call the wait_for_pid function to determine that, in fact, the purpose of setting the avoid_race_condition variable in the wait_for_pid function is for the stop option, which is indeed possible. Mysqld exits after checking pid file and before checking whether the process is alive.
If the mysqld process is not running properly, "MySQL server process # $mysqld_pid is not running!" will be printed. Information and delete the pid file.
If the length of the pid file is determined to be 0 when stop is executed, "MySQL server PID file could not be found!" will be printed. information.
So, in the case where the pid file does not exist, executing the stop option through the service script does not close the mysqld process, and at this point, you can shut down the mysqld process by means of kill $mysqld_pid.
'stop') # Stop daemon. We use a signal here to avoid having to know the # root password. 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 $echo_n "Shutting down MySQL" kill $mysqld_pid # mysqld should remove the pid file when it exits, so wait for it. Wait_for_pid removed "$mysqld_pid"$mysqld_pid_file_path"; return_value=$? Else log_failure_msg "MySQL server process # $mysqld_pid is not running!" Rm "$mysqld_pid_file_path" fi # Delete lock for RedHat / SuSE 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
Service script restart option
First, the stop operation is performed, and if the stop operation is successful, the start operation continues.
If the stop operation fails, "Failed to stop running server, so refusing to try to start." is output. Information and exit the script.
'restart') # Stop the service and regardless of whether it was # running or not, start it again. If $0 stop $other_args; then $0 start $other_args else log_failure_msg "Failed to stop running server, so refusing to try to start." Exit 1 fi
Service script reload option
First, determine whether the length of the pid file is 0, and if not, set the value in the file to the value of the mysqld_pid variable.
Then perform a kill-HUP operation on the process.
Kill-HUP pid
Pid is the process identity. Use this command if you want to change the configuration without stopping and restarting the service. After making the necessary changes to the configuration file, issue this command to dynamically update the service configuration.
By convention, when you send a hang signal (signal 1 or HUP), most server processes (all commonly used processes) reset and reload their configuration files.
If the length of the pid file is 0, output "MySQL PID file could not be found!".
'reload' |' force-reload') if test-s "$mysqld_pid_file_path"; then read mysqld_pid
< "$mysqld_pid_file_path" kill -HUP $mysqld_pid && log_success_msg "Reloading service MySQL" touch "$mysqld_pid_file_path" else log_failure_msg "MySQL PID file could not be found!" exit 1 fi ;; 服务脚本status选项 首先,判断pid文件长度是否为0,如果不是,则读取该文件中的值,并判断pid对应的进程是否运行正常, 如果运行正常,则输出"MySQL running" 如果不正常,则输出"MySQL is not running, but PID file exists" 如果pid文件的长度为0,则试图通过mysqld的启动命令来获取其pid, 这个时候,可能存在一个mysqld程序启动了多个实例,这会导致pid_count=`echo $mysqld_pid | wc -w`大于1。 这个时候,会输出"Multiple MySQL running but PID file could not be found"信息,并退出脚本。 如果mysqld_pid为空,则会继续判断"$lock_file_path"是否存在,如果存在, 则会输出"MySQL is not running, but lock file ($lock_file_path) exists"信息。 如果"$lock_file_path"不存在,则会输出"MySQL is not running"信息。 如果mysqld_pid等于1,则会输出"MySQL is running but PID file could not be found"信息。 'status') # First, check to see if pid file exists if test -s "$mysqld_pid_file_path" ; then read mysqld_pid < "$mysqld_pid_file_path" if kill -0 $mysqld_pid 2>/ dev/null; then log_success_msg "MySQL running ($mysqld_pid)" exit 0 else log_failure_msg "MySQL is not running, but PID file exists" exit 1 fi else # Try to find appropriate mysqld process mysqld_pid= `pidof $libexecdir/ mysqld` # test if multiple pids exist pid_count= `echo $mysqld_pid | wc-w`if test $pid_count-gt 1; then log_failure_msg "Multiple MySQL running but PID file could not be found ($mysqld_pid)" exit 5 elif test-z $mysqld_pid Then if test-f "$lock_file_path"; then log_failure_msg "MySQL is not running, but lock file ($lock_file_path) exists" exit 2 fi log_failure_msg "MySQL is not running" exit 3 else log_failure_msg "MySQL is running but PID file could not be found" exit 4 fi fi
Service script other options
If the first parameter of the script is not the above options, Usage information is output.
*) # usage basename= `basename "$0" `echo "Usage: $basename {start | stop | restart | reload | force-reload | status} [MySQL server options]" exit 1
At this point, the service script analysis of mysql is complete.
Summary
In the process of starting mysql through a service script, a "The server quit without updating PID file" error is reported, with two conditions
First, the pid file does not exist
Second, check that the process does not exist through kill-0$ pid
At this point, it can only be located through the error log of the mysql database.
If the service script does not make any adjustments, the default basedir is / usr/local/mysql,datadir is / usr/local/mysql/data
If your mysql service is not the default path
You need to explicitly set the
After testing, the following points need to be set up:
1. Set basedir and add conf variables
Where conf refers to the configuration file of mysqld, and it is recommended that the values of basedir and datadir be explicitly specified in the configuration file.
Here, datadir is not set, because datadir can be obtained through a configuration file.
But basedir must be specified, because the my_print_deefauts command must be judged based on basedir first
Basedir=/usr/local/mysql-advanced-5.6.23-linux-glibc2.5-x86_64datadir=conf=/usr/local/mysql-advanced-5.6.23-linux-glibc2.5-x86_64/my_3308.cnf
two。 Line 256, add extra_args= "- c $conf"
Extra_args= "- e $basedir/my.cnf.bak" if test-r "$basedir/my.cnf" then extra_args= "- e $basedir/my.cnf" else if test-r "$datadir/my.cnf" then extra_args= "- e $datadir/my.cnf" fifiextra_args= "- c $conf"
3. Modify the startup parameters of line 285 mysqld_safe
Set
$bindir/mysqld_safe-datadir= "$datadir"-pid-file= "$mysqld_pid_file_path" $other_args > / dev/null 2 > & 1 &
Modify to
Bindir/mysqld_safe-- defaults-file= "$conf"-- datadir= "$datadir"-- pid-file= "$mysqld_pid_file_path" $other_args > / dev/null 2 > & 1 &
Mainly by adding the-- defaults-file option
About the MySQL launch Times "The server quit without updating PID file" error how to solve here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.