]> TLD Linux GIT Repositories - packages/mysql.git/blobdiff - mysql.init
- fix bcond comment (breaks build)
[packages/mysql.git] / mysql.init
index 5337ee4e40c7a4d16aa07f818d45efeac43449c9..1e8ff67a796e77f16dab4aeeb0a637ae260fa1a4 100755 (executable)
 . /etc/sysconfig/network
 
 # Get service config
 . /etc/sysconfig/network
 
 # Get service config
-if [ -f /etc/sysconfig/mysql ]; then
-       . /etc/sysconfig/mysql
+if [ -f /etc/sysconfig/mysql-@mysqlversion@ ]; then
+       . /etc/sysconfig/mysql-@mysqlversion@
 else
 else
-       nls "Error: %s not found" /etc/sysconfig/mysql
+       nls "Error: %s not found" /etc/sysconfig/mysql-@mysqlversion@
        nls "%s can't be run." MySQL
        exit 1
 fi
 
 if [ -n "$MYSQL_DB_CLUSTERS" ]; then
        nls "%s can't be run." MySQL
        exit 1
 fi
 
 if [ -n "$MYSQL_DB_CLUSTERS" ]; then
-       nls "Warning: MYSQL_DB_CLUSTERS is set. It's obsolete. Use %s instead." /etc/mysql/clusters.conf
+       nls "Warning: MYSQL_DB_CLUSTERS is set. It's obsolete. Use %s instead." /etc/mysql/@mysqlversion@/clusters.conf
 fi
 
 fi
 
-if [ -f /etc/mysql/clusters.conf ]; then
-       MYSQL_DB_CLUSTERS=$(awk -F= '!/^#/ && /=/{print $2}' /etc/mysql/clusters.conf)
+if [ -f /etc/mysql/@mysqlversion@/clusters.conf ]; then
+       MYSQL_DB_CLUSTERS=$(awk -F= '!/^#/ && /=/{print $2}' /etc/mysql/@mysqlversion@/clusters.conf)
        if [ -z "$MYSQL_DB_CLUSTERS" ]; then
                nls "Warning: there are no configured clusters."
        fi
 
 else
        if [ -z "$MYSQL_DB_CLUSTERS" ]; then
                nls "Warning: there are no configured clusters."
        fi
 
 else
-       nls "Warning: Missing clusters config file %s" /etc/mysql/clusters.conf
+       nls "Warning: Missing clusters config file %s" /etc/mysql/@mysqlversion@/clusters.conf
        if [ -z "$MYSQL_DB_CLUSTERS" ]; then
                nls "Warning: there are no configured clusters."
                nls "Using default cluster /var/lib/mysql (compatibility mode)"
        if [ -z "$MYSQL_DB_CLUSTERS" ]; then
                nls "Warning: there are no configured clusters."
                nls "Using default cluster /var/lib/mysql (compatibility mode)"
@@ -51,7 +51,7 @@ else
        exit 0
 fi
 
        exit 0
 fi
 
-sharedir=/usr/share/mysql
+sharedir=/usr/share/mysql/@mysqlversion@
 
 action="$1"
 
 
 action="$1"
 
@@ -60,9 +60,9 @@ if [ $# -gt 1 ]; then
        shift
        # perform action for specified clusters only
        for a in "$@"; do
        shift
        # perform action for specified clusters only
        for a in "$@"; do
-               # try auto resolving from /etc/mysql/clusters.conf
+               # try auto resolving from /etc/mysql/@mysqlversion@/clusters.conf
                if [[ "$a" != /* ]]; then
                if [[ "$a" != /* ]]; then
-                       m=$(awk -va="$a" -F= 'substr($0, 1, length(a)) == a {print $1}' /etc/mysql/clusters.conf)
+                       m=$(awk -va="$a" -F= 'substr($0, 1, length(a)) == a {print $1}' /etc/mysql/@mysqlversion@/clusters.conf)
                        if [ -z "$m" ]; then
                                echo >&2 "Cluster name '$a' did not match anything!"
                                exit 1
                        if [ -z "$m" ]; then
                                echo >&2 "Cluster name '$a' did not match anything!"
                                exit 1
@@ -71,7 +71,7 @@ if [ $# -gt 1 ]; then
                                echo >&2 "Cluster name '$a' ambiguous:" $m
                                exit 1
                        fi
                                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)
+                       a=$(awk -va="$a" -F= 'substr($0, 1, length(a)) == a {print $2}' /etc/mysql/@mysqlversion@/clusters.conf)
                fi
                DB_CLUSTERS="$DB_CLUSTERS $a"
        done
                fi
                DB_CLUSTERS="$DB_CLUSTERS $a"
        done
@@ -80,7 +80,7 @@ else
 fi
 
 # global error log, if mysqld.conf hasn't migrated to log-error style
 fi
 
 # global error log, if mysqld.conf hasn't migrated to log-error style
-MYSQL_ERRLOG=/var/log/mysql/mysqld.log
+MYSQL_ERRLOG=/var/log/mysql/@mysqlversion@/mysql.log
 MYSQL_STOP_WAIT_TIME=${MYSQL_STOP_WAIT_TIME:-900}
 
 #
 MYSQL_STOP_WAIT_TIME=${MYSQL_STOP_WAIT_TIME:-900}
 
 #
@@ -125,7 +125,7 @@ mysqlstatus() {
        fi
 
        if [ "$mode" = "start" ]; then
        fi
 
        if [ "$mode" = "start" ]; then
-               MYSQL_GREP_PID=$(grep -alE "^/usr/sbin/mysqld.*${MYSQL_PIDFILE}" /proc/[0-9]*/cmdline 2> /dev/null | awk -F "/" '{ print $3; exit; }')
+               MYSQL_GREP_PID=$(grep -alE "^@mysqlsbindir@/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 [ -n "$MYSQL_GREP_PID" ]; then
                        MYSQL_PID=$MYSQL_GREP_PID
                        if grep -qa "$MYSQL_PIDFILE" /proc/$MYSQL_PID/cmdline 2> /dev/null; then
@@ -159,19 +159,13 @@ mysqlgetconfig() {
        local clusterdir="$1" config_file
        local mode="$2"
 
        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
-               config_file=/etc/mysqld.conf
+       local config=$(awk -F= -vclusterdir="$clusterdir" '!/^#/{ if (clusterdir == $2) print $1}' /etc/mysql/@mysqlversion@/clusters.conf)
+       if [[ $config = /* ]]; then
+               config_file="$config"
+       elif [ -f "/etc/mysql/@mysqlversion@/$config" ]; then
+               config_file="/etc/mysql/@mysqlversion@/$config"
        else
        else
-               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"
-               else
-                       config_file="$clusterdir/mysqld.conf"
-               fi
+               config_file="$clusterdir/mysqld.conf"
        fi
 
        MYSQL_CLUSTER_DIR="$clusterdir"
        fi
 
        MYSQL_CLUSTER_DIR="$clusterdir"
@@ -248,11 +242,7 @@ mysqlgetconfig() {
                unset MYSQL_LOG_ERROR
        fi
 
                unset MYSQL_LOG_ERROR
        fi
 
-       if is_yes "$MYSQL_RA_COMPAT"; then
-               MYSQL_DATA_DIR_SUB=""
-       else
-               MYSQL_DATA_DIR_SUB="/mysqldb"
-       fi
+       MYSQL_DATA_DIR_SUB="/mysqldb"
 
        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"
 
        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"
@@ -289,12 +279,12 @@ mysqlstart() {
 
 
        TMPDIR=/tmp nice -n ${SERVICE_RUN_NICE_LEVEL:-$DEFAULT_SERVICE_RUN_NICE_LEVEL} \
 
 
        TMPDIR=/tmp nice -n ${SERVICE_RUN_NICE_LEVEL:-$DEFAULT_SERVICE_RUN_NICE_LEVEL} \
-               /usr/bin/setsid /usr/sbin/mysqld \
+               /usr/bin/setsid @mysqlsbindir@/mysqld \
                        --defaults-file=$MYSQL_CONFIG \
                        --datadir=$MYSQL_DATA_DIR \
                        --pid-file=$MYSQL_PIDFILE \
                        ${MYSQL_LOG_ERROR:+--log-error="$MYSQL_LOG_ERROR"} \
                        --defaults-file=$MYSQL_CONFIG \
                        --datadir=$MYSQL_DATA_DIR \
                        --pid-file=$MYSQL_PIDFILE \
                        ${MYSQL_LOG_ERROR:+--log-error="$MYSQL_LOG_ERROR"} \
-                       $MYSQL_OPTIONS 2>/dev/null &
+                       $MYSQL_OPTIONS &
        pid=$!
 
        sleep 0.1
        pid=$!
 
        sleep 0.1
@@ -336,7 +326,7 @@ mysqlstop() {
 
        # try graceful shutdown -- send shutdown command
        # requires mysql_sysadmin user proper privs
 
        # try graceful shutdown -- send shutdown command
        # requires mysql_sysadmin user proper privs
-       /usr/bin/mysqladmin --defaults-file=$MYSQL_CONFIG ${MYSQL_SOCKET:+--socket=$MYSQL_SOCKET} shutdown >/dev/null 2>&1
+       @mysqlbindir@/mysqladmin --defaults-file=$MYSQL_CONFIG ${MYSQL_SOCKET:+--socket=$MYSQL_SOCKET} shutdown >/dev/null 2>&1
        mysqlstatus "$clusterdir" stop
 
        if [ "$MYSQL_PID" != "unknown" ]; then
        mysqlstatus "$clusterdir" stop
 
        if [ "$MYSQL_PID" != "unknown" ]; then
@@ -360,7 +350,7 @@ mysqlstop() {
 # report slave status
 # uses MYSQL_SOCKET - path to mysql socket
 slave_status() {
 # report slave status
 # uses MYSQL_SOCKET - path to mysql socket
 slave_status() {
-       if [ ! -x /usr/bin/mysql ]; then
+       if [ ! -x @mysqlbindir@/mysql ]; then
                echo >&2 "Slave status not available: 'mysql' program not installed."
                return
        fi
                echo >&2 "Slave status not available: 'mysql' program not installed."
                return
        fi
@@ -426,11 +416,11 @@ mysqlsubsys() {
        for mysqldir in $DB_CLUSTERS; do
                mysqlstatus "$mysqldir"
                if [ "$MYSQL_STATUS" = "running" ]; then
        for mysqldir in $DB_CLUSTERS; do
                mysqlstatus "$mysqldir"
                if [ "$MYSQL_STATUS" = "running" ]; then
-                       touch /var/lock/subsys/mysql
+                       touch /var/lock/subsys/mysql-@mysqlversion@
                        return
                fi
        done
                        return
                fi
        done
-       rm -f /var/lock/subsys/mysql
+       rm -f /var/lock/subsys/mysql-@mysqlversion@
 }
 
 mysqlinit() {
 }
 
 mysqlinit() {
@@ -455,7 +445,7 @@ mysqlinit() {
                MYSQL_CONFIG="$MYSQL_CLUSTER_DIR/mysqld.conf"
        fi
 
                MYSQL_CONFIG="$MYSQL_CLUSTER_DIR/mysqld.conf"
        fi
 
-       show "Initializing MySQL cluster %s" "$clusterdir"; started
+       show "Initializing cluster %s" "$clusterdir"; started
 
        # Check if not exist init database
        if [ -d "$MYSQL_DATA_DIR/mysql" ]; then
 
        # Check if not exist init database
        if [ -d "$MYSQL_DATA_DIR/mysql" ]; then
@@ -465,7 +455,7 @@ mysqlinit() {
                exit 6
        fi
 
                exit 6
        fi
 
-       show "Installing MySQL system tables for $MYSQL_DATA_DIR"
+       show "Initializing MySQL database for $MYSQL_DATA_DIR"
        busy
        TMP=/tmp TMPDIR=/tmp
 
        busy
        TMP=/tmp TMPDIR=/tmp
 
@@ -487,33 +477,44 @@ mysqlinit() {
        fi
 
        ok=0
        fi
 
        ok=0
-       /usr/sbin/mysqld \
+       @mysqlsbindir@/mysqld \
                --defaults-file=$MYSQL_CLUSTER_DIR/mysqld.conf \
                --initialize-insecure \
                --skip-grant-tables \
                --datadir=$MYSQL_DATA_DIR \
                --user=$MYSQL_USER \
                --defaults-file=$MYSQL_CLUSTER_DIR/mysqld.conf \
                --initialize-insecure \
                --skip-grant-tables \
                --datadir=$MYSQL_DATA_DIR \
                --user=$MYSQL_USER \
-               --slave-load-tmpdir=$MYSQL_DATA_DIR \
+               --replica-load-tmpdir=$MYSQL_DATA_DIR \
                --tmpdir=$MYSQL_DATA_DIR \
                --tmpdir=$MYSQL_DATA_DIR \
-               --log-error=$MYSQL_ERRLOG && ok=1
-       [ -f $MYSQL_DATA_DIR/mysql/user.frm ] || ok=0
+               --log-error=$MYSQL_ERRLOG \
+               && ok=1
+       [ -f $MYSQL_DATA_DIR/mysql.ibd ] || ok=0
 
        if [ "$ok" = 1 ]; then
                ok
                cat << END_OF_MSG
 
 
        if [ "$ok" = 1 ]; then
                ok
                cat << END_OF_MSG
 
-PLEASE REMEMBER TO SET A PASSWORD FOR THE mysql USERS!
-This is done, after starting database, in the order shown below,
-with:
+PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL USERS!
+
+Start database:
+$ service mysql-@mysqlversion@ start
+
+and set passwords:
+
+For 'root' user (ALL privileges, DB admin), paste command with new password:
+ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
+FLUSH PRIVILEGES;
+
+For 'mysql_sysadmin' (RELOAD, SHUTDOWN and REPLICATION CLIENT privileges):
+CREATE USER 'mysql_sysadmin'@'localhost' IDENTIFIED BY 'sysnewpassword' PASSWORD EXPIRE NEVER;
+GRANT RELOAD, SHUTDOWN, REPLICATION CLIENT ON *.* TO 'mysql_sysadmin'@'localhost';
+FLUSH PRIVILEGES;
 
 
-Add 'mysql_sysadmin' user (RELOAD and SHUTDOWN privileges):
-echo "CREATE USER 'mysql_sysadmin'@'localhost' IDENTIFIED BY 'SOME_RANDOM_PASSWORD'; FLUSH PRIVILEGES;" | mysql --ssl-mode=DISABLED -u root -S $MYSQL_SOCKET
-echo "GRANT RELOAD, SHUTDOWN ON *.* TO 'mysql_sysadmin'@'localhost'; FLUSH PRIVILEGES;" | mysql --ssl-mode=DISABLED -u root -S $MYSQL_SOCKET
 
 
-Set password for root user (ALL privileges, DB admin):
-echo "ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword'; FLUSH PRIVILEGES;" | mysql --ssl-mode=DISABLED -u root -S $MYSQL_SOCKET
+Both into command:
+$ mysql -u root -p --ssl-mode=disabled -S $MYSQL_SOCKET
 
 
-NOTE: mysql_sysadmin password should be placed to $MYSQL_CONFIG in
+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)
 
 mysqladmin section. See the manual for more instructions.
 (This user is used at logs rotation and server shutdown)
 
@@ -523,14 +524,14 @@ END_OF_MSG
                cat << END_OF_MSG
 ERROR:
 ERROR:
                cat << END_OF_MSG
 ERROR:
 ERROR:
-ERROR: Initialization of server FAILED!
+ERROR: Installation FAILED!
 ERROR:
 ERROR:
 
 ERROR:
 ERROR:
 
-Examine the logs in /var/log/mysql for more information. You can
+Examine the logs in $MYSQL_ERRLOG for more information. You can
 also try to start the mysqld daemon with:
 
 also try to start the mysqld daemon with:
 
-/usr/sbin/mysqld --skip-grant &
+@mysqlsbindir@/mysqld --skip-grant &
 
 You can use the command line tool mysql to connect to the mysql
 database and look at the grant tables:
 
 You can use the command line tool mysql to connect to the mysql
 database and look at the grant tables:
@@ -539,11 +540,12 @@ shell> mysql -u root mysql
 mysql> show tables
 
 Try 'mysqld --help' if you have problems with paths. Setting on
 mysql> show tables
 
 Try 'mysqld --help' if you have problems with paths. Setting on
-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 https://www.percona.com/software/mysql-database/mysql.
+logging in $MYSQL_DATA_DIR/mysqld.conf gives you a log in
+/var/log/mysql/@mysqlversion/query.log that may be helpful.
+The latest information about MySQL is available on the web at
+http://www.mysql.com/.
 
 
-Please check TLD Linux ftp site for newer versions of this package.
+Please check TLD Linux 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
 
 Please consult the MySQL manual section: 'Problems running
 mysql_install_db', and the manual section that describes problems on
@@ -554,13 +556,13 @@ END_OF_MSG
        fi
 
        # if it's first server, register as default
        fi
 
        # if it's first server, register as default
-       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
+       if [ ! -e /var/lib/mysql/@mysqlversion@/mysql.sock ] || [ -L /var/lib/mysql/@mysqlversion@/mysql.sock ] && [ -z "$(readlink /var/lib/mysql/@mysqlversion@/mysql.sock)" ]; then
+               sock=${MYSQL_SOCKET#/var/lib/mysql/@mysqlversion@/} # make it relative if possible
+               ln -s "$sock" /var/lib/mysql/@mysqlversion@/mysql.sock
        fi
        # same for config, move to /etc
        fi
        # same for config, move to /etc
-       if [ ! -e /etc/mysql/mysqld.conf ]; then
-               mv "$MYSQL_CLUSTER_DIR/mysqld.conf" /etc/mysql/mysqld.conf
+       if [ ! -e /etc/mysql/@mysqlversion@/mysqld.conf ]; then
+               mv "$MYSQL_CLUSTER_DIR/mysqld.conf" /etc/mysql/@mysqlversion@/mysqld.conf
        fi
 }
 
        fi
 }
 
@@ -595,7 +597,7 @@ stop() {
 }
 
 condrestart() {
 }
 
 condrestart() {
-       if [ ! -f /var/lock/subsys/mysql ]; then
+       if [ ! -f /var/lock/subsys/mysql-@mysqlversion@ ]; then
                msg_not_running "MySQL"
                RETVAL=$1
                return
                msg_not_running "MySQL"
                RETVAL=$1
                return
@@ -614,7 +616,7 @@ status() {
                        RETVAL=0
                        addr=${MYSQL_BIND_ADDRESS:-0.0.0.0}
                        port=${MYSQL_PORT:-3306}
                        RETVAL=0
                        addr=${MYSQL_BIND_ADDRESS:-0.0.0.0}
                        port=${MYSQL_PORT:-3306}
-                       socket=${MYSQL_SOCKET:-/var/lib/mysql/mysql.sock}
+                       socket=${MYSQL_SOCKET:-/var/lib/mysql/@mysqlversion@/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"
                        pid=$MYSQL_PID
                        nls "MySQL cluster %s, pid %s\n" "$mysqldir" "$pid"
                        [ -z "$MYSQL_SKIP_NETWORKING" ] && nls "\ttcp:%s:%s\n" "$addr" "$port"
@@ -648,7 +650,7 @@ status() {
                        if [ "$MYSQL_STATUS" = "running" ]; then
                                addr=${MYSQL_BIND_ADDRESS:-0.0.0.0}
                                port=${MYSQL_PORT:-3306}
                        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}
+                               socket=${MYSQL_SOCKET:-/var/lib/mysql/@mysqlversion@/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 "MySQL cluster %s, pid %s\n" "$mysqldir" "$pid"
                                [ -z "$MYSQL_SKIP_NETWORKING" ] && nls "\ttcp:%s:%s\n" "$addr" "$port"
                                nls "\tunix: %s\n" "$socket"
@@ -693,8 +695,8 @@ case "$action" in
        for mysqldir in $DB_CLUSTERS; do
                mysqlgetconfig "$mysqldir"
                # just if mysqld is really running
        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
-                       /usr/bin/mysqladmin --defaults-file="$MYSQL_CONFIG" --socket="$MYSQL_SOCKET" flush-logs
+               if @mysqlbindir@/mysqladmin --defaults-file="$MYSQL_CONFIG" --socket="$MYSQL_SOCKET" ping >/dev/null 2>&1; then
+                       @mysqlbindir@/mysqladmin --defaults-file="$MYSQL_CONFIG" --socket="$MYSQL_SOCKET" flush-logs
                fi
        done
        ;;
                fi
        done
        ;;