]> git.pld-linux.org Git - packages/mysql.git/blobdiff - mysql.init
small reorganize, move slave related options together
[packages/mysql.git] / mysql.init
old mode 100644 (file)
new mode 100755 (executable)
index 3072aad..fadce4c
@@ -5,8 +5,6 @@
 # chkconfig:   2345 84 25
 #
 # description:  A very fast and reliable SQL database engine.
-#
-# $Id$
 
 # Source function library
 . /etc/rc.d/init.d/functions
@@ -102,7 +100,7 @@ mysqlstatus() {
        clusterdir="$1"
        mode="$2"
        
-       mysqlgetconfig "$clusterdir"
+       mysqlgetconfig "$clusterdir" status
 
        MYSQL_STATUS="not running"
        MYSQL_PID="unknown"
@@ -153,9 +151,11 @@ mysqlstatus() {
 #
 # arguments
 # $1 - db cluster
+# $2 - status | other
 
 mysqlgetconfig() {
        local clusterdir="$1" config_file
+       local mode="$2"
 
        # emulate old behaviour if only one cluster specified
        if [ "$clusterdir" = "$MYSQL_DB_CLUSTERS" -a "$clusterdir" = "/var/lib/mysql" -a -f /etc/mysqld.conf ]; then
@@ -176,7 +176,11 @@ mysqlgetconfig() {
 
        if [ -z "$config_file" ]; then
                nls "Error: Can't find config file for %s cluster" "$clusterdir"
-               exit 6
+               if [ "$mode" = "status" ]; then 
+                       exit 3
+               else
+                       exit 6
+               fi
        else
                MYSQL_CONFIG="$config_file"
        fi
@@ -184,7 +188,11 @@ mysqlgetconfig() {
        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'?"
-               exit 6
+               if [ "$mode" = "status" ]; then 
+                       exit 3
+               else
+                       exit 6
+               fi
        fi
 
        # reset to initial state
@@ -196,8 +204,8 @@ mysqlgetconfig() {
                gsub(/\r$/, "");
 
                # trim spaces
-               gsub(/^[\t ]*|[\t ]*$/, "", $1);
-               gsub(/^[\t ]*|[\t ]*$/, "", $2);
+               gsub(/^[\t ]+|[\t ]+$/, "", $1);
+               gsub(/^[\t ]+|[\t ]+$/, "", $2);
        }
 
        # skip comments and empty lines
@@ -347,6 +355,58 @@ mysqlstop() {
        fi
 }
 
+# report slave status
+# uses MYSQL_SOCKET - path to mysql socket
+slave_status() {
+       # see if slave status can be reported
+       local err=0 slave_status=$(mysql -S $MYSQL_SOCKET -e 'show slave status\G')
+       if [ -z "$slave_status" ]; then
+               # slave not setup
+               return
+       fi
+
+       printf "\tSlave Status:\n"
+
+       eval $(echo "$slave_status" | awk -F': ' '/^ *[A-Za-z_]+:/{
+               k = tolower($1);
+               v = substr($0, length($1) + 3);
+               gsub(/\\/, "\\\\\\", v);
+               gsub(/"/, "\\\"", v);
+               gsub(/`/, "\\`", v);
+               gsub(/\$/, "\\$", v);
+               printf("%s=\"%s\";\n", k, v);
+       }')
+
+       if [ "$slave_io_running" != "Yes" ]; then
+               printf "\tSlave IO not running\n"
+               err=1
+       fi
+       if [ "$slave_sql_running" != "Yes" ]; then
+               printf "\tSlave SQL not running\n"
+               err=1
+       fi
+
+       if [ "$err" = 1 -a "$last_errno" -gt 0 ]; then
+               printf "\tERROR $last_errno: $last_error\n"
+       fi
+
+       if [ "$master_log_file" != "$relay_master_log_file" ]; then
+               printf "\tERROR logfile mismatch ($relay_master_log_file)\n"
+               err=1
+       fi
+
+       if [ -z "$read_master_log_pos" -o -z "$exec_master_log_pos" ]; then
+               printf "\tERROR No info about master\n"
+               err=1
+               return
+       fi
+
+       diff=$(($read_master_log_pos - $exec_master_log_pos))
+       printf "\tread pos: $read_master_log_pos ($master_log_file) (host: $master_host:$master_port)\n"
+       printf "\texec pos: $exec_master_log_pos\n"
+       printf "\tdiff: $diff\n"
+}
+
 #
 # check for running mysql instances; if any instance is running then
 # create subsys lock file
@@ -385,7 +445,7 @@ mysqlinit() {
                MYSQL_CONFIG="$MYSQL_CLUSTER_DIR/mysqld.conf"
        fi
 
-       show "Initializing cluster %s" "$clusterdir"; echo
+       show "Initializing cluster %s" "$clusterdir"; started
 
        # Check if not exist init database
        if [ -d "$MYSQL_DATA_DIR/mysql" ]; then
@@ -433,7 +493,6 @@ EOF
                --defaults-file=$MYSQL_CLUSTER_DIR/mysqld.conf \
                --bootstrap \
                --skip-grant-tables \
-               --skip-innodb \
                --datadir=$MYSQL_DATA_DIR \
                --user=$MYSQL_USER \
                --slave-load-tmpdir=$MYSQL_DATA_DIR \
@@ -469,7 +528,6 @@ END_OF_MSG
                        --defaults-file=$MYSQL_CLUSTER_DIR/mysqld.conf \
                        --bootstrap \
                        --skip-grant-tables \
-                       --skip-innodb \
                        --datadir=$MYSQL_DATA_DIR \
                        --user=$MYSQL_USER \
                        --slave-load-tmpdir=$MYSQL_DATA_DIR \
@@ -595,16 +653,21 @@ case "$action" in
        done
        ;;
   status)
+       RETVAL=3
        for mysqldir in $DB_CLUSTERS; do
                mysqlstatus "$mysqldir"
                if [ "$MYSQL_STATUS" = "running" ]; then
+                       RETVAL=0
                        addr=${MYSQL_BIND_ADDRESS:-0.0.0.0}
                        port=${MYSQL_PORT:-3306}
                        socket=${MYSQL_SOCKET:-/var/lib/mysql/mysql.sock}
                        pid=$MYSQL_PID
                        nls "MySQL cluster %s, pid %s\n" "$mysqldir" "$pid"
                        [ -z "$MYSQL_SKIP_NETWORKING" ] && nls "\ttcp:%s:%s\n" "$addr" "$port"
-                       nls "\tunix:%s\n" "$socket"
+                       nls "\tunix: %s\n" "$socket"
+
+                       MYSQL_SOCKET=$socket slave_status
+
                        pids="$pids/$MYSQL_PID/"
                        progress "$MYSQL_STATUS"
                else
@@ -634,7 +697,10 @@ case "$action" in
                                socket=${MYSQL_SOCKET:-/var/lib/mysql/mysql.sock}
                                nls "MySQL cluster %s, pid %s\n" "$mysqldir" "$pid"
                                [ -z "$MYSQL_SKIP_NETWORKING" ] && nls "\ttcp:%s:%s\n" "$addr" "$port"
-                               nls "\tunix:%s\n" "$socket"
+                               nls "\tunix: %s\n" "$socket"
+
+                               MYSQL_SOCKET=$socket slave_status
+
                                progress "$MYSQL_STATUS"
                        else
                                show "MySQL cluster %s" "$mysqldir"
This page took 0.041394 seconds and 4 git commands to generate.