diff options
author | Seppo Jaakola <seppo.jaakola@codership.com> | 2013-07-13 13:01:13 +0300 |
---|---|---|
committer | Seppo Jaakola <seppo.jaakola@codership.com> | 2013-07-13 13:01:13 +0300 |
commit | 0a9216835f406947fb4d492616da4cda75e5e113 (patch) | |
tree | 7fbf5059c59fa86ca255452f3ce312aece492652 /scripts | |
parent | 58926b5e1990d3245b55081ba511fbabe2604e17 (diff) | |
download | mariadb-git-0a9216835f406947fb4d492616da4cda75e5e113.tar.gz |
Initial merge result with mariaDB 10: lp:maria
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/CMakeLists.txt | 4 | ||||
-rw-r--r-- | scripts/mysqld_multi.sh | 130 | ||||
-rw-r--r-- | scripts/mysqld_safe.sh | 114 |
3 files changed, 231 insertions, 17 deletions
diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index 76e92899c2a..d11b6fa9bcc 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -313,6 +313,9 @@ IF(WIN32) INSTALL_SCRIPT(${CMAKE_CURRENT_BINARY_DIR}/${file}.pl COMPONENT Server_Scripts) ENDFOREACH() ELSE() + IF(WITH_WSREP) + SET(WSREP_BINARIES wsrep_sst_common wsrep_sst_mysqldump wsrep_sst_rsync wsrep_sst_xtrabackup) + ENDIF() # On Unix, most of the files end up in the bin directory SET(BIN_SCRIPTS msql2mysql @@ -329,6 +332,7 @@ ELSE() mysqldumpslow mysqld_multi mysqld_safe + ${WSREP_BINARIES} ) FOREACH(file ${BIN_SCRIPTS}) IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file}.sh) diff --git a/scripts/mysqld_multi.sh b/scripts/mysqld_multi.sh index cd1b6fc18b7..52135071ac5 100644 --- a/scripts/mysqld_multi.sh +++ b/scripts/mysqld_multi.sh @@ -38,7 +38,7 @@ use Getopt::Long; use POSIX qw(strftime getcwd); $|=1; -$VER="2.16"; +$VER="2.20"; my @defaults_options; # Leading --no-defaults, --defaults-file, etc. @@ -138,6 +138,7 @@ sub main print "will be disabled\nand some will be enabled.\n\n"; } + init_log() if (!defined($opt_log)); $groupids = $ARGV[1]; if ($opt_version) { @@ -163,7 +164,6 @@ sub main !($ARGV[0] =~ m/^stop$/i) && !($ARGV[0] =~ m/^report$/i))); - init_log() if (!defined($opt_log)); if (!$opt_no_log) { w2log("$my_progname log file version $VER; run: ", @@ -206,9 +206,9 @@ sub main } } -# -# Quote word for shell -# +#### +#### Quote word for shell +#### sub quote_shell_word { @@ -218,6 +218,10 @@ sub quote_shell_word return $option; } +#### +#### get options for a group +#### + sub defaults_for_group { my ($group) = @_; @@ -319,8 +323,12 @@ sub report_mysqlds sub start_mysqlds() { - my (@groups, $com, $tmp, $i, @options, $j, $mysqld_found, $info_sent); + my (@groups, $com, $com2, $tmp, $i, @options, $j, $mysqld_found, + $info_sent, $curdir, $mysql_install_db, $srcdir, $basedir, + $datadir); + $mysql_install_db= undef(); + $srcdir= undef(); if (!$opt_no_log) { w2log("\nStarting MySQL servers\n","$opt_log",0,0); @@ -334,8 +342,9 @@ sub start_mysqlds() { @options = defaults_for_group($groups[$i]); - $basedir_found= 0; # The default - $mysqld_found= 1; # The default + my $basedir_found= 0; # The default + my $datadir_found= 0; # The default + my $mysqld_found= 1; # The default $mysqld_found= 0 if (!length($mysqld)); $com= "$mysqld"; for ($j = 0, $tmp= ""; defined($options[$j]); $j++) @@ -350,6 +359,47 @@ sub start_mysqlds() $com= $options[$j]; $mysqld_found= 1; } + elsif ("--mysql-install-db=" eq substr($options[$j], 0, 19)) + { + # mysql_install_db related option + + $options[$j]=~ s/\-\-mysql\-install\-db\=//; + $mysql_install_db= $options[$j]; + } + elsif ("--srcdir=" eq substr($options[$j], 0, 9)) + { + # mysql_install_db related option + + $options[$j]=~ s/\-\-srcdir\=//; + $srcdir= $options[$j]; + } + elsif ("--include-config=" eq substr($options[$j], 0, 17)) + { + $options[$j]=~ s/\-\-include\-config\=//; + $com2= "my_print_defaults --config-file=$options[$j] $groups[$i]"; + + # we need to reorder the array so that options in extra config file + # come in the middle. Needed if someone wants to overwrite an option + + my ($k, @tmp_array); + for ($k= $j + 1; defined($options[$k]); $k++) + { + push (@tmp_array, $options[$k]); + undef($options[$k]); + } + pop(@options); # pop out last null array element + push (@options, `$com2`); + chomp(@options); # new lines away + push (@options, @tmp_array); + } + elsif ("--datadir=" eq substr($options[$j], 0, 10)) + { + $datadir= $options[$j]; + $datadir =~ s/^--datadir=//; + $datadir_found= 1; + $options[$j]= quote_shell_word($options[$j]); + $tmp.= " $options[$j]"; + } elsif ("--basedir=" eq substr($options[$j], 0, 10)) { $basedir= $options[$j]; @@ -373,6 +423,25 @@ sub start_mysqlds() print "wanted mysqld binary.\n\n"; $info_sent= 1; } + if (defined($mysql_install_db)) + { + $com2= "$mysql_install_db"; + $com2.= " --srcdir=$srcdir" if (defined($srcdir)); + $com2.= " --datadir=$datadir" if ($datadir_found); + + if (-d "$datadir/mysql") + { + my $wstr= "WARNING: $datadir/mysql already exists. Not going to\n"; + $wstr.= "run $mysql_install_db on $datadir\n"; + print $wstr if ($opt_verbose); + w2log($wstr, 0, 0); + } + else + { + w2log("Installing databases on $datadir..\n", 0, 0); + `$com2`; + } + } $com.= $tmp; $com.= " >> $opt_log 2>&1" if (!$opt_no_log); $com.= " &"; @@ -442,7 +511,7 @@ sub stop_mysqlds() sub get_mysqladmin_options { my ($i, @groups)= @_; - my ($mysqladmin_found, $com, $tmp, $j); + my ($mysqladmin_found, $com, $com2, $tmp, $j); @options = defaults_for_group($groups[$i]); @@ -465,6 +534,25 @@ sub get_mysqladmin_options $com= $options[$j]; $mysqladmin_found= 1; } + elsif ("--include-config=" eq substr($options[$j], 0, 17)) + { + $options[$j]=~ s/\-\-include\-config\=//; + $com2= "my_print_defaults --config-file=$options[$j] $groups[$i]"; + + # we need to reorder the array so that options in extra config file + # come in the middle. Needed if someone wants to overwrite an option + + my ($k, @tmp_array); + for ($k= $j + 1; defined($options[$k]); $k++) + { + push (@tmp_array, $options[$k]); + undef($options[$k]); + } + pop(@options); # pop out last null array element + push (@options, `$com2`); + chomp(@options); # new lines away + push (@options, @tmp_array); + } elsif ((($options[$j] =~ m/^(\-\-socket\=)(.*)$/) && !$opt_tcp_ip) || ($options[$j] =~ m/^(\-\-port\=)(.*)$/)) { @@ -484,8 +572,11 @@ sub get_mysqladmin_options return $com; } -# Return a list of option files which can be opened. Similar, but not -# identical, to behavior of my_search_option_files() +#### +#### Return a list of option files which can be opened. Similar, but not +#### identical, to behavior of my_search_option_files() +#### + sub list_defaults_files { my %opt; @@ -507,9 +598,11 @@ sub list_defaults_files ($ENV{HOME} ? "$ENV{HOME}/.my.cnf" : undef)); } +#### +#### Takes a specification of GNRs (see --help), and returns a list of matching +#### groups which actually are mentioned in a relevant config file +#### -# Takes a specification of GNRs (see --help), and returns a list of matching -# groups which actually are mentioned in a relevant config file sub find_groups { my ($raw_gids) = @_; @@ -824,6 +917,17 @@ Using: @{[join ' ', @defaults_options]} question. This will be recognised as a special option and will not be passed to the mysqld. This will allow one to start different mysqld versions with mysqld_multi. +--include-config= An optional config file inside a group [mysqld#] which + the program is currently reading. It will read any extra + options of that group from additional file and insert them + where this option was found. Note that the group name + [mysqld#] must be the same in order for options to be found. +--mysql-install-db=... + mysql_install_db script to be used for creating internal + databases. Used when installing datadir for the first time. + This option will be skipped with info in the log file if + 'mysql' database already exists in the given datadir. +--srcdir=... srcdir argument for mysql_install_db script. Optional. --no-log Print to stdout instead of the log file. By default the log file is turned on. --password=... Password for mysqladmin user. diff --git a/scripts/mysqld_safe.sh b/scripts/mysqld_safe.sh index 572a08781c8..7db2a5605e1 100644 --- a/scripts/mysqld_safe.sh +++ b/scripts/mysqld_safe.sh @@ -147,7 +147,7 @@ log_notice () { } eval_log_error () { - cmd="$1" + local cmd="$1" case $logging in file) cmd="$cmd >> "`shell_quote_string "$err_log"`" 2>&1" ;; syslog) @@ -183,6 +183,73 @@ shell_quote_string() { echo "$1" | sed -e 's,\([^a-zA-Z0-9/_.=-]\),\\\1,g' } +wsrep_pick_url() { + [ $# -eq 0 ] && return 0 + + log_error "WSREP: 'wsrep_urls' is DEPRECATED! Use wsrep_cluster_address to specify multiple addresses instead." + + if ! which nc >/dev/null; then + log_error "ERROR: nc tool not found in PATH! Make sure you have it installed." + return 1 + fi + + local url + # Assuming URL in the form scheme://host:port + # If host and port are not NULL, the liveness of URL is assumed to be tested + # If port part is absent, the url is returned literally and unconditionally + # If every URL has port but none is reachable, nothing is returned + for url in `echo $@ | sed s/,/\ /g` 0; do + local host=`echo $url | cut -d \: -f 2 | sed s/^\\\/\\\///` + local port=`echo $url | cut -d \: -f 3` + [ -z "$port" ] && break + nc -z "$host" $port >/dev/null && break + done + + if [ "$url" == "0" ]; then + log_error "ERROR: none of the URLs in '$@' is reachable." + return 1 + fi + + echo $url +} + +# Run mysqld with --wsrep-recover and parse recovered position from log. +# Position will be stored in wsrep_start_position_opt global. +wsrep_start_position_opt="" +wsrep_recover_position() { + local mysqld_cmd="$@" + local wr_logfile=$(mktemp) + local euid=$(id -u) + local ret=0 + + [ "$euid" = "0" ] && chown $user $wr_logfile + chmod 600 $wr_logfile + + log_notice "WSREP: Running position recovery with --log_error=$wr_logfile" + + eval_log_error $mysqld_cmd --log_error=$wr_logfile --wsrep-recover + + local rp="$(grep 'WSREP: Recovered position:' $wr_logfile)" + if [ -z "$rp" ]; then + local skipped="$(grep WSREP $wr_logfile | grep 'skipping position recovery')" + if [ -z "$skipped" ]; then + log_error "WSREP: Failed to recover position: " `cat $wr_logfile`; + ret=1 + else + log_notice "WSREP: Position recovery skipped" + fi + else + local start_pos="$(echo $rp | sed 's/.*WSREP\:\ Recovered\ position://' \ + | sed 's/^[ \t]*//')" + log_notice "WSREP: Recovered position $start_pos" + wsrep_start_position_opt="--wsrep_start_position=$start_pos" + fi + + rm $wr_logfile + + return $ret +} + parse_arguments() { # We only need to pass arguments through to the server if we don't # handle them here. So, we collect unrecognized options (passed on @@ -244,7 +311,13 @@ parse_arguments() { --skip-syslog) want_syslog=0 ;; --syslog-tag=*) syslog_tag="$val" ;; --timezone=*) TZ="$val"; export TZ; ;; - + --wsrep[-_]urls=*) wsrep_urls="$val"; ;; + --wsrep[-_]provider=*) + if test -n "$val" && test "$val" != "none" + then + wsrep_restart=1 + fi + ;; --help) usage ;; *) @@ -788,7 +861,8 @@ do done cmd="$cmd $args" # Avoid 'nohup: ignoring input' warning -test -n "$NOHUP_NICENESS" && cmd="$cmd < /dev/null" +nohup_redir="" +test -n "$NOHUP_NICENESS" && nohup_redir=" < /dev/null" log_notice "Starting $MYSQLD daemon with databases from $DATADIR" @@ -799,13 +873,31 @@ max_fast_restarts=5 # flag whether a usable sleep command exists have_sleep=1 +# maximum number of wsrep restarts +max_wsrep_restarts=0 + +# maximum number of wsrep restarts +max_wsrep_restarts=0 + while true do rm -f "$pid_file" # Some extra safety start_time=`date +%M%S` - eval_log_error "$cmd" + # this sets wsrep_start_position_opt + wsrep_recover_position "$cmd" + + [ $? -ne 0 ] && exit 1 # + + [ -n "$wsrep_urls" ] && url=`wsrep_pick_url $wsrep_urls` # check connect address + + if [ -z "$url" ] + then + eval_log_error "$cmd $wsrep_start_position_opt $nohup_redir" + else + eval_log_error "$cmd $wsrep_start_position_opt --wsrep_cluster_address=$url $nohup_redir" + fi if [ $want_syslog -eq 0 -a ! -f "$err_log" ]; then touch "$err_log" # hypothetical: log was renamed but not @@ -875,6 +967,20 @@ do I=`expr $I + 1` done fi + + if [ -n "$wsrep_restart" ] + then + if [ $wsrep_restart -le $max_wsrep_restarts ] + then + wsrep_restart=`expr $wsrep_restart + 1` + log_notice "WSREP: sleeping 15 seconds before restart" + sleep 15 + else + log_notice "WSREP: not restarting wsrep node automatically" + break + fi + fi + log_notice "mysqld restarted" if test -n "$CRASH_SCRIPT" then |