64
64
usage () {
65
65
cat << EOF
66
66
Usage: $0 [OPTIONS]
67
+ The following options may be given as the first argument:
67
68
--no-defaults Don't read the system defaults file
68
69
--defaults-file=FILE Use the specified defaults file
69
70
--defaults-extra-file=FILE Also use defaults from the specified file
71
+
72
+ Other options:
70
73
--ledir=DIRECTORY Look for mysqld in the specified directory
71
74
--open-files-limit=LIMIT Limit the number of open files
72
75
--core-file-size=LIMIT Limit core files to the specified size
@@ -205,7 +208,12 @@ parse_arguments() {
205
208
case " $arg " in
206
209
# these get passed explicitly to mysqld
207
210
--basedir=* ) MY_BASEDIR_VERSION=" $val " ;;
208
- --datadir=* ) DATADIR=" $val " ;;
211
+ --datadir=* )
212
+ case $val in
213
+ /) DATADIR=$val ;;
214
+ * ) DATADIR=" ` echo $val | sed ' s;/*$;;' ` " ;;
215
+ esac
216
+ ;;
209
217
--pid-file=* ) pid_file=" $val " ;;
210
218
--plugin-dir=* ) PLUGIN_DIR=" $val " ;;
211
219
--user=* ) user=" $val " ; SET_USER=1 ;;
@@ -387,63 +395,70 @@ set_malloc_lib() {
387
395
add_mysqld_ld_preload " $malloc_lib "
388
396
}
389
397
398
+ find_basedir_from_cmdline () {
399
+ for arg in " $@ " ; do
400
+ case $arg in
401
+ --basedir=* )
402
+ MY_BASEDIR_VERSION=" ` echo " $arg " | sed -e ' s;^--[^=]*=;;' ` "
403
+ # Convert to full path
404
+ cd " $MY_BASEDIR_VERSION "
405
+ if [ $? -ne 0 ] ; then
406
+ log_error " --basedir set to '$MY_BASEDIR_VERSION ', however could not access directory"
407
+ exit 1
408
+ fi
409
+ MY_BASEDIR_VERSION=" ` pwd` "
410
+ ;;
411
+ esac
412
+ done
413
+ }
390
414
391
415
#
392
416
# First, try to find BASEDIR and ledir (where mysqld is)
393
417
#
394
418
395
- if echo ' @pkgdatadir@' | grep ' ^@prefix@' > /dev/null
396
- then
397
- relpkgdata=` echo ' @pkgdatadir@' | sed -e ' s,^@prefix@,,' -e ' s,^/,,' -e ' s,^,./,' `
419
+ oldpwd=" ` pwd` "
420
+
421
+ # Args not parsed yet, check if --basedir was given on command line
422
+ find_basedir_from_cmdline " $@ "
423
+
424
+ # --basedir is already overridden on command line
425
+ if test -n " $MY_BASEDIR_VERSION " -a -d " $MY_BASEDIR_VERSION " ; then
426
+ # Search for mysqld and set ledir
427
+ for dir in @INSTALL_SBINDIR@ libexec sbin bin ; do
428
+ if test -x " $MY_BASEDIR_VERSION /$dir /mysqld" ; then
429
+ ledir=" $MY_BASEDIR_VERSION /$dir "
430
+ break
431
+ fi
432
+ done
433
+
398
434
else
399
- # pkgdatadir is not relative to prefix
400
- relpkgdata=' @pkgdatadir@'
401
- fi
435
+ # Basedir should be parent dir of bindir, unless some non-standard
436
+ # layout is used
402
437
403
- case " $0 " in
404
- /* )
405
- MY_PWD=' @prefix@'
406
- ;;
407
- * )
408
- MY_PWD=` dirname $0 `
409
- MY_PWD=` dirname $MY_PWD `
410
- ;;
411
- esac
412
- # Check for the directories we would expect from a binary release install
413
- if test -n " $MY_BASEDIR_VERSION " -a -d " $MY_BASEDIR_VERSION "
414
- then
415
- # BASEDIR is already overridden on command line. Do not re-set.
438
+ cd " ` dirname $0 ` "
439
+ if [ -h " $0 " ] ; then
440
+ realpath=" ` ls -l " $0 " | awk ' {print $NF}' ` "
441
+ cd " ` dirname " $realpath " ` "
442
+ fi
443
+ cd ..
444
+ MY_PWD=" ` pwd` "
445
+
446
+ # Search for mysqld and set ledir and BASEDIR
447
+ for dir in @INSTALL_SBINDIR@ libexec sbin bin ; do
448
+ if test -x " $MY_PWD /$dir /mysqld" ; then
449
+ MY_BASEDIR_VERSION=" $MY_PWD "
450
+ ledir=" $MY_BASEDIR_VERSION /$dir "
451
+ break
452
+ fi
453
+ done
416
454
417
- # Use BASEDIR to discover le.
418
- if test -x " $MY_BASEDIR_VERSION /libexec/mysqld"
419
- then
420
- ledir=" $MY_BASEDIR_VERSION /libexec"
421
- elif test -x " $MY_BASEDIR_VERSION /sbin/mysqld"
422
- then
423
- ledir=" $MY_BASEDIR_VERSION /sbin"
424
- else
425
- ledir=" $MY_BASEDIR_VERSION /bin"
455
+ # If we still didn't find anything, use the compiled-in defaults
456
+ if test -z " $MY_BASEDIR_VERSION " ; then
457
+ MY_BASEDIR_VERSION=' @prefix@'
458
+ ledir=' @libexecdir@'
426
459
fi
427
- elif test -f " $relpkgdata " /english/errmsg.sys -a -x " $MY_PWD /bin/mysqld"
428
- then
429
- MY_BASEDIR_VERSION=" $MY_PWD " # Where bin, share and data are
430
- ledir=" $MY_PWD /bin" # Where mysqld is
431
- # Check for the directories we would expect from a source install
432
- elif test -f " $relpkgdata " /english/errmsg.sys -a -x " $MY_PWD /libexec/mysqld"
433
- then
434
- MY_BASEDIR_VERSION=" $MY_PWD " # Where libexec, share and var are
435
- ledir=" $MY_PWD /libexec" # Where mysqld is
436
- elif test -f " $relpkgdata " /english/errmsg.sys -a -x " $MY_PWD /sbin/mysqld"
437
- then
438
- MY_BASEDIR_VERSION=" $MY_PWD " # Where sbin, share and var are
439
- ledir=" $MY_PWD /sbin" # Where mysqld is
440
- # Since we didn't find anything, used the compiled-in defaults
441
- else
442
- MY_BASEDIR_VERSION=' @prefix@'
443
- ledir=' @libexecdir@'
444
460
fi
445
461
446
-
447
462
#
448
463
# Second, try to find the data directory
449
464
#
@@ -456,10 +471,6 @@ then
456
471
then
457
472
defaults=" --defaults-extra-file=$DATADIR /my.cnf"
458
473
fi
459
- # Next try where the source installs put it
460
- elif test -d $MY_BASEDIR_VERSION /var/mysql
461
- then
462
- DATADIR=$MY_BASEDIR_VERSION /var
463
474
# Or just give up and use our compiled-in default
464
475
else
465
476
DATADIR=@localstatedir@
@@ -490,21 +501,10 @@ export MYSQL_HOME
490
501
491
502
# Get first arguments from the my.cnf file, groups [mysqld] and [mysqld_safe]
492
503
# and then merge with the command line arguments
493
- if test -x " $MY_BASEDIR_VERSION /bin/my_print_defaults"
494
- then
504
+ if test -x " $MY_BASEDIR_VERSION /bin/my_print_defaults" ; then
495
505
print_defaults=" $MY_BASEDIR_VERSION /bin/my_print_defaults"
496
- elif test -x ` dirname $0 ` /my_print_defaults
497
- then
498
- print_defaults=" ` dirname $0 ` /my_print_defaults"
499
- elif test -x ./bin/my_print_defaults
500
- then
501
- print_defaults=" ./bin/my_print_defaults"
502
- elif test -x @bindir@/my_print_defaults
503
- then
506
+ elif test -x " @bindir@/my_print_defaults" ; then
504
507
print_defaults=" @bindir@/my_print_defaults"
505
- elif test -x @bindir@/mysql_print_defaults
506
- then
507
- print_defaults=" @bindir@/mysql_print_defaults"
508
508
else
509
509
print_defaults=" my_print_defaults"
510
510
fi
@@ -515,6 +515,8 @@ append_arg_to_args () {
515
515
516
516
args=
517
517
518
+ cd " $oldpwd "
519
+
518
520
SET_USER=2
519
521
parse_arguments ` $print_defaults $defaults --loose-verbose mysqld server`
520
522
if test $SET_USER -eq 2
613
615
logdir=` dirname " $err_log " `
614
616
# Change the err log to the right user, if possible and it is in use
615
617
if [ $logging = " file" -o $logging = " both" ]; then
616
- if [ ! -f " $err_log " -a ! -h " $err_log " ]; then
618
+ if [ ! -e " $err_log " -a ! -h " $err_log " ]; then
617
619
if test -w / -o " $USER " = " root" ; then
618
620
case $logdir in
619
621
/var/log)
@@ -633,7 +635,7 @@ if [ $logging = "file" -o $logging = "both" ]; then
633
635
fi
634
636
fi
635
637
636
- if [ -f " $err_log " ]; then # Log to err_log file
638
+ if [ -f " $err_log " -o -p " $err_log " ]; then # Log to err_log file
637
639
log_notice " Logging to '$err_log '."
638
640
elif [ " x$user " = " xroot" ]; then # running as root, mysqld can create log file; continue
639
641
echo " Logging to '$err_log '." >&2
0 commit comments