24
24
# Short-Description: start and stop MySQL
25
25
# Description: MySQL is a very fast and reliable SQL database engine.
26
26
# ## END INIT INFO
27
-
28
- # If you install MySQL on some other places than /usr/local/mysql-5.0.33 , then you
27
+
28
+ # If you install MySQL on some other places than /usr/local/mysql-5.1.59 , then you
29
29
# have to do one of the following things for this script to work:
30
30
#
31
31
# - Run this script from within the MySQL installation directory
43
43
# If you change base dir, you must also change datadir. These may get
44
44
# overwritten by settings in the MySQL configuration files.
45
45
46
- basedir=
47
- datadir=
46
+ basedir=/usr/local/mysql
47
+ datadir=/usr/local/var/mysql
48
+
49
+ # Default value, in seconds, afterwhich the script should timeout waiting
50
+ # for server start.
51
+ # Value here is overriden by value in my.cnf.
52
+ # 0 means don't wait at all
53
+ # Negative numbers mean to wait indefinitely
54
+ service_startup_timeout=900
48
55
49
56
# The following variables are only set for letting mysql.server find things.
50
57
@@ -55,14 +62,14 @@ use_mysqld_safe=1
55
62
user=mysql
56
63
if test -z " $basedir "
57
64
then
58
- basedir=/usr/local/mysql
59
- bindir=/usr/local/mysql/bin
65
+ basedir=/usr/local/mysql-5.1.59
66
+ bindir=/usr/local/mysql-5.1.59 /bin
60
67
if test -z " $datadir "
61
68
then
62
- datadir=/usr/local/var/ mysql
69
+ datadir=/usr/local/mysql-5.1.59/var
63
70
fi
64
- sbindir=/usr/local/mysql/sbin
65
- libexecdir=/usr/local/mysql/libexec
71
+ sbindir=/usr/local/mysql-5.1.59 /sbin
72
+ libexecdir=/usr/local/mysql-5.1.59 /libexec
66
73
else
67
74
bindir=" $basedir /bin"
68
75
if test -z " $datadir "
@@ -115,17 +122,18 @@ parse_server_arguments() {
115
122
case " $arg " in
116
123
--basedir=* ) basedir=` echo " $arg " | sed -e ' s/^[^=]*=//' `
117
124
bindir=" $basedir /bin"
118
- if test -z " $datadir_set " ; then
119
- datadir=" $basedir /data"
120
- fi
121
- sbindir=" $basedir /sbin"
122
- libexecdir=" $basedir /libexec"
125
+ if test -z " $datadir_set " ; then
126
+ datadir=" $basedir /data"
127
+ fi
128
+ sbindir=" $basedir /sbin"
129
+ libexecdir=" $basedir /libexec"
123
130
;;
124
131
--datadir=* ) datadir=` echo " $arg " | sed -e ' s/^[^=]*=//' `
125
- datadir_set=1
126
- ;;
132
+ datadir_set=1
133
+ ;;
127
134
--user=* ) user=` echo " $arg " | sed -e ' s/^[^=]*=//' ` ;;
128
135
--pid-file=* ) server_pid_file=` echo " $arg " | sed -e ' s/^[^=]*=//' ` ;;
136
+ --service-startup-timeout=* ) service_startup_timeout=` echo " $arg " | sed -e ' s/^[^=]*=//' ` ;;
129
137
--use-mysqld_safe) use_mysqld_safe=1;;
130
138
--use-manager) use_mysqld_safe=0;;
131
139
esac
@@ -142,29 +150,55 @@ parse_manager_arguments() {
142
150
}
143
151
144
152
wait_for_pid () {
153
+ verb=" $1 "
154
+ manager_pid=" $2 " # process ID of the program operating on the pid-file
145
155
i=0
146
- while test $i -lt 35 ; do
147
- sleep 1
148
- case " $1 " in
156
+ avoid_race_condition=" by checking again"
157
+ while test $i -ne $service_startup_timeout ; do
158
+
159
+ case " $verb " in
149
160
' created' )
161
+ # wait for a PID-file to pop into existence.
150
162
test -s $pid_file && i=' ' && break
151
163
;;
152
164
' removed' )
165
+ # wait for this PID-file to disappear
153
166
test ! -s $pid_file && i=' ' && break
154
167
;;
155
168
* )
156
- echo " wait_for_pid () usage: wait_for_pid created|removed"
169
+ echo " wait_for_pid () usage: wait_for_pid created|removed manager_pid "
157
170
exit 1
158
171
;;
159
172
esac
173
+
174
+ # if manager isn't running, then pid-file will never be updated
175
+ if test -n " $manager_pid " ; then
176
+ if kill -0 " $manager_pid " 2> /dev/null; then
177
+ : # the manager still runs
178
+ else
179
+ # The manager may have exited between the last pid-file check and now.
180
+ if test -n " $avoid_race_condition " ; then
181
+ avoid_race_condition=" "
182
+ continue # Check again.
183
+ fi
184
+
185
+ # there's nothing that will affect the file.
186
+ log_failure_msg " Manager of pid-file quit without updating file."
187
+ return 1 # not waiting any more.
188
+ fi
189
+ fi
190
+
160
191
echo $echo_n " .$echo_c "
161
192
i=` expr $i + 1`
193
+ sleep 1
162
194
done
163
195
164
196
if test -z " $i " ; then
165
197
log_success_msg
198
+ return 0
166
199
else
167
200
log_failure_msg
201
+ return 1
168
202
fi
169
203
}
170
204
189
223
dirs=` sed -e " /$subpat /!d" -e ' s//\1/' $conf `
190
224
for d in $dirs
191
225
do
192
- d=` echo $d | sed -e ' s/[ ]//g' `
226
+ d=` echo $d | sed -e ' s/[ ]//g' `
193
227
if test -x " $d /bin/my_print_defaults"
194
228
then
195
229
print_defaults=" $d /bin/my_print_defaults"
224
258
fi
225
259
226
260
parse_server_arguments ` $print_defaults $extra_args mysqld server mysql_server mysql.server`
227
-
228
- # Look for the pidfile
261
+ # Look for the pidfile
229
262
parse_manager_arguments ` $print_defaults $extra_args manager`
230
263
231
264
#
@@ -250,12 +283,11 @@ else
250
283
esac
251
284
fi
252
285
253
- # Safeguard (relative paths, core dumps..)
254
- cd $basedir
255
-
256
286
case " $mode " in
257
287
' start' )
258
288
# Start daemon
289
+ # Safeguard (relative paths, core dumps..)
290
+ cd $basedir
259
291
260
292
manager=$bindir /mysqlmanager
261
293
if test -x $libexecdir /mysqlmanager
@@ -276,29 +308,35 @@ case "$mode" in
276
308
fi
277
309
# Give extra arguments to mysqld with the my.cnf file. This script may
278
310
# be overwritten at next upgrade.
279
- $manager --user=$user --pid-file=$pid_file > /dev/null 2>&1 &
280
- wait_for_pid created
311
+ " $manager " \
312
+ --mysqld-safe-compatible \
313
+ --user=" $user " \
314
+ --pid-file=" $pid_file " > /dev/null 2>&1 &
315
+ wait_for_pid created $! ; return_value=$?
281
316
282
317
# Make lock for RedHat / SuSE
283
318
if test -w /var/lock/subsys
284
319
then
285
320
touch /var/lock/subsys/mysqlmanager
286
321
fi
322
+ exit $return_value
287
323
elif test -x $bindir /mysqld_safe
288
324
then
289
325
# Give extra arguments to mysqld with the my.cnf file. This script
290
326
# may be overwritten at next upgrade.
291
327
pid_file=$server_pid_file
292
- $bindir /mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args > /dev/null 2>&1 &
293
- wait_for_pid created
328
+ $bindir /mysqld_safe --datadir=$datadir --pid-file=$server_pid_file \
329
+ --language=/usr/local/mysql/share/mysql/english $other_args > /dev/null 2>&1 &
330
+ wait_for_pid created $! ; return_value=$?
294
331
295
332
# Make lock for RedHat / SuSE
296
333
if test -w /var/lock/subsys
297
334
then
298
335
touch /var/lock/subsys/mysql
299
336
fi
337
+ exit $return_value
300
338
else
301
- log_failure_msg " Couldn't find MySQL manager or server"
339
+ log_failure_msg " Couldn't find MySQL manager ( $manager ) or server ( $bindir /mysqld_safe) "
302
340
fi
303
341
;;
304
342
@@ -319,16 +357,24 @@ case "$mode" in
319
357
if test -s " $pid_file "
320
358
then
321
359
mysqlmanager_pid=` cat $pid_file `
322
- echo $echo_n " Shutting down MySQL"
323
- kill $mysqlmanager_pid
324
- # mysqlmanager should remove the pid_file when it exits, so wait for it.
325
- wait_for_pid removed
326
-
360
+
361
+ if (kill -0 $mysqlmanager_pid 2> /dev/null)
362
+ then
363
+ echo $echo_n " Shutting down MySQL"
364
+ kill $mysqlmanager_pid
365
+ # mysqlmanager should remove the pid_file when it exits, so wait for it.
366
+ wait_for_pid removed " $mysqlmanager_pid " ; return_value=$?
367
+ else
368
+ log_failure_msg " MySQL manager or server process #$mysqlmanager_pid is not running!"
369
+ rm $pid_file
370
+ fi
371
+
327
372
# delete lock for RedHat / SuSE
328
373
if test -f $lock_dir
329
374
then
330
375
rm -f $lock_dir
331
376
fi
377
+ exit $return_value
332
378
else
333
379
log_failure_msg " MySQL manager or server PID file could not be found!"
334
380
fi
@@ -337,23 +383,61 @@ case "$mode" in
337
383
' restart' )
338
384
# Stop the service and regardless of whether it was
339
385
# running or not, start it again.
340
- $0 stop $other_args
341
- $0 start $other_args
386
+ if $0 stop $other_args ; then
387
+ $0 start $other_args
388
+ else
389
+ log_failure_msg " Failed to stop running server, so refusing to try to start."
390
+ exit 1
391
+ fi
342
392
;;
343
393
344
- ' reload' )
394
+ ' reload' | ' force-reload ' )
345
395
if test -s " $server_pid_file " ; then
346
- mysqld_pid= ` cat $server_pid_file `
396
+ read mysqld_pid < $server_pid_file
347
397
kill -HUP $mysqld_pid && log_success_msg " Reloading service MySQL"
348
398
touch $server_pid_file
349
399
else
350
400
log_failure_msg " MySQL PID file could not be found!"
401
+ exit 1
351
402
fi
352
403
;;
353
-
354
- * )
355
- # usage
356
- echo " Usage: $0 {start|stop|restart|reload} [ MySQL server options ]"
357
- exit 1
404
+ ' status' )
405
+ # First, check to see if pid file exists
406
+ if test -s " $server_pid_file " ; then
407
+ read mysqld_pid < $server_pid_file
408
+ if kill -0 $mysqld_pid 2> /dev/null ; then
409
+ log_success_msg " MySQL running ($mysqld_pid )"
410
+ exit 0
411
+ else
412
+ log_failure_msg " MySQL is not running, but PID file exists"
413
+ exit 1
414
+ fi
415
+ else
416
+ # Try to find appropriate mysqld process
417
+ mysqld_pid=` pidof $libexecdir /mysqld`
418
+ if test -z $mysqld_pid ; then
419
+ if test " $use_mysqld_safe " = " 0" ; then
420
+ lockfile=/var/lock/subsys/mysqlmanager
421
+ else
422
+ lockfile=/var/lock/subsys/mysql
423
+ fi
424
+ if test -f $lockfile ; then
425
+ log_failure_msg " MySQL is not running, but lock exists"
426
+ exit 2
427
+ fi
428
+ log_failure_msg " MySQL is not running"
429
+ exit 3
430
+ else
431
+ log_failure_msg " MySQL is running but PID file could not be found"
432
+ exit 4
433
+ fi
434
+ fi
435
+ ;;
436
+ * )
437
+ # usage
438
+ echo " Usage: $0 {start|stop|restart|reload|force-reload|status} [ MySQL server options ]"
439
+ exit 1
358
440
;;
359
441
esac
442
+
443
+ exit 0
0 commit comments