Vim/etc/init.d/mysqld

Source: Internet
Author: User
Tags stop script

/ETC/INIT.D is a general boot service that is stored in this directory

/ETC/RC.D startup configuration files and scripts

/ETC/INIT.D &/ETC/RC.D/INIT.D is the same directory with the same content
Implementation mechanism, in fact/etc/init.d is a symbolic link file, links to/etc/rc.d/init.d
You can see that by running the following command

[Email protected] ~]# ls-ld/etc/init.d
lrwxrwxrwx. 1 root root-Oct 2 12:15/ETC/INIT.D-RC.D/INIT.D

The method of establishment is:ln-s/etc/rc.d/init.d/etc/init.d

[Email protected]]# vim/etc/init.d/mysqld

1 #!/bin/sh
2 # Copyright abandoned 1996 TCX datakonsult AB & Monty program KB & Detron HB
3 # This file was public domain and comes with NO WARRANTY of any kind
4
5 # MySQL Daemon start/stop script.
6
7 # Usually this was put in/etc/init.d (at least on machines SYSV R4 based
8 # Systems) and linked To/etc/rc3.d/s99mysql And/etc/rc0.d/k01mysql.
9 # When the-is-done the MySQL server would be started
Ten # started and shut down when the systems goes down.
11
# Comments to support Chkconfig on RedHat Linux
# chkconfig:2345 64 36
# description:a very fast and reliable SQL database engine.
15
# Comments to support LSB init script conventions
# # # # BEGIN INIT INFO
# Provides:mysql
# Required-start: $local _fs $network $remote _fs
# should-start:ypbind NSCD LDAP ntpd xntpd
# required-stop: $local _fs $network $remote _fs
# Default-start:2 3 4 5
# default-stop:0 1 6
# Short-description:start and Stop MySQL
# Description:mysql is a very fast and reliable SQL database engine.
# # # # END INIT INFO
27
# If You install MySQL in some other places Than/usr/local/mysql
# of the following things for the.
30 #
#-Run This script from within the MySQL installation directory
#-Create a/etc/my.cnf file with the following information:
# [MYSQLD]
Basedir=<path-to-mysql-installation-directory> #
#-Add the above to any other configuration file (for example ~/.my.ini)
$ # and copy my_print_defaults To/usr/bin
PNS #-Add The path to the mysql-installation-directory to the Basedir variable
# below.
39 #
Want to affect other MySQL variables, you should make your changes
THE/ETC/MY.CNF, ~/.MY.CNF, or other MySQL configuration files.
42
# If You change base dir, you must also the change DataDir. These may get
# Overwritten by settings in the MySQL configuration files.
45
46
47Basedir=/usr/local/mysql
48Datadir=/data/mysql/data
49
# Default value, in seconds, afterwhich the script should timeout waiting
# for server start.
# Value: Overriden by value in MY.CNF.
# 0 means don ' t wait at all
# negative numbers mean to wait indefinitely
service_startup_timeout=900
56
# # Lock directory for Redhat/suse.
Lockdir= '/var/lock/subsys '
Lock_file_path= "$lockdir/mysql"
60
The following variables is only set for letting Mysql.server find things.
62
Defaults # Set Some
Mysqld_pid_file_path=
If Test-z "$basedir"
and then
Basedir=/usr/local/mysql
Bindir=/usr/local/mysql/bin
If Test-z "$datadir"
Then
Datadir=/usr/local/mysql/data
The fi
Sbindir=/usr/local/mysql/bin
Libexecdir=/usr/local/mysql/bin
All else
Bindir= "$basedir/bin"
If Test-z "$datadir"
Then
Datadir= "$basedir/data"
Fi
Bayi sbindir= "$basedir/sbin"
Libexecdir= "$basedir/libexec"
The fi
84
# Datadir_set is used to determine if datadir am set (and so should be
# *not* set inside of the--basedir= handler.)
datadir_set=
88
89 #
# Use LSB init script functions for printing messages, if possible
91 #
Lsb_functions= "/lib/lsb/init-functions"
If Test-f $lsb _functions; Then
94. $LSB _functions
On Else
Log_success_msg ()
97 {
98 echo "success! [Email protected] "
99}
Log_failure_msg ()
101 {
102 echo "error! [Email protected] "
103}
104 fi
105
106 path= "/sbin:/usr/sbin:/bin:/usr/bin: $basedir/bin"
107 Export PATH
108
109 Mode=$1 # Start or stop
110
111 [$#-ge 1] && shift
112
113
Other_args= "$*" # uncommon, but needed if called from an RPM upgrade action
# expected: "--skip-networking--skip-grant-tables"
They is not checked here, intentionally, as it is the resposibility
117 # of the "spec" file author to give correct arguments only.
118
119 case ' echo ' testing\c "', ' echo-n testing ' in
*c*,-n*) echo_n= echo_c=;
121 *c*,*) Echo_n=-n echo_c=;
122 *) echo_n= echo_c= ' \c ';;
123 Esac
124
Parse_server_arguments () {
126 for Arg do
127 case ' $arg ' in
--basedir=*) basedir= ' echo ' $arg | Sed-e ' s/^[^=]*=//'
129 bindir= "$basedir/bin"
If Test-z "$datadir _set"; Then
131 datadir= "$basedir/data"
The fi
133 sbindir= "$basedir/sbin"
134 libexecdir= "$basedir/libexec"
135;;
136--datadir=*) datadir= ' echo ' $arg | Sed-e ' s/^[^=]*=//'
137 Datadir_set=1
138;;
139--pid-file=*) Mysqld_pid_file_path= ' echo ' $arg | Sed-e ' s/^[^=]*=//';;
--service-startup-timeout=*) service_startup_timeout= ' echo ' $arg | Sed-e ' s/^[^=]*=//';;
141 Esac
142 Done
143}
144
145 wait_for_pid () {
146 verb= "$" # Created | Removed
147 pid= "$" # Process ID of the program operating on the Pid-file
148 pid_file_path= "$" # path to the PID file.
149
I=0
151 avoid_race_condition= "by checking again"
152
153 while Test $i-ne $service _startup_timeout; Do
154
155 case ' $verb ' in
156 ' created ')
157 # Wait for a pid-file to pops into existence.
158 test-s "$pid _file_path" && i= "&& break
159;;
' Removed ')
161 # Wait for this pid-file to disappear
162 Test! -S "$pid _file_path" && i= "&& break
163;;
164 *)
165 echo "Wait_for_pid () usage:wait_for_pid created|removed pid Pid_file_path"
166 Exit 1
167;;
168 ESAC
169
# if server isn ' t running, then pid-file'll never be updated
171 if Test-n "$pid"; Then
172 if kill-0 "$pid" 2>/dev/null; Then
173: # The server still runs
174 Else
175 # The server may have exited between, the last Pid-file check, and now.
176 if Test-n "$avoid _race_condition"; Then
177 avoid_race_condition= ""
178 Continue # Check again.
179 fi
180
181 # There's nothing that would affect the file.
182 log_failure_msg "The server quit without updating PID file ($pid _file_path)."
183 return 1 # not waiting any more.
184 fi
185 fi
186
187 echo $echo _n ". $echo _c"
188 i= ' expr $i + 1 '
189 Sleep 1
190
191 done
192
193 if Test-z "$i"; Then
194 log_success_msg
195 return 0
196 Else
197 Log_failure_msg
198 return 1
199 fi
200}
201
202 # Get arguments from the my.cnf file,
203 # The only group, which are read from now on IS [mysqld]
204 if Test-x./bin/my_print_defaults
205 Then
206 print_defaults= "./bin/my_print_defaults"
207 Elif Test-x $bindir/my_print_defaults
208 Then
209 print_defaults= "$bindir/my_print_defaults"
Elif test-x $bindir/mysql_print_defaults
211 Then
212 print_defaults= "$bindir/mysql_print_defaults"
213 Else
214 # Try to find Basedir in/etc/my.cnf
215conf=/etc/my.cnf
216 print_defaults=
217 If Test-r $conf
218 Then
219 subpat= ' ^[^=]*basedir[^=]*=\ (. *\) $ '
dirs= ' sed-e '/$subpat/!d "-e ' s//\1/' $conf '
221 for D in $dirs
222 do
223 d= ' echo $d | Sed-e ' s/[]//g '
224 if Test-x "$d/bin/my_print_defaults"
225 Then
226 print_defaults= "$d/bin/my_print_defaults"
227 Break
228 fi
229 if Test-x "$d/bin/mysql_print_defaults"
Then
231 print_defaults= "$d/bin/mysql_print_defaults"
232 Break
233 fi
234 done
235 fi
236
237 # Hope It's in the PATH ... but I doubt it
238 test-z "$print _defaults" && print_defaults= "My_print_defaults"
239 fi
240
241 #
242 # Read defaults file from ' Basedir '. If There is no defaults file there
243 # Check if it's in the old (depricated) place (DataDir) and read it from there
244 #
245
246 extra_args= ""
247 if Test-r "$basedir/my.cnf"
248 Then
249 extra_args= "-E $basedir/my.cnf"
+ Else
251 if Test-r "$datadir/my.cnf"
252 Then
253 extra_args= "-E $datadir/my.cnf"
254 fi
255 fi
256
257 parse_server_arguments ' $print _defaults $extra _args mysqld server Mysql_server mysql.server '
258
259 #
260 # Set PID file if not given
261 #
262 if test-z "$mysqld _pid_file_path"
263 Then
Mysqld_pid_file_path= $datadir/' hostname '. PID
265 Else
266 case ' $mysqld _pid_file_path ' in
267/*);;
268 *) mysqld_pid_file_path= "$datadir/$mysqld _pid_file_path";;
269 ESAC
The fi
271
272 case ' $mode ' in
273 ' start ')
274 # Start Daemon
275
276 # Safeguard (relative paths, core dumps ...)
277 CD $basedir
278
279 echo $echo _n "Starting MySQL"
280 If Test-x $bindir/mysqld_safe
281 Then
282 # Give extra arguments to mysqld with the my.cnf file. This script
283 # May is overwritten at next upgrade.
284 $bindir/mysqld_safe--datadir= "$datadir"--pid-file= "$mysqld _pid_file_path" $other _args >/dev/null 2>& 1 &
285 Wait_for_pid created "$!" "$mysqld _pid_file_path"; Return_value=$?
286
287 # Make lock for Redhat/suse
288 if test-w "$lockdir"
289 Then
290 Touch "$lock _file_path"
291 fi
292
293 Exit $return _value
294 Else
295 log_failure_msg "couldn ' t find MySQL server ($bindir/mysqld_safe)"
296 fi
297;;
298
299 ' Stop ')
# Stop Daemon. We use a signal here to avoid have to know the
301 # root Password.
302
303 if test-s "$mysqld _pid_file_path"
304 Then
305 mysqld_pid= ' cat ' $mysqld _pid_file_path "'
60S
307 if (kill-0 $mysqld _pid 2>/dev/null)
308 Then
309 echo $echo _n "shutting down MySQL"
310 Kill $mysqld _pid
311 # mysqld should remove the PID file when it exits, so wait for it.
312 Wait_for_pid removed "$mysqld _pid" "$mysqld _pid_file_path"; Return_value=$?
313 Else
314 log_failure_msg "MySQL server process # $mysqld _pid is not running!"
315 RM "$mysqld _pid_file_path"
The fi
317
318 # Delete Lock for Redhat/suse
319 if Test-f "$lock _file_path"
About
321 rm-f "$lock _file_path"
322 fi
323 exit $return _value
324 Else
325 log_failure_msg "MySQL server PID file could not be found!"
326 fi
327;;
328
329 ' restart ')
# Stop the service and regardless of whether it was
331 # Running or not, start it again.
332 If $ stop $other _args; Then
333 $ start $other _args
334 Else
335 log_failure_msg "Failed to stop running server, so refusing to try to start."
336 Exit 1
337 fi
338;;
339
340 ' Reload ' | ' Force-reload ')
341 if test-s "$mysqld _pid_file_path"; Then
342 Read Mysqld_pid < "$mysqld _pid_file_path"
343 kill-hup $mysqld _pid && log_success_msg "reloading service MySQL"
344 Touch "$mysqld _pid_file_path"
345 Else
346 log_failure_msg "MySQL PID file could not be found!"
347 Exit 1
348 fi
349;;
' Status ')
351 # First, check to see if PID file exists
352 if test-s "$mysqld _pid_file_path"; Then
353 Read Mysqld_pid < "$mysqld _pid_file_path"
354 if kill-0 $mysqld _pid 2>/dev/null; Then
355 log_success_msg "MySQL running ($mysqld _pid)"
356 Exit 0
357 Else
358 log_failure_msg "MySQL isn't running, but PID file exists"
359 Exit 1
The fi
361 Else
362 # Try to find appropriate mysqld process
363 mysqld_pid= ' pidof $libexecdir/mysqld '
364
365 # Test if multiple PIDs exist
366 pid_count= ' echo $mysqld _pid | Wc-w '
367 if test $pid _COUNT-GT 1; Then
368 log_failure_msg "multiple MySQL running but PID file could is found ($mysqld _pid)"
369 Exit 5
370 elif test-z $mysqld _pid; Then
371 if Test-f "$lock _file_path"; Then
372 log_failure_msg "MySQL isn't running, but lock file ($lock _file_path) exists"
373 Exit 2
374 fi
375 Log_failure_msg "MySQL is not running"
376 Exit 3
377 Else
378 Log_failure_msg "MySQL is running but PID file could not be found"
379 Exit 4
380 fi
381 fi
382;;
383 *)
384 # Usage
385 basename= ' basename '
386 echo "Usage: $basename {start|stop|restart|reload|force-reload|status} [MySQL server Options]"
387 Exit 1
388;;
389 ESAC
390
391 Exit 0

Vim/etc/init.d/mysqld

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.