X-Git-Url: https://git.pld-linux.org/?p=packages%2Fmysql.git;a=blobdiff_plain;f=mysql.init;h=47db1a1b3e836a540b4f07f7131c150c43c4dc66;hp=3b46d5b11b56d52d1c70164ac11ba6ac94ad3d55;hb=a978e4cc2873fa921707566bbee24c205330a051;hpb=494b45818100144100602685d05817708dc9209f diff --git a/mysql.init b/mysql.init old mode 100644 new mode 100755 index 3b46d5b..47db1a1 --- a/mysql.init +++ b/mysql.init @@ -1,11 +1,11 @@ #!/bin/sh # -# mysql A very fast and reliable SQL database engine +# mysql A very fast and reliable SQL database engine # -# chkconfig: 2345 84 25 +# chkconfig: 2345 84 25 # # description: A very fast and reliable SQL database engine. -# + # Source function library . /etc/rc.d/init.d/functions @@ -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,13 +57,28 @@ 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} +# global error log, if mysqld.conf hasn't migrated to log-error style +MYSQL_ERRLOG=/var/log/mysql/mysqld.log MYSQL_STOP_WAIT_TIME=${MYSQL_STOP_WAIT_TIME:-900} # @@ -85,7 +100,7 @@ mysqlstatus() { clusterdir="$1" mode="$2" - mysqlgetconfig "$clusterdir" + mysqlgetconfig "$clusterdir" status MYSQL_STATUS="not running" MYSQL_PID="unknown" @@ -111,7 +126,7 @@ mysqlstatus() { 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 grep -qa "$MYSQL_PIDFILE" /proc/$MYSQL_PID/cmdline 2> /dev/null; then if [ -f "$MYSQL_PIDFILE" ]; then MYSQL_PIDFILE_PID=$(cat "$MYSQL_PIDFILE") fi @@ -131,66 +146,105 @@ mysqlstatus() { } # get mysql configuration in variables -# MYSQL_CONFIG MYSQL_DATA_DIR MYSQL_USER MYSQL_PIDFILE +# MYSQL_CONFIG MYSQL_CLUSTER_DIR +# MYSQL_DATA_DIR MYSQL_USER MYSQL_PIDFILE MYSQL_SOCKET MYSQL_PORT MYSQL_BIND_ADDRESS MYSQL_SKIP_NETWORKING MYSQL_LOG_ERROR # # arguments # $1 - db cluster +# $2 - status | other mysqlgetconfig() { - clusterdir="$1" + 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 - 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 + local 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 + if [ "$mode" = "status" ]; then + exit 3 + else + exit 6 + fi 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'?" - exit 6 + if [ "$mode" = "status" ]; then + exit 3 + else + exit 6 + fi fi - eval `awk ' -/^[ \t]*\[.*\][ \t]*$/ { - match($0,/\[.*\]/) - section=substr($0,RSTART+1,RSTART+RLENGTH-3) -} -section=="mysqld" && $2~"=" { - if ($1=="datadir") { - printf("MYSQL_DATA_DIR=%s;", $3) - } else if ($1=="user") { - printf("MYSQL_USER=%s;", $3) - } else if ($1=="pid-file") { - printf("MYSQL_PIDFILE=%s;", $3) - } else if ($1=="socket") { - printf("MYSQL_SOCKET=%s;", $3) + # reset to initial state + MYSQL_DATA_DIR= MYSQL_USER= MYSQL_PIDFILE= MYSQL_SOCKET= MYSQL_PORT= MYSQL_BIND_ADDRESS= MYSQL_SKIP_NETWORKING= MYSQL_LOG_ERROR= + + eval `awk -F= ' + { + # undos + gsub(/\r$/, ""); + + # trim spaces + gsub(/^[\t ]+|[\t ]+$/, "", $1); + gsub(/^[\t ]+|[\t ]+$/, "", $2); } -} -END { - print "export MYSQL_DATA_DIR MYSQL_USER MYSQL_PIDFILE MYSQL_SOCKET" -} -' $config_file` + # skip comments and empty lines + /^[;#]|^ *$/ { next } + + /^[ \t]*\[.*\][ \t]*$/ { + match($0, /\[.*\]/); + section = substr($0, RSTART + 1, RSTART + RLENGTH - 3); + next; + } + + section == "mysqld" { + if ($1 == "datadir") { + printf("MYSQL_DATA_DIR=%s;", $2); + } else if ($1 == "user") { + printf("MYSQL_USER=%s;", $2); + } else if ($1 == "pid-file") { + printf("MYSQL_PIDFILE=%s;", $2); + } else if ($1 == "socket") { + printf("MYSQL_SOCKET=%s;", $2); + } else if ($1 == "port") { + printf("MYSQL_PORT=%s;", $2); + } else if ($1 == "bind-address") { + printf("MYSQL_BIND_ADDRESS=%s;", $2); + } else if ($1 == "skip-networking") { + printf("MYSQL_SKIP_NETWORKING=1;"); + } else if ($1 == "log-error") { + printf("MYSQL_LOG_ERROR=%s;", $2); + } + } + ' $config_file` + + # error log not defined in config file. add one + if [ -z "$MYSQL_LOG_ERROR" ]; then + MYSQL_LOG_ERROR=$MYSQL_ERRLOG + else + # unset, so mysqld would use value from config itself + unset MYSQL_LOG_ERROR + fi if is_yes "$MYSQL_RA_COMPAT"; then MYSQL_DATA_DIR_SUB="" @@ -210,7 +264,7 @@ END { exit 6 fi - if [ -z $MYSQL_USER ]; then + if [ -z "$MYSQL_USER" ]; then echo "$(nls 'MySQL user not configured properly')"'!' >&2 nls "Edit %s and configure it." "$config_file" >&2 exit 6 @@ -219,7 +273,7 @@ END { # start mysql mysqlstart() { - clusterdir="$1" + local clusterdir="$1" mysqlgetconfig "$clusterdir" if [ ! -d "$MYSQL_DATA_DIR/mysql" ]; then nls "MySQL cluster %s not initialized." "$clusterdir" @@ -227,18 +281,35 @@ mysqlstart() { exit 6 fi - msg_starting "MySQL $clusterdir" - busy + msg_starting "MySQL $clusterdir"; busy [ -z "$DEFAULT_SERVICE_RUN_NICE_LEVEL" ] && DEFAULT_SERVICE_RUN_NICE_LEVEL=0 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 + + + 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_LOG_ERROR:+--log-error="$MYSQL_LOG_ERROR"} \ + $MYSQL_OPTIONS & + pid=$! + + sleep 0.1 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 + echo "" + show "Waiting for MySQL to start" + busy + + # while the pid is running, mysql is starting up + # if the pidfile was created, it started up successfully + # if either case fails we break and report status + while true; do + [ -d /proc/$pid ] || break [ -f "$MYSQL_PIDFILE" ] && break - sleep 0.1 + sleep 0.2 done fi @@ -256,13 +327,13 @@ mysqlstart() { # stop mysql mysqlstop() { - clusterdir="$1" + local clusterdir="$1" mysqlstatus "$clusterdir" stop msg_stopping "MySQL $clusterdir" busy # try graceful shutdown -- send shutdown command - # requires mysql_logrotate user proper privs + # requires mysql_sysadmin user proper privs /usr/bin/mysqladmin --defaults-file=$MYSQL_CONFIG ${MYSQL_SOCKET:+--socket=$MYSQL_SOCKET} shutdown >/dev/null 2>&1 mysqlstatus "$clusterdir" stop @@ -284,6 +355,61 @@ 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 --defaults-file="$MYSQL_CONFIG" --socket="$MYSQL_SOCKET" -e 'show slave status\G') + if [ -z "$slave_status" ]; then + # slave not setup + return + fi + + printf "Slave Status:\n" + + set -f + 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); + gsub(/\$/, "\\$", v); + printf("%s=\"%s\";\n", k, v); + }') + set +f + + 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 %s: %s\n" "$last_errno" "$last_error" + fi + + if [ "$master_log_file" != "$relay_master_log_file" ]; then + printf "\tERROR logfile mismatch (%s)\n" "$relay_master_log_file" + 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: %s (%s) (host: %s:%d)\n" "$read_master_log_pos" "$master_log_file" "$master_host" "$master_port" + printf "\texec pos: %s\n" "$exec_master_log_pos" + printf "\tdiff: %s\n" "$diff" +} + # # check for running mysql instances; if any instance is running then # create subsys lock file @@ -301,7 +427,7 @@ mysqlsubsys() { } mysqlinit() { - clusterdir="$1" + local clusterdir="$1" if [ -f /etc/mysqld.conf ]; then nls "Running in \`no cluster compat' mode: can't initialize database." @@ -322,492 +448,129 @@ mysqlinit() { MYSQL_CONFIG="$MYSQL_CLUSTER_DIR/mysqld.conf" fi - nls "Initializing cluster %s" "$clusterdir" + show "Initializing cluster %s" "$clusterdir"; started # Check if not exist init database if [ -d "$MYSQL_DATA_DIR/mysql" ]; then nls "Seems that database is initialized now. Remove by hand %s" "$MYSQL_DATA_DIR/mysql" nls "before initializing database." nls "For now skipping cluster %s." "$clusterdir" - return + exit 6 fi - show "Creating privilege mysql tables for $MYSQL_DATA_DIR" + show "Installing MySQL system tables for $MYSQL_DATA_DIR" busy 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 - fail - 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 - deltext - fail - nls "Sorry, the host '%s' could not be looked up." "$hostname" - nls "Please configure the 'hostname' command to return a correct hostname." - exit 1 - fi - - # Initialize variables - 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="" c_p="" - c_pp="" - - # Check for old tables - if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/db.frm - then - # mysqld --bootstrap wants one command/line - c_d="$c_d CREATE TABLE db (" - c_d="$c_d Host char(60) DEFAULT '' NOT NULL," - c_d="$c_d Db char(64) DEFAULT '' NOT NULL," - c_d="$c_d User char(16) DEFAULT '' NOT NULL," - c_d="$c_d Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_d="$c_d Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_d="$c_d Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_d="$c_d Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_d="$c_d Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_d="$c_d Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_d="$c_d Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_d="$c_d References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_d="$c_d Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_d="$c_d Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_d="$c_d Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_d="$c_d Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_d="$c_d Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_d="$c_d Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_d="$c_d Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_d="$c_d Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_d="$c_d Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_d="$c_d PRIMARY KEY Host (Host,Db,User)," - c_d="$c_d KEY User (User)" - c_d="$c_d )" - c_d="$c_d CHARACTER SET utf8 COLLATE utf8_bin" - c_d="$c_d comment='Database privileges';" - - i_d="INSERT INTO db VALUES ('%','test','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','N','N'); - INSERT INTO db VALUES ('%','test\_%','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','N','N');" - - fi - - if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/host.frm - then - c_h="$c_h CREATE TABLE host (" - c_h="$c_h Host char(60) DEFAULT '' NOT NULL," - c_h="$c_h Db char(64) DEFAULT '' NOT NULL," - c_h="$c_h Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_h="$c_h Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_h="$c_h Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_h="$c_h Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_h="$c_h Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_h="$c_h Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_h="$c_h Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_h="$c_h References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_h="$c_h Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_h="$c_h Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_h="$c_h Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_h="$c_h Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_h="$c_h Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_h="$c_h Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_h="$c_h Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_h="$c_h Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_h="$c_h Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_h="$c_h PRIMARY KEY Host (Host,Db)" - c_h="$c_h )" - c_h="$c_h CHARACTER SET utf8 COLLATE utf8_bin" - c_h="$c_h comment='Host privileges; Merged with database privileges';" - fi - - if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/user.frm - then - c_u="$c_u CREATE TABLE user (" - c_u="$c_u Host char(60) binary DEFAULT '' NOT NULL," - c_u="$c_u User char(16) binary DEFAULT '' NOT NULL," - c_u="$c_u Password char(41) character set latin1 collate latin1_bin DEFAULT '' NOT NULL," - c_u="$c_u Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_u="$c_u Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_u="$c_u Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_u="$c_u Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_u="$c_u Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_u="$c_u Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_u="$c_u Reload_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_u="$c_u Shutdown_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_u="$c_u Process_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_u="$c_u File_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_u="$c_u Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_u="$c_u References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_u="$c_u Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_u="$c_u Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_u="$c_u Show_db_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_u="$c_u Super_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_u="$c_u Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_u="$c_u Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_u="$c_u Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_u="$c_u Repl_slave_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_u="$c_u Repl_client_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_u="$c_u Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_u="$c_u Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_u="$c_u Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_u="$c_u Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_u="$c_u Create_user_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," - c_u="$c_u ssl_type enum('','ANY','X509', 'SPECIFIED') COLLATE utf8_general_ci DEFAULT '' NOT NULL," - c_u="$c_u ssl_cipher BLOB NOT NULL," - c_u="$c_u x509_issuer BLOB NOT NULL," - c_u="$c_u x509_subject BLOB NOT NULL," - c_u="$c_u max_questions int(11) unsigned DEFAULT 0 NOT NULL," - c_u="$c_u max_updates int(11) unsigned DEFAULT 0 NOT NULL," - c_u="$c_u max_connections int(11) unsigned DEFAULT 0 NOT NULL," - c_u="$c_u max_user_connections int(11) unsigned DEFAULT 0 NOT NULL," - c_u="$c_u PRIMARY KEY Host (Host,User)" - c_u="$c_u ) engine=MyISAM" - c_u="$c_u CHARACTER SET utf8 COLLATE utf8_bin" - c_u="$c_u comment='Users and global privileges';" - - - i_u="INSERT INTO user VALUES ('localhost','mysql','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0); - INSERT INTO user VALUES ('$hostname', 'mysql','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0); - INSERT INTO user (host,user) values ('localhost',''); - INSERT INTO user (host,user) values ('$hostname',''); - INSERT INTO user VALUES ('localhost','mysql_logrotate','','N','N','N','N','N','N','Y','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','','','','',0,0,0,0);" - fi - - if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/func.frm - then - c_f="$c_f CREATE TABLE func (" - c_f="$c_f name char(64) DEFAULT '' NOT NULL," - c_f="$c_f ret tinyint(1) DEFAULT '0' NOT NULL," - c_f="$c_f dl char(128) DEFAULT '' NOT NULL," - c_f="$c_f type enum ('function','aggregate') COLLATE utf8_general_ci NOT NULL," - 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';" - fi - - if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/tables_priv.frm - then - c_t="$c_t CREATE TABLE tables_priv (" - c_t="$c_t Host char(60) DEFAULT '' NOT NULL," - c_t="$c_t Db char(64) DEFAULT '' NOT NULL," - c_t="$c_t User char(16) DEFAULT '' NOT NULL," - c_t="$c_t Table_name char(60) DEFAULT '' NOT NULL," - c_t="$c_t Grantor char(77) DEFAULT '' NOT NULL," - c_t="$c_t Timestamp timestamp(14)," - c_t="$c_t Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index', 'Alter','Create View','Show view') COLLATE utf8_general_ci DEFAULT '' NOT NULL," - c_t="$c_t Column_priv set('Select','Insert','Update','References') COLLATE utf8_general_ci DEFAULT '' NOT NULL," - c_t="$c_t PRIMARY KEY (Host,Db,User,Table_name)," - 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';" - fi - - if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/columns_priv.frm - then - c_c="$c_c CREATE TABLE columns_priv (" - c_c="$c_c Host char(60) DEFAULT '' NOT NULL," - c_c="$c_c Db char(64) DEFAULT '' NOT NULL," - c_c="$c_c User char(16) DEFAULT '' NOT NULL," - c_c="$c_c Table_name char(64) DEFAULT '' NOT NULL," - c_c="$c_c Column_name char(64) DEFAULT '' NOT NULL," - c_c="$c_c Timestamp timestamp(14)," - c_c="$c_c Column_priv set('Select','Insert','Update','References') COLLATE utf8_general_ci DEFAULT '' NOT NULL," - 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';" - fi - - if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/procs_priv.frm - then - c_pp="$c_pp CREATE TABLE procs_priv (" - c_pp="$c_pp Host char(60) binary DEFAULT '' NOT NULL," - c_pp="$c_pp Db char(64) binary DEFAULT '' NOT NULL," - c_pp="$c_pp User char(16) binary DEFAULT '' NOT NULL," - c_pp="$c_pp Routine_name char(64) binary DEFAULT '' NOT NULL," - c_pp="$c_pp Routine_type enum('FUNCTION','PROCEDURE') NOT NULL," - c_pp="$c_pp Grantor char(77) DEFAULT '' NOT NULL," - c_pp="$c_pp Proc_priv set('Execute','Alter Routine','Grant') COLLATE utf8_general_ci DEFAULT '' NOT NULL," - c_pp="$c_pp Timestamp timestamp(14)," - c_pp="$c_pp PRIMARY KEY (Host,Db,User,Routine_name,Routine_type)," - c_pp="$c_pp KEY Grantor (Grantor)" - c_pp="$c_pp )" - c_pp="$c_pp CHARACTER SET utf8 COLLATE utf8_bin" - c_pp="$c_pp comment='Procedure 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 - - 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 - - if test ! -f $MYSQL_DATA_DIR/mysqldb/mysql/proc.frm - then - c_p="$c_p CREATE TABLE proc (" - c_p="$c_p db char(64) collate utf8_bin DEFAULT '' NOT NULL," - c_p="$c_p name char(64) DEFAULT '' NOT NULL," - c_p="$c_p type enum('FUNCTION','PROCEDURE') NOT NULL," - c_p="$c_p specific_name char(64) DEFAULT '' NOT NULL," - c_p="$c_p language enum('SQL') DEFAULT 'SQL' NOT NULL," - c_p="$c_p sql_data_access enum('CONTAINS_SQL'," - c_p="$c_p 'NO_SQL'," - c_p="$c_p 'READS_SQL_DATA'," - c_p="$c_p 'MODIFIES_SQL_DATA'" - c_p="$c_p ) DEFAULT 'CONTAINS_SQL' NOT NULL," - c_p="$c_p is_deterministic enum('YES','NO') DEFAULT 'NO' NOT NULL," - c_p="$c_p security_type enum('INVOKER','DEFINER') DEFAULT 'DEFINER' NOT NULL," - c_p="$c_p param_list blob DEFAULT '' NOT NULL," - c_p="$c_p returns char(64) DEFAULT '' NOT NULL," - c_p="$c_p body longblob DEFAULT '' NOT NULL," - c_p="$c_p definer char(77) collate utf8_bin DEFAULT '' NOT NULL," - c_p="$c_p created timestamp," - c_p="$c_p modified timestamp," - c_p="$c_p sql_mode set(" - c_p="$c_p 'REAL_AS_FLOAT'," - c_p="$c_p 'PIPES_AS_CONCAT'," - c_p="$c_p 'ANSI_QUOTES'," - c_p="$c_p 'IGNORE_SPACE'," - c_p="$c_p 'NOT_USED'," - c_p="$c_p 'ONLY_FULL_GROUP_BY'," - c_p="$c_p 'NO_UNSIGNED_SUBTRACTION'," - c_p="$c_p 'NO_DIR_IN_CREATE'," - c_p="$c_p 'POSTGRESQL'," - c_p="$c_p 'ORACLE'," - c_p="$c_p 'MSSQL'," - c_p="$c_p 'DB2'," - c_p="$c_p 'MAXDB'," - c_p="$c_p 'NO_KEY_OPTIONS'," - c_p="$c_p 'NO_TABLE_OPTIONS'," - c_p="$c_p 'NO_FIELD_OPTIONS'," - c_p="$c_p 'MYSQL323'," - c_p="$c_p 'MYSQL40'," - c_p="$c_p 'ANSI'," - c_p="$c_p 'NO_AUTO_VALUE_ON_ZERO'," - c_p="$c_p 'NO_BACKSLASH_ESCAPES'," - c_p="$c_p 'STRICT_TRANS_TABLES'," - c_p="$c_p 'STRICT_ALL_TABLES'," - c_p="$c_p 'NO_ZERO_IN_DATE'," - c_p="$c_p 'NO_ZERO_DATE'," - c_p="$c_p 'INVALID_DATES'," - c_p="$c_p 'ERROR_FOR_DIVISION_BY_ZERO'," - c_p="$c_p 'TRADITIONAL'," - c_p="$c_p 'NO_AUTO_CREATE_USER'," - c_p="$c_p 'HIGH_NOT_PRECEDENCE'" - c_p="$c_p ) DEFAULT '' NOT NULL," - c_p="$c_p comment char(64) collate utf8_bin DEFAULT '' NOT NULL," - c_p="$c_p PRIMARY KEY (db,name,type)" - c_p="$c_p )" - c_p="$c_p character set utf8" - c_p="$c_p comment='Stored Procedures';" - fi - mkdir -p "$MYSQL_DATA_DIR" > /dev/null 2>&1 # 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 + 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.*\)=.*#\1= $MYSQL_DATA_DIR#g" \ - -e "s#\(pid-file.*\)=.*#\1= $MYSQL_PIDFILE#g" \ - -e "s#\(socket.*\)=.*#\1= $MYSQL_SOCKET#g" \ - /usr/share/mysql/mysqld.conf > "$MYSQL_CLUSTER_DIR/mysqld.conf" + if [ -f /usr/share/percona-server/mysqld.conf -a ! -f "$MYSQL_CLUSTER_DIR/mysqld.conf" ]; then + 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/percona-server/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 ] || [ -L /var/lib/mysql/mysql.sock ] && [ -z "$(readlink /var/lib/mysql/mysql.sock)" ]; then - sock=$(echo "$MYSQL_SOCKET" | sed -e 's,^/var/lib/mysql/,,') + 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 \ - --datadir=$MYSQL_DATA_DIR --user=$MYSQL_USER << END_OF_DATA -CREATE DATABASE mysql; -use mysql; -$c_d -$i_d - -$c_h -$i_h - -$c_u -$i_u - -$c_f -$i_f - -$c_t -$c_c - -$c_ht -$c_hc -$c_hk -$c_hr - -$c_tzn -$c_tz -$c_tzt -$c_tztt -$c_tzls - -$c_p -$c_pp -END_OF_DATA - then - ok - cat << END_OF_MSG + cat > $MYSQL_DATA_DIR/mysql-init.sql <<-EOF + CREATE DATABASE mysql; + use mysql; + $(cat /usr/share/percona-server/mysql_system_tables.sql) + $(sed -e "/@current_hostname/d" /usr/share/percona-server/mysql_system_tables_data.sql) +EOF + + ok=0 + /usr/sbin/mysqld \ + --defaults-file=$MYSQL_CLUSTER_DIR/mysqld.conf \ + --bootstrap \ + --skip-grant-tables \ + --datadir=$MYSQL_DATA_DIR \ + --user=$MYSQL_USER \ + --slave-load-tmpdir=$MYSQL_DATA_DIR \ + --tmpdir=$MYSQL_DATA_DIR \ + --log-error=$MYSQL_ERRLOG \ + < $MYSQL_DATA_DIR/mysql-init.sql && ok=1 + [ -f $MYSQL_DATA_DIR/mysql/user.frm ] || ok=0 + + if [ "$ok" = 1 ]; then + rm -f $MYSQL_DATA_DIR/mysql-init.sql + ok + cat << END_OF_MSG PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL USERS! -This is done (after starting database; press enter when asked for password) with: +This is done, after starting database, in the order shown, +with: -/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' +For 'mysql_sysadmin' (RELOAD and SHUTDOWN privileges): +echo "update mysql.user set password=password('newpassword') where user='mysql_sysadmin'; FLUSH PRIVILEGES;" | mysql -u mysql -S $MYSQL_SOCKET -NOTE: mysql_logrotate password should be placed to $MYSQL_CONFIG in +For 'mysql' user (ALL privileges, DB admin): +echo "update mysql.user set password=password('newpassword') where user='mysql'; FLUSH PRIVILEGES;" | mysql -u mysql -S $MYSQL_SOCKET + +NOTE: mysql_sysadmin password should be placed to $MYSQL_CONFIG in mysqladmin section. See the manual for more instructions. +(This user is used at logs rotation and server shutdown) + +END_OF_MSG + show "Filling help tables..." + ok=0 + ( echo "use mysql;"; cat /usr/share/percona-server/fill_help_tables.sql ) | \ + /usr/sbin/mysqld \ + --defaults-file=$MYSQL_CLUSTER_DIR/mysqld.conf \ + --bootstrap \ + --skip-grant-tables \ + --datadir=$MYSQL_DATA_DIR \ + --user=$MYSQL_USER \ + --slave-load-tmpdir=$MYSQL_DATA_DIR \ + --tmpdir=$MYSQL_DATA_DIR \ + --log-error=$MYSQL_ERRLOG \ + && ok=1 + if [ "$ok" = 1 ]; then + ok + else + cat << END_OF_MSG -If you want to use new help tables in MySQL 4.1.x then you'll need to import the help data: -/usr/bin/mysql -u mysql -p -S $MYSQL_SOCKET mysql < /usr/share/mysql/fill_help_tables.sql +WARNING: HELP FILES ARE NOT COMPLETELY INSTALLED! +The "HELP" command might not work properly. END_OF_MSG - else - fail - cat << END_OF_MSG -Installation of grant tables FAILED! + fi + else + fail + cat << END_OF_MSG +ERROR: +ERROR: +ERROR: Installation of grant tables FAILED! +ERROR: +ERROR: + +The initialization SQL script was preserved at $MYSQL_DATA_DIR/mysql-init.sql -Examine the logs in $MYSQL_DATA_DIR for more information. You can -also try to start the mysqld demon with: +Examine the logs in /var/log/mysql for more information. You can +also try to start the mysqld daemon with: /usr/sbin/mysqld --skip-grant & -You can use the command line tool /usr/bin/mysql to connect to the mysql +You can use the command line tool mysql to connect to the mysql database and look at the grant tables: -shell> /usr/bin/mysql -u mysql mysql +shell> mysql -u mysql mysql mysql> show tables Try 'mysqld --help' if you have problems with paths. Setting on -logging in /etc/mysqld.conf gives you a log in /var/log/mysql/log that +logging in $MYSQL_DATA_DIR/mysqld.conf gives you a log in /var/log/mysql/query.log that may be helpful. The latest information about MySQL is available on the web at http://www.mysql.com/. @@ -816,12 +579,9 @@ 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! END_OF_MSG - - exit 1 + exit 1 fi } @@ -829,15 +589,8 @@ END_OF_MSG # End of useful functions. # -RETVAL=0 -case "$action" in - start) - if [ ! -f $MYSQL_ERRLOG ]; then - touch $MYSQL_ERRLOG - fi - chown mysql:mysql $MYSQL_ERRLOG - chmod 640 $MYSQL_ERRLOG - +start() { + local mysqldir for mysqldir in $DB_CLUSTERS; do mysqlstatus "$mysqldir" start if [ "$MYSQL_STATUS" = "running" ]; then @@ -847,8 +600,10 @@ case "$action" in fi done mysqlsubsys - ;; - stop) +} + +stop() { + local mysqldir for mysqldir in $DB_CLUSTERS; do mysqlstatus "$mysqldir" stop if [ "$MYSQL_STATUS" = "not running" ]; then @@ -858,12 +613,37 @@ case "$action" in fi done mysqlsubsys - ;; - status) +} + +condrestart() { + if [ ! -f /var/lock/subsys/mysql ]; then + msg_not_running "MySQL" + RETVAL=$1 + return + fi + + stop + start +} + +status() { + local mysqldir addr port socket pid pids running datadir + RETVAL=3 for mysqldir in $DB_CLUSTERS; do mysqlstatus "$mysqldir" if [ "$MYSQL_STATUS" = "running" ]; then - show "MySQL cluster %s, PID %s" "$mysqldir" "$MYSQL_PID" + 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" + + MYSQL_SOCKET=$socket slave_status + + pids="$pids/$MYSQL_PID/" progress "$MYSQL_STATUS" else show "MySQL cluster %s" "$mysqldir" @@ -871,12 +651,58 @@ case "$action" in fi echo done - exit $? + + for pid in $(/sbin/pidof mysqld); do + if [[ $pids != */$pid/* ]]; then + running="$running $pid" + fi + done + + if [ $# = 1 -a "$running" ]; then + nls "Warning: MySQL Daemon processes not under clusters.conf control:" + # see if we can display their status + for pid in $running; do + datadir=$(cat /proc/$pid/cmdline | tr '\0' '\n' | fgrep -- --datadir=) + datadir=${datadir#--datadir=} # strip --datadir + mysqldir=${datadir%/mysqldb/db} # strip /mysqldb/db + mysqlstatus "$mysqldir" + if [ "$MYSQL_STATUS" = "running" ]; then + addr=${MYSQL_BIND_ADDRESS:-0.0.0.0} + port=${MYSQL_PORT:-3306} + 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" + + MYSQL_SOCKET=$socket slave_status + + progress "$MYSQL_STATUS" + else + show "MySQL cluster %s" "$mysqldir" + progress "$MYSQL_STATUS" "$CFAIL" + fi + echo + done + fi +} + +RETVAL=0 +case "$action" in + start) + start ;; - restart|force-reload) - $0 stop $DB_CLUSTERS - $0 start $DB_CLUSTERS - exit $? + stop) + stop + ;; + restart) + stop + start + ;; + try-restart) + condrestart 0 + ;; + force-reload) + condrestart 7 ;; init) for mysqldir in $DB_CLUSTERS; do @@ -885,7 +711,7 @@ case "$action" in exit $? ;; flush-logs) - for mysqldir in $DB_CLUSTERS; do + for mysqldir in $DB_CLUSTERS; do mysqlgetconfig "$mysqldir" # just if mysqld is really running if /usr/bin/mysqladmin --defaults-file="$MYSQL_CONFIG" --socket="$MYSQL_SOCKET" ping >/dev/null 2>&1; then @@ -893,11 +719,12 @@ case "$action" in fi done ;; + status) + status + ;; *) - msg_usage "$0 {start|stop|init|restart|force-reload|status}" + msg_usage "$0 {start|stop|restart|try-restart|force-reload|init|flush-logs|status}" exit 3 esac exit $RETVAL - -# vi: shiftwidth=4 tabstop=4