]> git.pld-linux.org Git - packages/mysql.git/blobdiff - mysql.init
- merge initscript improvements from HEAD
[packages/mysql.git] / mysql.init
index 7d89e4e37bb6ff7ccf363661b940a5f72bd19e73..9d3354cf20eb5ce5bbe7acf19fca1de581ba157b 100644 (file)
@@ -26,7 +26,7 @@ if [ -n "$MYSQL_DB_CLUSTERS" ]; then
 fi
 
 if [ -f /etc/mysql/clusters.conf ]; then
-       MYSQL_DB_CLUSTERS=$(grep -v '^#' /etc/mysql/clusters.conf | cut -s -f 2 -d '=')
+       MYSQL_DB_CLUSTERS=$(awk -F= '!/^#/{print $2}' /etc/mysql/clusters.conf)
        if [ -z "$MYSQL_DB_CLUSTERS"  ]; then
                nls "Warning: there are no configured clusters."
        fi
@@ -57,12 +57,29 @@ action="$1"
 if [ $# -gt 1 ]; then
        shift
        # perform action for specified clusters only
-       DB_CLUSTERS="$@"
+       for a in "$@"; do
+               # try auto resolving from /etc/mysql/clusters.conf
+               if [[ "$a" != /* ]]; then
+                       m=$(awk -va="$a" -F= 'substr($0, 1, length(a)) == a {print $1}' /etc/mysql/clusters.conf)
+                       if [ -z "$m" ]; then
+                               echo >&2 "Cluster name '$a' did not match anything!"
+                               exit 1
+                       fi
+                       if [ $(echo "$m" | wc -l) -gt 1 ]; then
+                               echo >&2 "Cluster name '$a' ambiguous:" $m
+                               exit 1
+                       fi
+                       a=$(awk -va="$a" -F= 'substr($0, 1, length(a)) == a {print $2}' /etc/mysql/clusters.conf)
+               fi
+               DB_CLUSTERS="$DB_CLUSTERS $a"
+       done
 else
        DB_CLUSTERS="$MYSQL_DB_CLUSTERS"
 fi
 
 MYSQL_ERRLOG=/var/log/mysql/err
+MYSQL_START_WAIT_TIME=${MYSQL_START_WAIT_TIME:-15}
+MYSQL_STOP_WAIT_TIME=${MYSQL_STOP_WAIT_TIME:-900}
 
 #
 # Useful functions.
@@ -73,25 +90,59 @@ MYSQL_ERRLOG=/var/log/mysql/err
 #
 # arguments:
 # $1 - db cluster
+# $2 - start|stop
 #
 # sets variables:
-# MYSQL_STATUS = running | not running | died
+# MYSQL_STATUS = starting | running | not running | died
 # MYSQL_PID    = pid of mysqld process
 #
 mysqlstatus() {
        clusterdir="$1"
-       mysqlgetconfig "$clusterdir"
+       mode="$2"
        
+       mysqlgetconfig "$clusterdir"
+
        MYSQL_STATUS="not running"
        MYSQL_PID="unknown"
+       MYSQL_PIDFILE_PID=""
+       MYSQL_GREP_PID=""
 
-       [ -f "$MYSQL_PIDFILE" ] && MYSQL_PID=$(cat "$MYSQL_PIDFILE")
+       if [ -f "$MYSQL_PIDFILE" ]; then
+               MYSQL_PIDFILE_PID=$(cat "$MYSQL_PIDFILE")
+       fi
+       
+       if [ -n "$MYSQL_PIDFILE_PID" ]; then
+               MYSQL_PID=$MYSQL_PIDFILE_PID
+               if [ ! -d "/proc/$MYSQL_PID" ]; then
+                       MYSQL_STATUS="died"
+                       return
+               elif (grep -qa "$MYSQL_PIDFILE" /proc/$MYSQL_PID/cmdline 2> /dev/null); then
+                       MYSQL_STATUS="running"
+                       return
+               fi
+       fi
 
-       if [ ! -d "/proc/$MYSQL_PID" -a "$MYSQL_PID" != "unknown" ]; then
-               MYSQL_STATUS="died"
-       elif [ -d "/proc/$MYSQL_PID" ]; then
-               grep -qa "$MYSQL_PIDFILE" /proc/$MYSQL_PID/cmdline && MYSQL_STATUS="running" || MYSQL_STATUS="not running"
+       if [ "$mode" = "start" ]; then
+               MYSQL_GREP_PID=$(grep -lE "^/usr/sbin/mysqld.*${MYSQL_PIDFILE}" /proc/[0-9]*/cmdline 2> /dev/null | awk -F "/" '{ print $3; exit; }')
+               if [ -n "$MYSQL_GREP_PID" ]; then
+                       MYSQL_PID=$MYSQL_GREP_PID
+                       if (grep -qa "$MYSQL_PIDFILE" /proc/$MYSQL_PID/cmdline 2> /dev/null); then
+                               if [ -f "$MYSQL_PIDFILE" ]; then
+                                       MYSQL_PIDFILE_PID=$(cat "$MYSQL_PIDFILE")
+                               fi
+                               if [ -n "$MYSQL_PIDFILE_PID" ]; then
+                                       MYSQL_PID=$MYSQL_PIDFILE_PID
+                                       MYSQL_STATUS="running"
+                                       return
+                               else
+                                       MYSQL_STATUS="starting"
+                                       return
+                               fi
+                       fi
+               fi
        fi
+
+       # else default, "not running"
 }
 
 # get mysql configuration in variables
@@ -105,29 +156,28 @@ mysqlgetconfig() {
 
        # emulate old behaviour if only one cluster specified
        if [ "$clusterdir" = "$MYSQL_DB_CLUSTERS" -a "$clusterdir" = "/var/lib/mysql" -a -f /etc/mysqld.conf ]; then
-               MYSQL_RA_COMPAT=yes; export MYSQL_RA_COMPAT
+               MYSQL_RA_COMPAT=yes
                config_file=/etc/mysqld.conf
        else
-               # TODO: convert this piece of crap to awk
-               config=`grep -v "^#" /etc/mysql/clusters.conf | grep "${clusterdir}$" | cut -s -f 1 -d '='`
-               if echo "$config" | grep -q '^/'; then
+               config=$(awk -F= -vclusterdir="$clusterdir" '!/^#/{ if (clusterdir == $2) print $1}' /etc/mysql/clusters.conf)
+               if [[ $config = /* ]]; then
                        config_file="$config"
                elif [ -f "/etc/mysql/$config" ]; then
-                       config_file=/etc/mysql/$config
+                       config_file="/etc/mysql/$config"
                else
                        config_file="$clusterdir/mysqld.conf"
                fi
        fi
 
-       MYSQL_CLUSTER_DIR="$clusterdir"; export MYSQL_CLUSTER_DIR
-       
+       MYSQL_CLUSTER_DIR="$clusterdir"
+
        if [ -z "$config_file" ]; then
                nls "Error: Can't find config file for %s cluster" "$clusterdir"
                exit 6
        else
-               MYSQL_CONFIG="$config_file"; export MYSQL_CONFIG
+               MYSQL_CONFIG="$config_file"
        fi
-       
+
        if [ ! -f "$config_file" ]; then
                nls "Error: config file %s not found" "$config_file"
                nls "MySQL can't be run. Did you initialize DB by doing \`$0 init'?"
@@ -137,22 +187,19 @@ mysqlgetconfig() {
        eval `awk '
 /^[ \t]*\[.*\][ \t]*$/ {
        match($0,/\[.*\]/)
-       section=substr($0,RSTART+1,RSTART+RLENGTH-3)
+       section=substr($0, RSTART + 1, RSTART + RLENGTH - 3)
 }
-section=="mysqld" && $2~"=" {
-       if ($1=="datadir") {
+section == "mysqld" && $2 ~ "=" {
+       if ($1 == "datadir") {
                printf("MYSQL_DATA_DIR=%s;", $3)
-       } else if ($1=="user") {
+       } else if ($1 == "user") {
                printf("MYSQL_USER=%s;", $3)
-       } else if ($1=="pid-file") {
+       } else if ($1 == "pid-file") {
                printf("MYSQL_PIDFILE=%s;", $3)
-       } else if ($1=="socket") {
+       } else if ($1 == "socket") {
                printf("MYSQL_SOCKET=%s;", $3)
        }
 }
-END {
-       print "export MYSQL_DATA_DIR MYSQL_USER MYSQL_PIDFILE MYSQL_SOCKET"
-}
 ' $config_file`
 
 
@@ -161,13 +208,13 @@ END {
        else
                MYSQL_DATA_DIR_SUB="/mysqldb"
        fi
-               
+
        if [ -z "$MYSQL_DATA_DIR" -o "$MYSQL_DATA_DIR" != "${clusterdir}${MYSQL_DATA_DIR_SUB}/db" ]; then
                nls "Error: datadir specified in %s should be %s" "$config_file" "$clusterdir${MYSQL_DATA_DIR_SUB}/db"
                nls " MySQL can't be run."
                exit 6
        fi
-       
+
        if [ -z "$MYSQL_PIDFILE" -o "$MYSQL_PIDFILE" != "$clusterdir${MYSQL_DATA_DIR_SUB}/mysql.pid" ]; then
                nls "Error: pid-file specified in %s should be %s" "$config_file" "$clusterdir${MYSQL_DATA_DIR_SUB}/mysql.pid"
                nls " MySQL can't be run."
@@ -194,9 +241,19 @@ mysqlstart() {
        msg_starting "MySQL $clusterdir"
        busy
        [ -z "$DEFAULT_SERVICE_RUN_NICE_LEVEL" ] && DEFAULT_SERVICE_RUN_NICE_LEVEL=0
-       TMPDIR=/tmp nice -n ${SERVICE_RUN_NICE_LEVEL:-$DEFAULT_SERVICE_RUN_NICE_LEVEL} /usr/bin/setsid /usr/sbin/mysqld --defaults-file=$MYSQL_CONFIG --datadir=$MYSQL_DATA_DIR --pid-file=$MYSQL_PIDFILE >> $MYSQL_ERRLOG 2>&1 &
-       sleep 2
-       mysqlstatus "$clusterdir"
+       rm -f "$MYSQL_PIDFILE"
+       TMPDIR=/tmp nice -n ${SERVICE_RUN_NICE_LEVEL:-$DEFAULT_SERVICE_RUN_NICE_LEVEL} /usr/bin/setsid /usr/sbin/mysqld --defaults-file=$MYSQL_CONFIG --datadir=$MYSQL_DATA_DIR --pid-file=$MYSQL_PIDFILE $MYSQL_OPTIONS >> $MYSQL_ERRLOG 2>&1 &
+       sleep 0.2
+       mysqlstatus "$clusterdir" start
+       # it takes longer for mysqld to start and create pidfile if it has to recover innodb transactions
+       if [ "$MYSQL_STATUS" = "starting" ]; then
+               for nr in $(seq 1 $(($MYSQL_START_WAIT_TIME*10))); do
+                       [ -f "$MYSQL_PIDFILE" ] && break
+                       sleep 0.1
+               done
+       fi
+
+       mysqlstatus "$clusterdir" start
        if [ "$MYSQL_STATUS" = "running" -a "$MYSQL_PID" != "unknown" ]; then
                ok
        elif [ "$MYSQL_STATUS" = "died" ]; then
@@ -211,35 +268,31 @@ mysqlstart() {
 # stop mysql
 mysqlstop() {
        clusterdir="$1"
-       mysqlstatus "$clusterdir"
+       mysqlstatus "$clusterdir" stop
        msg_stopping "MySQL $clusterdir"
        busy
 
-# TODO
-#  graceful mysql shutdown with mysqladmin shutdown requires 'shutdown'
-#  privilege. create new user mysqlctl or rename mysql_logrotate to mysqlctl
-#  and give it both privs (flush-logs and shutdown)?
-
        # try graceful shutdown -- send shutdown command
-       /usr/bin/mysqladmin --defaults-file=$MYSQL_CONFIG ${MYSQL_SOCKET:+--socket=$MYSQL_SOCKET} shutdown 2>/dev/null
-       mysqlstatus "$clusterdir"
-
-       [ "$MYSQL_PID" != "unknown" ] && kill -TERM "$MYSQL_PID" 2> /dev/null
-       # 3 seconds
-       for nr in 1 2 3; do
-               [ -d "/proc/$MYSQL_PID" ] && sleep 1
-       done
-       mysqlstatus "$clusterdir"
+       # requires mysql_logrotate user proper privs
+       /usr/bin/mysqladmin --defaults-file=$MYSQL_CONFIG ${MYSQL_SOCKET:+--socket=$MYSQL_SOCKET} shutdown >/dev/null 2>&1
+       mysqlstatus "$clusterdir" stop
+
+       if [ "$MYSQL_PID" != "unknown" ]; then
+               kill -TERM "$MYSQL_PID" 2> /dev/null
+               for nr in $(seq 1 $(($MYSQL_STOP_WAIT_TIME*10))); do
+                       [ -d "/proc/$MYSQL_PID" ] || break
+                       sleep 0.1
+               done
+       fi
+       
+       mysqlstatus "$clusterdir" stop
        if [ "$MYSQL_STATUS" = "died" ]; then
                died
-       elif [ "$MYSQL_STATUS" = "running" ]; then
+       elif [ "$MYSQL_STATUS" = "running" -o "$MYSQL_STATUS" = "starting" ]; then
                fail
        else
                ok
        fi
-
-       # FIXME: should let mysqld remove pid by itself?
-       rm -f "$MYSQL_PIDFILE"
 }
 
 #
@@ -275,6 +328,9 @@ mysqlinit() {
                MYSQL_DATA_DIR="$clusterdir/mysqldb/db"
                MYSQL_PIDFILE="$clusterdir/mysqldb/mysql.pid"
                MYSQL_SOCKET="$clusterdir/mysqldb/mysql.sock"
+
+               # this $MYSQL_CONFIG will be created later
+               MYSQL_CONFIG="$MYSQL_CLUSTER_DIR/mysqld.conf"
        fi
 
        nls "Initializing cluster %s" "$clusterdir"
@@ -289,13 +345,12 @@ mysqlinit() {
 
        show "Creating privilege mysql tables for $MYSQL_DATA_DIR"
        busy
-       TMP=/tmp TMPDIR=/tmp 
+       TMP=/tmp TMPDIR=/tmp
 
-               
        # Install this in the user table, too
        hostname="`hostname --fqdn 2> /dev/null | tr -d '[:space:]'`"
        [ -z "$hostname" ] && hostname="localhost-unknown"
-               
+
        # Check if hostname is valid
        if [ -z "$hostname" ]; then
                deltext
@@ -303,7 +358,7 @@ mysqlinit() {
                nls "Sorry, the host name is not configured."
                nls "Please configure the 'hostname' command to return a hostname."
                exit 1
-       elif ! hostname -i >/dev/null 2>&1; then 
+       elif ! hostname -i >/dev/null 2>&1; then
                deltext
                fail
                nls "Sorry, the host '%s' could not be looked up." "$hostname"
@@ -312,11 +367,11 @@ mysqlinit() {
        fi
 
        # Initialize variables
-       c_d="" i_d=""
-       c_h="" i_h=""
-       c_u="" i_u=""
-       c_f="" i_f=""
-       c_t="" c_c=""
+       c_d="" i_d="" c_ht=""  c_tz=""
+       c_h="" i_h="" c_hc=""  c_tzt=""
+       c_u="" i_u="" c_hk=""  c_tztt=""
+       c_f="" i_f="" c_hr=""  c_tzls=""
+       c_t="" c_c="" c_tzn=""
 
        # Check for old tables
        if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/db.frm
@@ -346,7 +401,7 @@ mysqlinit() {
 
          i_d="INSERT INTO db VALUES ('%','test','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y');
          INSERT INTO db VALUES ('%','test\_%','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y');"
-           
+
        fi
 
        if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/host.frm
@@ -430,7 +485,7 @@ mysqlinit() {
          c_f="$c_f   PRIMARY KEY (name)"
          c_f="$c_f )"
          c_f="$c_f CHARACTER SET utf8 COLLATE utf8_bin"
-         c_f="$c_f   comment='User defined functions';"
+         c_f="$c_f comment='User defined functions';"
        fi
 
        if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/tables_priv.frm
@@ -448,7 +503,7 @@ mysqlinit() {
          c_t="$c_t   KEY Grantor (Grantor)"
          c_t="$c_t )"
          c_t="$c_t CHARACTER SET utf8 COLLATE utf8_bin"
-         c_t="$c_t   comment='Table privileges';"
+         c_t="$c_t comment='Table privileges';"
        fi
 
        if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/columns_priv.frm
@@ -464,26 +519,141 @@ mysqlinit() {
          c_c="$c_c   PRIMARY KEY (Host,Db,User,Table_name,Column_name)"
          c_c="$c_c )"
          c_c="$c_c CHARACTER SET utf8 COLLATE utf8_bin"
-         c_c="$c_c   comment='Column privileges';"
+         c_c="$c_c comment='Column privileges';"
+       fi
+
+       if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/help_topic.frm
+       then
+         c_ht="$c_ht CREATE TABLE help_topic ("
+         c_ht="$c_ht   help_topic_id    int unsigned not null,"
+         c_ht="$c_ht   name             varchar(64) not null,"
+      c_ht="$c_ht   help_category_id smallint unsigned not null,"
+         c_ht="$c_ht   description      text not null,"
+         c_ht="$c_ht   example          text not null,"
+         c_ht="$c_ht   url              varchar(128) not null,"
+         c_ht="$c_ht   primary key      (help_topic_id),"
+         c_ht="$c_ht   unique index     (name)"
+         c_ht="$c_ht )"
+         c_ht="$c_ht CHARACTER SET utf8"
+         c_ht="$c_ht comment='help topics';"
+       fi
+
+       if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/help_category.frm
+       then
+         c_hc="$c_hc CREATE TABLE help_category ("
+         c_hc="$c_hc   help_category_id   smallint unsigned not null,"
+         c_hc="$c_hc   name               varchar(64) not null,"
+         c_hc="$c_hc   parent_category_id smallint unsigned null,"
+         c_hc="$c_hc   url                varchar(128) not null,"
+         c_hc="$c_hc   primary key        (help_category_id),"
+         c_hc="$c_hc   unique index       (name)"
+         c_hc="$c_hc )"
+         c_hc="$c_hc   CHARACTER SET utf8"
+         c_hc="$c_hc comment='help categories';"
+       fi
+
+       if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/help_keyword.frm
+       then
+         c_hk="$c_hk CREATE TABLE help_keyword ("
+         c_hk="$c_hk   help_keyword_id  int unsigned not null,"
+         c_hk="$c_hk   name             varchar(64) not null,"
+         c_hk="$c_hk   primary key      (help_keyword_id),"
+         c_hk="$c_hk   unique index     (name)"
+         c_hk="$c_hk )"
+         c_hk="$c_hk   CHARACTER SET utf8"
+         c_hk="$c_hk comment='help keywords';"
        fi
 
-       mkdir -p "$MYSQL_DATA_DIR" > /dev/null 2>&1
+       if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/help_relation.frm
+       then
+         c_hr="$c_hr CREATE TABLE help_relation ("
+         c_hr="$c_hr   help_topic_id    int unsigned not null references help_topic,"
+         c_hr="$c_hr   help_keyword_id  int unsigned not null references help_keyword,"
+         c_hr="$c_hr   primary key      (help_keyword_id, help_topic_id)"
+         c_hr="$c_hr )"
+         c_hr="$c_hr   CHARACTER SET utf8"
+         c_hr="$c_hr comment='keyword-topic relation';"
+       fi
+
+       if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/time_zone_name.frm
+       then
+         c_tzn="$c_tzn CREATE TABLE time_zone_name ("
+         c_tzn="$c_tzn   Name char(64) NOT NULL,"
+         c_tzn="$c_tzn   Time_zone_id int unsigned NOT NULL,"
+         c_tzn="$c_tzn   PRIMARY KEY Name (Name)"
+         c_tzn="$c_tzn )"
+         c_tzn="$c_tzn   CHARACTER SET utf8"
+         c_tzn="$c_tzn comment='Time zone names';"
+       fi
+
+       if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/time_zone.frm
+       then
+         c_tz="$c_tz CREATE TABLE time_zone ("
+         c_tz="$c_tz   Time_zone_id int unsigned NOT NULL auto_increment,"
+         c_tz="$c_tz   Use_leap_seconds enum('Y','N') DEFAULT 'N' NOT NULL,"
+         c_tz="$c_tz   PRIMARY KEY TzId (Time_zone_id)"
+         c_tz="$c_tz )"
+         c_tz="$c_tz   CHARACTER SET utf8"
+         c_tz="$c_tz comment='Time zones';"
+       fi
+
+       if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/time_zone_transition.frm
+       then
+         c_tzt="$c_tzt CREATE TABLE time_zone_transition ("
+         c_tzt="$c_tzt   Time_zone_id int unsigned NOT NULL,"
+         c_tzt="$c_tzt   Transition_time bigint signed NOT NULL,"
+         c_tzt="$c_tzt   Transition_type_id int unsigned NOT NULL,"
+         c_tzt="$c_tzt   PRIMARY KEY TzIdTranTime (Time_zone_id, Transition_time)"
+         c_tzt="$c_tzt )"
+         c_tzt="$c_tzt   CHARACTER SET utf8"
+         c_tzt="$c_tzt comment='Time zone transitions';"
+       fi
+
+       if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/time_zone_transition_type.frm
+       then
+         c_tztt="$c_tztt CREATE TABLE time_zone_transition_type ("
+         c_tztt="$c_tztt   Time_zone_id int unsigned NOT NULL,"
+         c_tztt="$c_tztt   Transition_type_id int unsigned NOT NULL,"
+         c_tztt="$c_tztt   Offset int signed DEFAULT 0 NOT NULL,"
+         c_tztt="$c_tztt   Is_DST tinyint unsigned DEFAULT 0 NOT NULL,"
+         c_tztt="$c_tztt   Abbreviation char(8) DEFAULT '' NOT NULL,"
+         c_tztt="$c_tztt   PRIMARY KEY TzIdTrTId (Time_zone_id, Transition_type_id)"
+         c_tztt="$c_tztt )"
+         c_tztt="$c_tztt   CHARACTER SET utf8"
+         c_tztt="$c_tztt comment='Time zone transition types';"
+       fi
+
+       if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/time_zone_leap_second.frm
+       then
+         c_tzls="$c_tzls CREATE TABLE time_zone_leap_second ("
+         c_tzls="$c_tzls   Transition_time bigint signed NOT NULL,"
+         c_tzls="$c_tzls   Correction int signed NOT NULL,"
+         c_tzls="$c_tzls   PRIMARY KEY TranTime (Transition_time)"
+         c_tzls="$c_tzls )"
+         c_tzls="$c_tzls CHARACTER SET utf8"
+         c_tzls="$c_tzls   comment='Leap seconds information for time zones';"
+       fi
+
+       mkdir -p "$MYSQL_DATA_DIR"
        # Using mysql:mysql for MYSQL_CLUSTER_DIR is creating SECURITY hole, root:root is proper
        chown root:root "$MYSQL_CLUSTER_DIR"
     chown mysql:mysql "$MYSQL_CLUSTER_DIR/mysqldb" "$MYSQL_DATA_DIR" > /dev/null 2>&1
        chmod 751 "$MYSQL_CLUSTER_DIR" "$MYSQL_CLUSTER_DIR/mysqldb"
 
        if [ -f /usr/share/mysql/mysqld.conf -a ! -f "$MYSQL_CLUSTER_DIR/mysqld.conf" ]; then
-           sed -e "s#datadir.*=.*#datadir      = $MYSQL_DATA_DIR#g" \
-               -e "s#pid-file.*=.*#pid-file = $MYSQL_PIDFILE#g" \
-               -e "s#socket.*=.*#socket = $MYSQL_SOCKET#g" \
-               /usr/share/mysql/mysqld.conf > "$MYSQL_CLUSTER_DIR/mysqld.conf"
+           sed -e "
+               s#\(datadir.*\)=.*#\1= $MYSQL_DATA_DIR#g;
+               s#\(pid-file.*\)=.*#\1= $MYSQL_PIDFILE#g;
+               s#\(socket.*\)=.*#\1= $MYSQL_SOCKET#g;
+               s#@clusterdir@#$MYSQL_CLUSTER_DIR#g;
+               " /usr/share/mysql/mysqld.conf > "$MYSQL_CLUSTER_DIR/mysqld.conf"
            chown root:root "$MYSQL_CLUSTER_DIR/mysqld.conf"
            chmod 640 "$MYSQL_CLUSTER_DIR/mysqld.conf"
        fi
 
-       if [ ! -e /var/lib/mysql/mysql.sock ]; then
-           ln -s "$MYSQL_SOCKET" /var/lib/mysql/mysql.sock
+       if [ ! -e /var/lib/mysql/mysql.sock ] || [ -L /var/lib/mysql/mysql.sock ] && [ -z "$(readlink /var/lib/mysql/mysql.sock)" ]; then
+               sock=${MYSQL_SOCKET#/var/lib/mysql/} # make it relative if possible
+           ln -s "$sock" /var/lib/mysql/mysql.sock
        fi
 
        if /usr/sbin/mysqld --bootstrap --skip-grant-tables \
@@ -504,25 +674,34 @@ $i_f
 
 $c_t
 $c_c
+
+$c_ht
+$c_hc
+$c_hk
+$c_hr
+
+$c_tzn
+$c_tz
+$c_tzt
+$c_tztt
+$c_tzls
 END_OF_DATA
-       then 
+       then
            ok
        cat << END_OF_MSG
 
 PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL USERS!
-This is done (after starting database) with:
+This is done (after starting database; press enter when asked for password) with:
 
-/usr/bin/mysqladmin -u mysql -S $MYSQL_SOCKET password 'password'
-/usr/bin/mysqladmin -h $hostname -u mysql -S $MYSQL_SOCKET password 'password'
-/usr/bin/mysqladmin -u mysql_logrotate -S $MYSQL_SOCKET password 'password'
+/usr/bin/mysqladmin -u mysql -p -S $MYSQL_SOCKET password 'password'
+/usr/bin/mysqladmin -h $hostname -u mysql -p -S $MYSQL_SOCKET password 'password'
+/usr/bin/mysqladmin -u mysql_logrotate -p -S $MYSQL_SOCKET password 'password'
 
 NOTE: mysql_logrotate password should be placed to $MYSQL_CONFIG in
 mysqladmin section. See the manual for more instructions.
 
-IMPORTANT: The configuration file is mysqld.conf in MYSQL_DB_CLUSTERS directories.
-
 END_OF_MSG
-      else  
+      else
            fail
            cat << END_OF_MSG
 Installation of grant tables FAILED!
@@ -543,13 +722,13 @@ logging in /etc/mysqld.conf gives you a log in /var/log/mysql/log that
 may be helpful. The latest information about MySQL is available on the
 web at http://www.mysql.com/.
 
-Please check PLD ftp site for newer versions of this package.
+Please check PLD Linux ftp site for newer versions of this package.
 
 Please consult the MySQL manual section: 'Problems running
 mysql_install_db', and the manual section that describes problems on
 your OS.  Another information source is the MySQL email archive.
 Please check all of the above before mailing us!  And if you do mail
-us, you MUST use the /usr/bin/mysqlbug script!  
+us, you MUST use the /usr/bin/mysqlbug script!
 
 END_OF_MSG
 
@@ -561,9 +740,7 @@ END_OF_MSG
 # End of useful functions.
 #
 
-RETVAL=0
-case "$action" in
-  start)
+start() {
        if [ ! -f $MYSQL_ERRLOG ]; then
                touch $MYSQL_ERRLOG
        fi
@@ -571,7 +748,7 @@ case "$action" in
        chmod 640 $MYSQL_ERRLOG
 
        for mysqldir in $DB_CLUSTERS; do
-               mysqlstatus "$mysqldir"
+               mysqlstatus "$mysqldir" start
                if [ "$MYSQL_STATUS" = "running" ]; then
                        msg_already_running "MySQL $mysqldir"
                else
@@ -579,10 +756,11 @@ case "$action" in
                fi
        done
        mysqlsubsys
-       ;;
-  stop)
+}
+
+stop() {
        for mysqldir in $DB_CLUSTERS; do
-               mysqlstatus "$mysqldir"
+               mysqlstatus "$mysqldir" stop
                if [ "$MYSQL_STATUS" = "not running" ]; then
                        msg_not_running "MySQL $mysqldir"
                else
@@ -590,19 +768,33 @@ case "$action" in
                fi
        done
        mysqlsubsys
+}
+
+RETVAL=0
+case "$action" in
+  start)
+       start
+       ;;
+  stop)
+       stop
        ;;
   status)
-       status mysqld
        for mysqldir in $DB_CLUSTERS; do
                mysqlstatus "$mysqldir"
-               echo "MySQL cluster $mysqldir: $MYSQL_STATUS"
+               if [ "$MYSQL_STATUS" = "running" ]; then
+                       show "MySQL cluster %s, PID %s" "$mysqldir" "$MYSQL_PID"
+                       progress "$MYSQL_STATUS"
+               else
+                       show "MySQL cluster %s" "$mysqldir"
+                       progress "$MYSQL_STATUS" "$CFAIL"
+               fi
+               echo
        done
        exit $?
        ;;
   restart|force-reload)
-       $0 stop $DB_CLUSTERS
-       $0 start $DB_CLUSTERS
-       exit $?
+       stop
+       start
        ;;
   init)
        for mysqldir in $DB_CLUSTERS; do
@@ -613,7 +805,10 @@ case "$action" in
   flush-logs)
        for mysqldir in $DB_CLUSTERS; do
            mysqlgetconfig "$mysqldir"
-           /usr/bin/mysqladmin --defaults-file="$MYSQL_CONFIG" --socket="$MYSQL_SOCKET" flush-logs
+               # just if mysqld is really running
+               if /usr/bin/mysqladmin --defaults-file="$MYSQL_CONFIG" --socket="$MYSQL_SOCKET" ping >/dev/null 2>&1; then
+                       /usr/bin/mysqladmin --defaults-file="$MYSQL_CONFIG" --socket="$MYSQL_SOCKET" flush-logs
+               fi
        done
        ;;
   *)
This page took 0.049617 seconds and 4 git commands to generate.