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/mysqld_safe.sh | |
parent | 58926b5e1990d3245b55081ba511fbabe2604e17 (diff) | |
download | mariadb-git-0a9216835f406947fb4d492616da4cda75e5e113.tar.gz |
Initial merge result with mariaDB 10: lp:maria
Diffstat (limited to 'scripts/mysqld_safe.sh')
-rw-r--r-- | scripts/mysqld_safe.sh | 114 |
1 files changed, 110 insertions, 4 deletions
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 |