diff --git a/install_mariadb.sh b/install_mariadb.sh index eb17188..557c6fb 100755 --- a/install_mariadb.sh +++ b/install_mariadb.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash -_MARIADB_VERSION=10.1.24 +_backup_date="$(date +"%Y-%m-%d-%H%M")" + +_MARIADB_VERSION=10.2.13 _MARIADB_SRC_BASE_DIR="$(realpath $(dirname $0))" @@ -15,7 +17,6 @@ _MARIADB_GROUP=mysql _DISTRIBUTION=Debian -#_VSERVER_GUEST=ja _VSERVER_GUEST=nein _required_debian_packages="libevent-dev @@ -26,8 +27,10 @@ _required_debian_packages="libevent-dev libpam0g-dev libpcre3-dev libgroonga-dev + gnutls-dev default-jdk" +_CRONTAB_BAKUP_FILE="$(mktemp)" ## - Let make use multiple cores (-j) ## - @@ -36,6 +39,16 @@ export MAKEFLAGS=-j$(expr `grep "^processor" /proc/cpuinfo | sort -u | wc -l` + ## --- Some functions ## --- +clean_up() { + + # Perform program exit housekeeping + if [[ -s "$_CRONTAB_BAKUP_FILE" ]]; then + crontab -u root $_CRONTAB_BAKUP_FILE + fi + rm -f $_CRONTAB_BAKUP_FILE + exit $1 +} + echononl(){ echo X\\c > /tmp/shprompt$$ if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then @@ -67,6 +80,12 @@ warn (){ echo "" } +info (){ + echo "" + echo -e "\t[ \033[32m\033[1mInfo\033[m ]: $*" + echo "" +} + echo_ok() { echo -e "\033[75G[ \033[32mok\033[m ]" @@ -82,6 +101,8 @@ echo_skipped() { ## --- ## --- END: functions +trap clean_up SIGHUP SIGINT SIGTERM + _curdir=`pwd` @@ -95,6 +116,16 @@ if [ "$(id -u)" != "0" ]; then fatal Skript muss als \"root\" ausgeführt werden fi +# - OS supports systemd ? +# - +_systemd="$(which systemd)" +_systemctl="$(which systemctl)" +if [[ -z "$_systemd" ]] && [[ -z "$_systemctl" ]]; then + SYSTEMD_EXISTS=false +else + SYSTEMD_EXISTS=true +fi + DISTRIBUTION= echo "" echo -e "\033[32m--\033[m" @@ -153,10 +184,23 @@ else UPDATE_MARIADB=false fi +if $UPDATE_MARIADB ; then + echo "" + echononl "Get current MARIADB Version.." + CURRENT_VERSION="$(mysql -V | grep -o -E "Distrib\s+[0-9]+\.[0-9]+\.[0-9]+" | awk '{print$2}')" + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + fatal "Getting current mariadb version failed!" + fi + echo "" +fi -clear -echo -e "\033[21G\033[32mInstallationsscript für die MariaDB Datenbank \033[m" -echo "" + +#clear +#echo -e "\033[21G\033[32mInstallationsscript für die MariaDB Datenbank \033[m" +#echo "" echo -e "\033[32m--\033[m" echo "" echo "Gib die Versionsnummer der MariaDB-Distribution an." @@ -174,7 +218,11 @@ do _MARIADB_DATA_DIR=/data/mariadb-$MARIADB_VERSION distfile=mariadb-${MARIADB_VERSION}.tar.gz done -MARIADB_MAJOR_VERSION=`echo $MARIADB_VERSION | cut -d '.' -f1,2` +MARIADB_MAIN_VERSION=`echo $MARIADB_VERSION | cut -d '.' -f1,2` +MARIADB_MAJOR_VERSION=`echo $MARIADB_VERSION | cut -d '.' -f1` +MARIADB_MINOR_VERSION=`echo $MARIADB_VERSION | cut -d '.' -f2` +MARIADB_PATCH_LEVEL=`echo $MARIADB_VERSION | cut -d '.' -f2` + echo "" echo -e "\033[32m--\033[m" @@ -211,6 +259,21 @@ do done +MY_CNF_FILE="${MARIADB_INSTALL_DIR}/etc/my.cnf" + +if $UPDATE_MARIADB ; then + echo "" + echononl "Ermittle Installations Verz. der existierenden MARIADB Installation." + if [[ -d "$(dirname "$MARIADB_INSTALL_DIR")/maria-$CURRENT_VERSION" ]]; then + MARIADB_CUR_INSTALL_DIR="$(dirname "$MARIADB_INSTALL_DIR")/maria-$CURRENT_VERSION" + echo_ok + else + echo_failed + fatal "Kann Installations Verz. der z.Zt. installierten Version nicht finden!" + fi + echo "" +fi + echo "" echo -e "\033[32m--\033[m" echo "" @@ -226,6 +289,20 @@ do fi done +if $UPDATE_MARIADB ; then + echo "" + echononl "Ermittle MARIADB-Datenbank Verz. der existierenden MARIADB Installation." + if [[ -d "$(dirname "$MARIADB_DATA_DIR")/maria-$CURRENT_VERSION" ]]; then + MARIADB_CUR_DATA_DIR="$(dirname "$MARIADB_DATA_DIR")/maria-$CURRENT_VERSION" + echo_ok + else + echo_failed + fatal "Kann Datenbank Verz. der installierten Version nicht finden!" + fi + echo "" +fi + + echo "" echo -e "\033[32m--\033[m" echo "" @@ -295,12 +372,17 @@ do fi done -clear -echo -e "\033[21G\033[32mInstallationsscript für die MariaDB Datenbank \033[m" +#clear +#echo -e "\033[21G\033[32mInstallationsscript für die MariaDB Datenbank \033[m" + echo "" echo -e "\033[32m--\033[m" echo "" -echo "Gib ein Passwort für den root user an.." +if ! $UPDATE_MARIADB ; then + echo "Gib ein Passwort für den root user an.." +else + echo "Gib das 'root' Passwort der bestehenden Installation an" +fi echo "" _MARIADB_ROOT_PW_1="X" _MARIADB_ROOT_PW_2="Y" @@ -323,51 +405,35 @@ do if [ "$_MARIADB_ROOT_PW_1" != "$_MARIADB_ROOT_PW_2" ];then echo -e "\n\t\033[33m\033[1mPassworteingaben sind nicht identisch!\033[m\n" else - MARIADB_ROOT_PW=$_MARIADB_ROOT_PW_1 + if $UPDATE_MARIADB ; then + if $(pgrep mysqld_safe > /dev/null 2>&1) || $(pgrep mysqld > /dev/null 2>&1); then + if $(mysql --user="root" --password="$_MARIADB_ROOT_PW_1" -N -s -e 'quit' > /dev/null 2>&1) ; then + MARIADB_ROOT_PW=$_MARIADB_ROOT_PW_1 + else + echo -e "\n\t\033[33m\033[1mFalsches Passwort\033[m\n" + _MARIADB_ROOT_PW_1="" + fi + else + MARIADB_ROOT_PW=$_MARIADB_ROOT_PW_1 + fi + else + MARIADB_ROOT_PW=$_MARIADB_ROOT_PW_1 + fi fi done -if $UPDATE_MARIADB ; then - __SYMLINK_INITSCRIPT=nein - __SYMLINK_INSTALL_DIR=nein - __SYMLINK_DATA_DIR=nein -else - __SYMLINK_INITSCRIPT=ja - __SYMLINK_INSTALL_DIR=ja - __SYMLINK_DATA_DIR=ja -fi -clear -echo -e "\033[21G\033[32mInstallationsscript für die MariaDB Datenbank \033[m" -echo "" +__SYMLINK_INSTALL_DIR=ja +__SYMLINK_DATA_DIR=ja + echo -e "\033[32m--\033[m" echo "" echo "Symlinks:" echo "" echo " - Setze Symlink für das Init Skript (/etc/init.d/mysql.server)" echo " - Setze Sysmlink for das Installationsverzeichnis `dirname $MARIADB_INSTALL_DIR`/mysql" -echo " - Setze Sysmlink for das Datenverzeichnis `dirname $MARIADB_DATA_DIR`/mysql" echo "" -_SYMLINK_INITSCRIPT="" -echononl "Sysmlink für das Init Skript? (ja/nein) [${__SYMLINK_INITSCRIPT}]: " -read _SYMLINK_INITSCRIPT -if [ "X$_SYMLINK_INITSCRIPT" = "X" ];then - _SYMLINK_INITSCRIPT=$__SYMLINK_INITSCRIPT -fi -while [ "$_SYMLINK_INITSCRIPT" != "ja" \ - -a "$_SYMLINK_INITSCRIPT" != "Ja" \ - -a "$_SYMLINK_INITSCRIPT" != "nein" \ - -a "$_SYMLINK_INITSCRIPT" != "Nein" ]; do - echononl "Falsche Eingabe. (ja/nein): " - read _SYMLINK_INITSCRIPT -done -if [ "$_SYMLINK_INITSCRIPT" = "ja" -o "$_SYMLINK_INITSCRIPT" = "Ja" ]; then - SYMLINK_INITSCRIPT=true -else - SYMLINK_INITSCRIPT=false -fi - echo "" _SYMLINK_INSTALL_DIR="" echononl "Sysmlink für das Installationsverzeichnis? (ja/nein) [${__SYMLINK_INSTALL_DIR}]: " @@ -376,10 +442,8 @@ if [ "X$_SYMLINK_INSTALL_DIR" = "X" ];then _SYMLINK_INSTALL_DIR=$__SYMLINK_INSTALL_DIR fi -while [ "$_SYMLINK_INSTALL_DIR" != "ja" \ - -a "$_SYMLINK_INSTALL_DIR" != "Ja" \ - -a "$_SYMLINK_INSTALL_DIR" != "nein" \ - -a "$_SYMLINK_INSTALL_DIR" != "Nein" ]; do +_SYMLINK_INSTALL_DIR="$(echo "$_SYMLINK_INSTALL_DIR" | tr '[:upper:]' '[:lower:]')" +while [ "$_SYMLINK_INSTALL_DIR" != "ja" -a "$_SYMLINK_INSTALL_DIR" != "nein" ]; do echononl "Falsche Eingabe. (ja/nein): " read _SYMLINK_INSTALL_DIR done @@ -397,10 +461,8 @@ if [ "X$_SYMLINK_DATA_DIR" = "X" ];then _SYMLINK_DATA_DIR=$__SYMLINK_DATA_DIR fi -while [ "$_SYMLINK_DATA_DIR" != "ja" \ - -a "$_SYMLINK_DATA_DIR" != "Ja" \ - -a "$_SYMLINK_DATA_DIR" != "nein" \ - -a "$_SYMLINK_DATA_DIR" != "Nein" ]; do +__SYMLINK_DATA_DIR="$(echo "$_SYMLINK_DATA_DIR" | tr '[:upper:]' '[:lower:]')" +while [ "$_SYMLINK_DATA_DIR" != "ja" -a "$_SYMLINK_DATA_DIR" != "nein" ]; do echononl "Falsche Eingabe. (ja/nein): " read _SYMLINK_DATA_DIR done @@ -432,12 +494,62 @@ while [ "X$OK" != "Xja" -a "X$OK" != "Xnein" ]; do done if [ "$OK" = "ja" ]; then SYSTEMD_EXISTS=false + VSERVER_GUEST=true else - if [ "X`which systemd`" = "X" ]; then - SYSTEMD_EXISTS=false - else - SYSTEMD_EXISTS=true - fi + VSERVER_GUEST=false +fi + + + + + +if $SYSTEMD_EXISTS ; then + INSTALL_SYSTEMD_SERVICE="" + echo "" + echo -e "\033[32m--\033[m" + echo "" + echo "Wie soll der MariaDB (mysql) Datenbank Service getsartet werden?" + echo "" + echo "[1] SysVinit script mysql.server" + echo -e "[2] \033[37m\033[1mSystemd service mysqld.service\033[m" + echo "" + echo "" + echo "Type a number or press to choose highlighted value" + echo "" + echononl "Eingabe: " + + while [[ "$INSTALL_SYSTEMD_SERVICE" != "true" ]] && [[ "$INSTALL_SYSTEMD_SERVICE" != "false" ]]; do + + #while [[ -z "$INSTALL_SYSTEMD_SERVICE" ]];do + read OPTION + case $OPTION in + 1) INSTALL_SYSTEMD_SERVICE=false + ;; + 2) INSTALL_SYSTEMD_SERVICE=true + ;; + '') INSTALL_SYSTEMD_SERVICE=true + ;; + *) echo "" + echo -e "\tFalsche Eingabe ! [ 1 = Systemd Service ; 2 = SysVinit Script ]" + echo "" + echononl "Eingabe:" + ;; + esac + done + +else + INSTALL_SYSTEMD_SERVICE=false +fi + + +MARIADB_SERVICE_FILE="" +MARIADB_SYSV_INIT_SCRIPT="" +SYSTEMD_PID_DIR="" +if $INSTALL_SYSTEMD_SERVICE ; then + MARIADB_SERVICE_FILE="mariadb.service" + SYSTEMD_PID_DIR="$MARIADB_DATA_DIR" +else + MARIADB_SYSV_INIT_SCRIPT="mysql.server" fi @@ -448,15 +560,21 @@ if ! $UPDATE_MARIADB ; then echo -e "-- \033[33m\033[1mNeusistallation\033[m --" else echo -e "-- \033[33m\033[1mUpdate\033[m (Erstzen einer vorhandenen Installation) --" + echo "" + echo "Current MariaDB Version...: $CURRENT_VERSION" + echo "Current data dir..........: $MARIADB_CUR_DATA_DIR" + echo "Current installation dir..: $MARIADB_CUR_INSTALL_DIR" + echo "" fi echo "" echo "Linuxdistribution.........: $DISTRIBUTION" echo "" echo "MariaDB Versionsnummer....: $MARIADB_VERSION" -echo " MariaDB Major Verion....: $MARIADB_MAJOR_VERSION" +echo " MariaDB Main Verion.....: $MARIADB_MAIN_VERSION" echo "" echo "Sourcecodeverzeicnis......: $MARIADB_SRC_BASE_DIR" echo "Installationsverzeichnis..: $MARIADB_INSTALL_DIR" +echo "Default file 'my.cnf'.....: $MY_CNF_FILE" echo "Datenbankverzeichnis......: $MARIADB_DATA_DIR" echo "Log Verzeichnis...........: $MARIADB_LOG_DIR" echo "TCP Port..................: $MARIADB_PORT" @@ -464,11 +582,20 @@ echo "Unix Socket...............: $MARIADB_UNIX_SOCKET" echo "MariaDB-User..............: $MARIADB_USER" echo "MariaDB-Gruppe............: $MARIADB_GROUP" echo "" -echo "Symlink Initskript........: $SYMLINK_INITSCRIPT" echo "Symlink Installationsverz.: $SYMLINK_INSTALL_DIR" echo "Symlink Datenverzeichnis..: $SYMLINK_DATA_DIR" echo "" -echo "Using systemd.............: $SYSTEMD_EXISTS" +echo "Systemd Unterstützung.....: $SYSTEMD_EXISTS" +if $INSTALL_SYSTEMD_SERVICE ; then + echo "Starmethode...............: Systemd Service" + echo "MariaDB Service File......: $MARIADB_SERVICE_FILE" + echo "Systemd pid directory.....: $SYSTEMD_PID_DIR" +else + echo "Starmethode...............: SysVinit Script" + echo "MariaDB SysyVinit Script..: $MARIADB_SYSV_INIT_SCRIPT" +fi +echo "" +echo "VServer guest system......: $VSERVER_GUEST" echo "" echononl "einverstanden [ja/nein]: " read OK @@ -484,8 +611,7 @@ done ## - Sorcecode Verzeichnis vorhanden? ## - if [ ! -d ${MARIADB_SRC_BASE_DIR} ] ; then - mkdir -p $MARIADB_SRC_BASE_DIR - #fatal "Kann MariaDB Sourcecode Verzeichnis \"${MARIADB_SRC_BASE_DIR}\" nicht finden." + fatal "Kann MariaDB Sourcecode Verzeichnis \"${MARIADB_SRC_BASE_DIR}\" nicht finden." fi @@ -507,6 +633,7 @@ if [ ! -f ${MARIADB_SRC_BASE_DIR}/$distfile ] ; then fi echo "" +echo "" ## - Erstelle Logverzeichnis @@ -537,15 +664,21 @@ if ! $UPDATE_MARIADB ; then echo "## - Neusistallation" >> ${logdir}/main.log else echo "## - Update (Erstzen einer vorhandenen Installation)" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "## - Current MariaDB Version...: $CURRENT_VERSION" >> ${logdir}/main.log + echo "## - Current installation dir..: $MARIADB_CUR_INSTALL_DIR" >> ${logdir}/main.log + echo "## - Current data dir..........: $MARIADB_CUR_DATA_DIR" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log fi echo "## -" >> ${logdir}/main.log echo "## - Linuxdistribution.........: $DISTRIBUTION" >> ${logdir}/main.log echo "## - " >> ${logdir}/main.log echo "## - MariaDB Versionsnummer....: $MARIADB_VERSION" >> ${logdir}/main.log -echo "## - MariaDB Major Verion...: $MARIADB_MAJOR_VERSION" >> ${logdir}/main.log +echo "## - MariaDB Main Verion....: $MARIADB_MAIN_VERSION" >> ${logdir}/main.log echo "## - " >> ${logdir}/main.log echo "## - Sourcecodeverzeicnis......: $MARIADB_SRC_BASE_DIR" >> ${logdir}/main.log echo "## - Installationsverzeichnis..: $MARIADB_INSTALL_DIR" >> ${logdir}/main.log +echo "## - Default file 'my.cnf'.....: $MY_CNF_FILE" >> ${logdir}/main.log echo "## - Datenbankverzeichnis......: $MARIADB_DATA_DIR" >> ${logdir}/main.log echo "## - Log Verzeichnis...........: $MARIADB_LOG_DIR" >> ${logdir}/main.log echo "## - TCP Port..................: $MARIADB_PORT" >> ${logdir}/main.log @@ -553,20 +686,37 @@ echo "## - Unix Socket...............: $MARIADB_UNIX_SOCKET" >> ${logdir}/main.l echo "## - MariaDB-User..............: $MARIADB_USER" >> ${logdir}/main.log echo "## - MariaDB-Gruppe............: $MARIADB_GROUP" >> ${logdir}/main.log echo "## - " >> ${logdir}/main.log -echo "## - Symlink Initskript........: $SYMLINK_INITSCRIPT" >> ${logdir}/main.log echo "## - Symlink Installationsverz.: $SYMLINK_INSTALL_DIR" >> ${logdir}/main.log echo "## - Symlink Datenverzeichnis..: $SYMLINK_DATA_DIR" >> ${logdir}/main.log -echo "## - " >> ${logdir}/main.log +echo "## -" >> ${logdir}/main.log +echo "## -" >> ${logdir}/main.log +echo "## - Systemd Unterstützung.....: $SYSTEMD_EXISTS" >> ${logdir}/main.log +if $INSTALL_SYSTEMD_SERVICE ; then + echo "## - Starmethode...............: Systemd Service" >> ${logdir}/main.log + echo "## - MariaDB Service File......: $MARIADB_SERVICE_FILE" >> ${logdir}/main.log + echo "## - Systemd pid directory.....: $SYSTEMD_PID_DIR" >> ${logdir}/main.log +else + echo "## - Starmethode...............: SysVinit Script" >> ${logdir}/main.log + echo "## - MariaDB SysyVinit Script..: $MARIADB_SYSV_INIT_SCRIPT" >> ${logdir}/main.log +fi +echo "## -" >> ${logdir}/main.log +echo "## - VServer guest system......: $VSERVER_GUEST" >> ${logdir}/main.log echo "" >> ${logdir}/main.log echo "" >> ${logdir}/main.log echo "UPDATE_MARIADB=$UPDATE_MARIADB" >> ${logdir}/main.log +if ! $UPDATE_MARIADB ; then + echo "CURRENT_VERSION=$CURRENT_VERSION" >> ${logdir}/main.log + echo "MARIADB_CUR_DATA_DIR=$MARIADB_CUR_DATA_DIR" >> ${logdir}/main.log + echo "MARIADB_CUR_INSTALL_DIR=$MARIADB_CUR_INSTALL_DIR" >> ${logdir}/main.log +fi echo "" >> ${logdir}/main.log echo "DISTRIBUTION=$DISTRIBUTION" >> ${logdir}/main.log echo "" >> ${logdir}/main.log echo "MARIADB_VERSION=$MARIADB_VERSION" >> ${logdir}/main.log echo "MARIADB_SRC_BASE_DIR=$MARIADB_SRC_BASE_DIR" >> ${logdir}/main.log echo "MARIADB_INSTALL_DIR=$MARIADB_INSTALL_DIR" >> ${logdir}/main.log +echo "MY_CNF_FILE=$MY_CNF_FILE" >> ${logdir}/main.log echo "MARIADB_DATA_DIR=$MARIADB_DATA_DIR" >> ${logdir}/main.log echo "MARIADB_LOG_DIR=$MARIADB_LOG_DIR" >> ${logdir}/main.log echo "MARIADB_PORT=$MARIADB_PORT" >> ${logdir}/main.log @@ -574,82 +724,303 @@ echo "MARIADB_UNIX_SOCKET=$MARIADB_UNIX_SOCKET" >> ${logdir}/main.log echo "MARIADB_USER=$MARIADB_USER" >> ${logdir}/main.log echo "MARIADB_GROUP=$MARIADB_GROUP" >> ${logdir}/main.log echo "" >> ${logdir}/main.log -echo "SYMLINK_INITSCRIPT=$SYMLINK_INITSCRIPT" >> ${logdir}/main.log echo "SYMLINK_INSTALL_DIR=$SYMLINK_INSTALL_DIR" >> ${logdir}/main.log echo "SYMLINK_DATA_DIR=$SYMLINK_DATA_DIR" >> ${logdir}/main.log -echo "" >> ${logdir}/main.log +echo "SYSTEMD_EXISTS=$SYSTEMD_EXISTS" >> ${logdir}/main.log +echo "INSTALL_SYSTEMD_SERVICE=$INSTALL_SYSTEMD_SERVICE" >> ${logdir}/main.log +echo "MARIADB_SERVICE_FILE=$MARIADB_SERVICE_FILE" >> ${logdir}/main.log +echo "SYSTEMD_PID_DIR=$SYSTEMD_PID_DIR" >> ${logdir}/main.log +echo "MARIADB_SYSV_INIT_SCRIPT=$MARIADB_SYSV_INIT_SCRIPT" >> ${logdir}/main.log +echo "VSERVER_GUEST=$VSERVER_GUEST" >> ${logdir}/main.log _MARIADB_INITSCRIPT= -if [ -f /etc/init.d/mysql.server ];then +if [ -f "/etc/init.d/$MARIADB_SYSV_INIT_SCRIPT" ];then + _MARIADB_INITSCRIPT="${MARIADB_SYSV_INIT_SCRIPT}" +elif [ -f /etc/init.d/mysql.server ];then _MARIADB_INITSCRIPT="mysql.server" elif [ -f /etc/init.d/mysql ];then _MARIADB_INITSCRIPT="mysql" fi -if ! $UPDATE_MARIADB ; then +_SYSTEMD_SERVICE_FILE= +if [[ -f "/etc/systemd/system/$MARIADB_SERVICE_FILE" ]]; then + _SYSTEMD_SERVICE_FILE="${MARIADB_SERVICE_FILE}" +elif [[ -f /etc/systemd/system/mysql.service ]] ; then + _SYSTEMD_SERVICE_FILE="mysql.service" +elif [[ -f /etc/systemd/system/mysqld.service ]] ; then + _SYSTEMD_SERVICE_FILE="mysqld.service" +fi - if [ "X${_MARIADB_INITSCRIPT}X" != "XX" ];then +if [[ -z "$_MARIADB_INITSCRIPT" ]] && [[ -z "$_SYSTEMD_SERVICE_FILE" ]] && $UPDATE_MARIADB ; then + fatal "Kein start/stop Sevice File/ Init Script gefunden.." +fi - PID=`ps aux | grep "mysqld_safe" | grep -v grep | awk '{print$2}'` - if [ "X${PID}X" != "XX" ];then - echononl "Stoppe mysql Server.." - echo "" >> ${logdir}/main.log - if $SYSTEMD_EXISTS ; then - echo "systemctl stop mysql.server" >> ${logdir}/main.log - systemctl stop mysql.server >> ${logdir}/main.log 2>&1 - else - echo "/etc/init.d/$_MARIADB_INITSCRIPT stop" >> ${logdir}/main.log - /etc/init.d/$_MARIADB_INITSCRIPT stop >> ${logdir}/main.log 2>&1 - fi - sleep 5 - PID=`ps aux | grep "mysqld_safe" | grep -v grep | awk '{print$2}'` - if [ "X${PID}X" = "XX" ]; then - echo_ok - else - echo_failed - PID=`ps aux | grep "mysqld" | grep -v grep | awk '{print$2}'` - echononl "Abbruch (kill -9) aller mysqld Prozesse.." - echo "" >> ${logdir}/main.log - echo "kill -9 $PID" >> ${logdir}/main.log 2>&1 - kill -9 $PID - if [ "$?" = "0" ]; then - echo_ok - else - echo_failed - fi - fi +## ----- +## - Doing some pre-installation tasks +## ----- +echo "" +echo "" +echo -e "\033[37m\033[1mDoing some pre-installation tasks..\033[m" +echo "" + +echo "" >> ${logdir}/main.log +echo "" >> ${logdir}/main.log +echo "## -----" >> ${logdir}/main.log +echo "## - Doing some pre-installation tasks" >> ${logdir}/main.log +echo "## -----" >> ${logdir}/main.log + + +echononl "Adding Group \"$MARIADB_GROUP\".." +if cat /etc/group | grep -e "^${MARIADB_GROUP}:" > /dev/null 2>&1 ; then + echo_skipped +else + echo "" >> ${logdir}/main.log + echo "## - Erstelle Gruppe \"$MARIADB_GROUP\"" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "groupadd -r $MARIADB_GROUP" >> ${logdir}/main.log + groupadd -r $MARIADB_GROUP >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + fatal Kann Gruppe \"${MARIADB_GROUP}\" nicht erstellen.. + fi +fi + +echononl "Adding User \"$MARIADB_USER\".." +if id -u $MARIADB_USER > /dev/null 2>&1; then + echo_skipped +else + echo "" >> ${logdir}/main.log + echo "## - Erstelle User \"$MARIADB_USER\"" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "useradd -r -M -d /noexistent -s /bin/false -g $MARIADB_GROUP $MARIADB_USER" >> ${logdir}/main.log + useradd -r -M -d /noexistent -s /bin/false -g $MARIADB_GROUP $MARIADB_USER >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + fatal Kann User \"${MARIADB_USER}\" nicht erstellen.. + fi +fi + +## - Disable crontab for user root +## - +_crontab_found=false +echononl "Backup crontab" +echo "" >> ${logdir}/main.log +echo "## - Backup crontab" >> ${logdir}/main.log +echo "## - " >> ${logdir}/main.log +echo "crontab -u root -l > $_CRONTAB_BAKUP_FILE" >> ${logdir}/main.log +crontab -u root -l >> $_CRONTAB_BAKUP_FILE 2>> ${logdir}/main.log +if [ "$?" = "0" ]; then + echo_ok + _crontab_found=true +else + if [[ ! -s "$_CRONTAB_BAKUP_FILE" ]] ; then + echo_skipped + warn "No crontab for user 'root'found." + else + echo_failed + error "Backup crontab failed" + fi +fi + +if $_crontab_found ; then + echononl "Disable crontab for user root" + echo "" >> ${logdir}/main.log + echo "## - Disable crontab for user root" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "crontab -r -u root" >> ${logdir}/main.log + crontab -r -u root >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + fi +fi + +## - Stop MariaDB Service if running +## - +echononl "Stop MariaDB Service.." +PIDS="$(ps aux | grep -E "(bin/mysqld_safe |bin/mysqld )" | grep -v grep | awk '{print$2}')" +if [[ "X${PIDS}X" != "XX" ]];then + echo "" >> ${logdir}/main.log + echo "## - Stop MySQL Service" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + if $SYSTEMD_EXISTS ; then + if [[ -n "$_SYSTEMD_SERVICE_FILE" ]] ; then + echo "systemctl stop ${_SYSTEMD_SERVICE_FILE}" >> ${logdir}/main.log + systemctl stop ${_SYSTEMD_SERVICE_FILE} >> ${logdir}/main.log 2>&1 + else + echo "systemctl stop ${_MARIADB_INITSCRIPT}" >> ${logdir}/main.log + systemctl stop ${_MARIADB_INITSCRIPT} >> ${logdir}/main.log 2>&1 fi + else + echo "/etc/init.d/$_MARIADB_INITSCRIPT stop" >> ${logdir}/main.log + /etc/init.d/$_MARIADB_INITSCRIPT stop >> ${logdir}/main.log 2>&1 + fi - ## - Entferne symbolische Links aus den Run Level Verzeichnissen - ## - - echononl "Entferne symbolische Links aus den Run Level Verzeichnissen" + sleep 5 + + PIDS="$(ps aux | grep -E "(bin/mysqld_safe |bin/mysqld )" | grep -v grep | awk '{print$2}')" + if [[ -z "${PIDS}" ]]; then + echo_ok + else + echo_failed + + echononl "Abbruch (kill -9) aller mysqld Prozesse.." echo "" >> ${logdir}/main.log - echo "update-rc.d -f $_MARIADB_INITSCRIPT remove" >> ${logdir}/main.log - update-rc.d -f $_MARIADB_INITSCRIPT remove >> ${logdir}/main.log 2>&1 + echo "## - Abbruch (kill -9) aller mysqld Prozesse" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + + declare -i i=0 + + while [[ -n "$PIDS" ]] ; do + + if [[ $i -gt 10 ]]; then + echo_failed + error "Killing remaining MySQL processes failed!" + break + fi + + for _PID in $PIDS ; do + echo "kill -9 $_PID" >> ${logdir}/main.log + kill -9 $_PID >> ${logdir}/main.log 2>&1 + done + + sleep 2 + + PIDS="$(ps aux | grep -E "(bin/mysqld_safe |bin/mysqld )" | grep -v grep | awk '{print$2}')" + (( i++ )) + done + + [[ $i -le 10 ]] && echo_ok + fi +else + echo_skipped +fi + +## ----- +## - Deactivate starting MySQL database service at boot time and +## - cleanup System from SysVinit script and/or Systemd service file +## ----- +if [[ -n "$_MARIADB_INITSCRIPT" ]] || [[ -n "$_SYSTEMD_SERVICE_FILE" ]]; then + echo "" + echo "" + echo -e "\033[37m\033[1mDeactivate starting MariaDB database service at boot time and" + echo -e "cleanup System from SysVinit script and/or Systemd service file.\033[m" + echo "" + + echo "" >> ${logdir}/main.log + echo "" >> ${logdir}/main.log + echo "## -----" >> ${logdir}/main.log + echo "## - Deactivate starting MariaDB database service at boot time and" >> ${logdir}/main.log + echo "## - cleanup System from SysVinit script and/or Systemd service file." >> ${logdir}/main.log + echo "## -----" >> ${logdir}/main.log +fi + +if [ "X${_MARIADB_INITSCRIPT}X" != "XX" ];then + + if [ -f "/etc/init.d/$_MARIADB_INITSCRIPT" ]; then + echononl "Entferne existierendes Initskript" + echo "" >> ${logdir}/main.log + echo "## - Entferne existierendes Initskript" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "rm -f /etc/init.d/$_MARIADB_INITSCRIPT" >> ${logdir}/main.log + rm -f /etc/init.d/$_MARIADB_INITSCRIPT >> ${logdir}/main.log 2>&1 if [ "$?" = "0" ]; then echo_ok else echo_failed - fatal "Kann symbolische Links (Run Level Verzeichnisse) nicht entfernen." - fi - - if [ -f "/etc/init.d/$_MARIADB_INITSCRIPT" ]; then - echononl "Entferne existierendes Initskript" - echo "" >> ${logdir}/main.log - echo "rm -f /etc/init.d/$_MARIADB_INITSCRIPT" >> ${logdir}/main.log - rm -f /etc/init.d/$_MARIADB_INITSCRIPT >> ${logdir}/main.log 2>&1 - if [ "$?" = "0" ]; then - echo_ok - else - echo_failed - fatal "Kann Mexistierendes Initskript nicht entfernen." - fi + fatal "Kann existierendes Initskript nicht entfernen." fi fi + ## - Entferne symbolische Links aus den Run Level Verzeichnissen + ## - + echononl "Entferne symbolische Links aus den Run Level Verzeichnissen" + echo "" >> ${logdir}/main.log + echo "## - Entferne symbolische Links aus den Run Level Verzeichnissen" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "update-rc.d -f $_MARIADB_INITSCRIPT remove" >> ${logdir}/main.log + update-rc.d -f $_MARIADB_INITSCRIPT remove >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + fatal "Kann symbolische Links (Run Level Verzeichnisse) nicht entfernen." + fi +fi + +if [[ -n "$_SYSTEMD_SERVICE_FILE" ]]; then + + echononl "Deaktiviere Systemd Service \"$_SYSTEMD_SERVICE_FILE\".." + echo "" >> ${logdir}/main.log + echo "## - Deaktiviere Systemd Service \"$_SYSTEMD_SERVICE_FILE\"" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "systemctl disable \"$_SYSTEMD_SERVICE_FILE\"" >> ${logdir}/main.log + + systemctl disable "$_SYSTEMD_SERVICE_FILE" >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + fatal "Kann Systemd Service \"$_SYSTEMD_SERVICE_FILE\" nicht deaktivieren!" + fi + + echononl "Entferne Systemd Service \"etc/systemd/system/${_SYSTEMD_SERVICE_FILE}\".." + echo "" >> ${logdir}/main.log + echo "## - Enferne datei \"/etc/systemd/system/${_SYSTEMD_SERVICE_FILE}\"" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "rm \"/etc/systemd/system/${_SYSTEMD_SERVICE_FILE}\"" >> ${logdir}/main.log + + rm "/etc/systemd/system/${_SYSTEMD_SERVICE_FILE}" >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + fatal "Kann existierendes Initskript nicht entfernen." + fi + + echononl "Reload Systemd Daemon" + echo "" >> ${logdir}/main.log + echo "## - Reload Systemd Daemon" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "systemctl daemon-reload" >> ${logdir}/main.log + + systemctl daemon-reload >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error "Kann Systemd Daemon nicht reloaden." + fi + + +fi + + +## ----- +## - Install needed debian packages +## ----- + +if ! $UPDATE_MARIADB ; then + + echo "" + echo "" + echo -e "\033[37m\033[1mInstall needed debian packages\033[m" + echo "" + + echo "" >> ${logdir}/main.log + echo "" >> ${logdir}/main.log + echo "## -----" >> ${logdir}/main.log + echo "## - Install needed debian packages" >> ${logdir}/main.log + echo "## -----" >> ${logdir}/main.log + ## - Uninstall debian mysql packages if installed ## - if [ "$DISTRIBUTION" = "Debian" ]; then @@ -662,21 +1033,45 @@ if ! $UPDATE_MARIADB ; then if [ -n "$INSTALLED_MYSQL_DEB" ]; then echo "" >> ${logdir}/main.log echo "apt-get remove --purge -q -y $INSTALLED_MYSQL_DEB" >> ${logdir}/main.log - apt-get remove --purge -q -y $INSTALLED_MYSQL_DEB >> ${logdir}/main.log 2>&1 + apt-get remove --purge -q -y $INSTALLED_MYSQL_DEB >> ${logdir}/main.log 2>&1 if [ "$?" = "0" ]; then echo_ok else echo_failed - fatal Kann MySQL Packete nicht deinstalieren.. + fatal Kann MySQL Pakete nicht deinstalieren.. fi else echo_skipped fi fi +# if [[ -d /etc/mysql ]]; then +# +# echononl "Sichere/Verschiebe exitierendes Verzeichnis /etc/mysql .." +# echo "" >> ${logdir}/main.log +# echo "## - Sichere/Verschiebe exitierendes Verzeichnis /etc/mysql" >> ${logdir}/main.log +# echo "## -" >> ${logdir}/main.log +# echo "mv /etc/mysql \"/etc/mysql.${_backup_date}\"" >> ${logdir}/main.log +# mv /etc/mysql "/etc/mysql.${_backup_date}" >> ${logdir}/main.log +# if [[ $? -eq 0 ]]; then +# echo_ok +# else +# echo_failed +# fatal "Kann Verzeichnis '/etc/mysql' nicht sichern!" +# fi +# +# fi # if [[ -d /etc/mysql ]]; then + echononl "Update index files of the debian repositories" - echo "apt-get update" >> ${logdir}/apt-install.log + echo "" >> ${logdir}/main.log + echo "## - Update index files of the debian repositories" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "## - See: ${logdir}/apt-install.log" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "apt-get update" >> ${logdir}/main.log + + echo "apt-get update" >> ${logdir}/apt-install.log apt-get update >> ${logdir}/apt-install.log 2>&1 if [ "$?" = "0" ]; then echo_ok @@ -686,11 +1081,18 @@ if ! $UPDATE_MARIADB ; then fatal "\"apt-get update\" failed!" fi + ## - Install cmake if not exists ## echononl "Installing \"cmake\".." _cmake=`which cmake` if [ "X$_cmake" = "X" ]; then + echo "" >> ${logdir}/main.log + echo "## - Installing \"cmake\"" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "## - See: ${logdir}/apt-install.log" >> ${logdir}/main.log + echo "DEBIAN_FRONTEND=noninteractive apt-get install -q -y cmake" >> ${logdir}/main.log + echo "DEBIAN_FRONTEND=noninteractive apt-get install -q -y cmake" >> ${logdir}/apt-install.log DEBIAN_FRONTEND=noninteractive apt-get install -q -y cmake >> ${logdir}/apt-install.log 2>&1 if [ "$?" = "0" ]; then @@ -704,34 +1106,6 @@ if ! $UPDATE_MARIADB ; then echo_skipped fi - ## - Install dependency packages for \"mysql-server\" - ## - - echononl "Installing dependency packages for \"mysql-server\"" - echo "DEBIAN_FRONTEND=noninteractive apt-get -q -y build-dep mysql-server" >> ${logdir}/apt-install.log 2>&1 - - DEBIAN_FRONTEND=noninteractive apt-get -q -y build-dep mysql-server >> ${logdir}/apt-install.log 2>&1 - if [ "$?" = 0 ]; then - echo_ok - echo "" >> ${logdir}/apt-install.log - else - echo_failed - fatal "Installing dependency packages for \"mysql-server\" failed!" - fi - - if apt-cache search mariadb-server | grep -q -E "^mariadb-server" > /dev/null 2>&1 ; then - echononl "Installing dependency packages for \"mariadb-server\"" - echo "DEBIAN_FRONTEND=noninteractive apt-get -q -y build-dep mariadb-server" >> ${logdir}/apt-install.log 2>&1 - - DEBIAN_FRONTEND=noninteractive apt-get -q -y build-dep mariadb-server >> ${logdir}/apt-install.log 2>&1 - if [ "$?" = 0 ]; then - echo_ok - echo "" >> ${logdir}/apt-install.log - else - echo_failed - fatal "Installing dependency packages for \"mariadb-server\" failed!" - fi - fi - ## - Install further debian packages ## - declare -a deb_package_arr @@ -743,6 +1117,12 @@ if ! $UPDATE_MARIADB ; then echononl "Installing $_debian_pkg .." if ! dpkg -l $_debian_pkg 2> /dev/null | grep -e "^ii" > /dev/null 2>&1 ; then + echo "" >> ${logdir}/main.log + echo "## - Installing $_debian_pkg" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "## - See: ${logdir}/apt-install.log" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "DEBIAN_FRONTEND=noninteractive apt-get install -q -y $_debian_pkg" >> ${logdir}/main.log echo "" >> ${logdir}/apt-install.log echo "DEBIAN_FRONTEND=noninteractive apt-get install -q -y $_debian_pkg" >> ${logdir}/apt-install.log @@ -753,10 +1133,7 @@ if ! $UPDATE_MARIADB ; then echo "" >> ${logdir}/apt-install.log else echo_failed - error "Installing debian package \"$_debian_pkg\" failed!" - if [[ "$_debian_pkg" = "default-jdk" ]]; then - warn "Maybe deinstallation of \"hdparm\" solved this problem " - fi + fatal "Installing debian package \"$_debian_pkg\" failed!" fi else echo_skipped @@ -768,50 +1145,150 @@ if ! $UPDATE_MARIADB ; then export JAVA_HOME=/usr/lib/jvm/default-java fi - echononl "Adding Group \"$MARIADB_GROUP\".." - if cat /etc/group | grep -e "^${MARIADB_GROUP}:" > /dev/null 2>&1 ; then - echo_skipped - else - groupadd -r $MARIADB_GROUP > ${logdir}/groupadd.log 2>&1 - if [ "$?" = "0" ]; then - echo_ok - else - echo_failed - fatal Kann Gruppe \"${MARIADB_GROUP}\" nicht erstellen.. - fi - fi - - echononl "Adding User \"$MARIADB_USER\".." - if id -u $MARIADB_USER > /dev/null 2>&1; then - echo_skipped - else - useradd -r -M -d /noexistent -s /bin/false -g $MARIADB_GROUP $MARIADB_USER > ${logdir}/useradd.log 2>&1 - if [ "$?" = "0" ]; then - echo_ok - else - echo_failed - fatal Kann User \"${MARIADB_USER}\" nicht erstellen.. - fi - fi -fi - - -if [ -d $MARIADB_DATA_DIR ]; then - echononl "Verschiebe exitierendes MariaDB Datenbank-Verzeichnis ..." + ## - Install dependency packages for \"mariadb-server\" + ## - + echononl "Installing dependency packages for \"mariadb-server\"" echo "" >> ${logdir}/main.log - echo "mv $MARIADB_DATA_DIR ${MARIADB_DATA_DIR}.`date +\"%Y%m%d-%H%M\"`" >> ${logdir}/main.log - mv $MARIADB_DATA_DIR ${MARIADB_DATA_DIR}.`date +"%Y%m%d-%H%M"` >> ${logdir}/main.log 2>&1 - if [ "$?" = "0" ]; then + echo "## - Installing dependency packages for \"mariadb-server\"" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "## - See: ${logdir}/apt-install.log" >> ${logdir}/main.log + echo "## - " >> ${logdir}/main.log + echo "DEBIAN_FRONTEND=noninteractive apt-get -q -y build-dep mariadb-server" >> ${logdir}/main.log + + echo "" >> ${logdir}/apt-install.log + echo "DEBIAN_FRONTEND=noninteractive apt-get -q -y build-dep mariadb-server" >> ${logdir}/apt-install.log 2>&1 + + DEBIAN_FRONTEND=noninteractive apt-get -q -y build-dep mariadb-server >> ${logdir}/apt-install.log 2>&1 + if [ "$?" = 0 ]; then echo_ok + echo "" >> ${logdir}/apt-install.log else echo_failed - fatal Kann Datenbank-Verzeichnis \"${MARIADB_DATA_DIR}\" nicht verschieben.. + fatal "Installing dependency packages for \"mariadb-server\" failed!" + fi + +# if apt-cache search mariadb-server | grep -q -E "^mariadb-server" > /dev/null 2>&1 ; then +# echononl "Installing dependency packages for \"mariadb-server\"" +# echo "DEBIAN_FRONTEND=noninteractive apt-get -q -y build-dep mariadb-server" >> ${logdir}/apt-install.log 2>&1 +# +# DEBIAN_FRONTEND=noninteractive apt-get -q -y build-dep mariadb-server >> ${logdir}/apt-install.log 2>&1 +# if [ "$?" = 0 ]; then +# echo_ok +# echo "" >> ${logdir}/apt-install.log +# else +# echo_failed +# fatal "Installing dependency packages for \"mariadb-server\" failed!" +# fi +# fi + +fi # if ! $UPDATE_MARIADB + + +## ----- +## - Backup directories and files from existing installation +## ----- + +if $UPDATE_MARIADB ; then + + echo "" + echo "" + echo -e "\033[37m\033[1mBackup directories and files from existing installation\033[m" + echo "" + + echo "" >> ${logdir}/main.log + echo "" >> ${logdir}/main.log + echo "## -----" >> ${logdir}/main.log + echo "## - Backup directories and files from existing installation" >> ${logdir}/main.log + echo "## -----" >> ${logdir}/main.log + + if [ -d $MARIADB_DATA_DIR ]; then + echononl "Sichere exitierendes MariaDB Datenbank-Verzeichnis ..." + echo "" >> ${logdir}/main.log + echo "## - Sichere exitierendes MariaDB Datenbank-Verzeichnis" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "cp -a $MARIADB_DATA_DIR ${MARIADB_DATA_DIR}.${_backup_date}" >> ${logdir}/main.log + cp -a $MARIADB_DATA_DIR ${MARIADB_DATA_DIR}.$_backup_date >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + fatal "Kann Datenbank-Verzeichnis \"${MARIADB_DATA_DIR}\" nicht verschieben.." + fi + elif [[ -d "$MARIADB_CUR_DATA_DIR" ]] ; then + echononl "Kopiere exitierendes MariaDB Datenbank-Verzeichnis ..." + echo "" >> ${logdir}/main.log + echo "## - Kopiere exitierendes MariaDB Datenbank-Verzeichnis" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "cp -a \"$MARIADB_CUR_DATA_DIR\" \"$MARIADB_DATA_DIR\"" >> ${logdir}/main.log + cp -a "$MARIADB_CUR_DATA_DIR" "$MARIADB_DATA_DIR" >> ${logdir}/main.log + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + fatal "Kopieren \"$MARIADB_CUR_DATA_DIR\" --> \"${MARIADB_DATA_DIR}\" fehlgeschlagen.." + fi + else + echo_failed + fatal "Exitierendes MariaDB Datenbank-Verzeichnis nicht gefunden!" + fi + + + if [ -d ${MARIADB_INSTALL_DIR} ];then + echononl "Verschiebe exitierendes Installationsverzeichnis ..." + echo "" >> ${logdir}/main.log + echo "## - Verschiebe exitierendes Installationsverzeichnis" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "mv $MARIADB_INSTALL_DIR $MARIADB_INSTALL_DIR.${_backup_date}" >> ${logdir}/main.log + mv $MARIADB_INSTALL_DIR $MARIADB_INSTALL_DIR.$_backup_date >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + fatal Kann Installationsverzeichnis \"${MARIADB_INSTALL_DIR}\" nicht verschieben.. + fi + fi + +fi # if $UPDATE_MARIADB + + +## ----- +## - Create needed directories for the new installation +## ----- + +echo "" +echo "" +echo -e "\033[37m\033[1mCreate needed directories for the new installation\033[m" +echo "" + +if ! $UPDATE_MARIADB ; then + if [ -d ${MARIADB_DATA_DIR} ];then + echononl "Verschiebe exitierendes MariaDB Datenverzeichnis ..." + echo "" >> ${logdir}/main.log + echo "## - Verschiebe exitierendes MariaDB Datenverzeichnis" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "mv $MARIADB_DATA_DIR $MARIADB_DATA_DIR.${_backup_date}" >> ${logdir}/main.log + mv $MARIADB_DATA_DIR $MARIADB_DATA_DIR.$_backup_date >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + warn "Something went wrong, because the moved directory should NOT exists at this time. + Maybe you run an fresh new installion but MariaDB was already installed. anyway.." + else + echo_failed + fatal Kann MariaDB Datenverzeichnis \"${MARIADB_DATA_DIR}\" nicht verschieben.. + fi fi fi +echo "" >> ${logdir}/main.log +echo "" >> ${logdir}/main.log +echo "## -----" >> ${logdir}/main.log +echo "## - Create needed directories for the new installation" >> ${logdir}/main.log +echo "## -----" >> ${logdir}/main.log echononl "Erstelle Datenbank-Verzeichnis \"$MARIADB_DATA_DIR\".." echo "" >> ${logdir}/main.log +echo "## - Erstelle Datenbank-Verzeichnis \"$MARIADB_DATA_DIR\"" >> ${logdir}/main.log +echo "## -" >> ${logdir}/main.log echo "mkdir -p $MARIADB_DATA_DIR" >> ${logdir}/main.log mkdir -p $MARIADB_DATA_DIR >> ${logdir}/main.log 2>&1 if [ "$?" = "0" ]; then @@ -821,8 +1298,11 @@ else fatal Kann Datenbank-Verzeichnis \"${MARIADB_DATA_DIR}\" nicht erstellen.. fi + echononl "Setze Besitzer \"${MARIADB_USER}:${MARIADB_GROUP}\" für Datenbank-Verzeichnis" echo "" >> ${logdir}/main.log +echo "## - Setze Besitzer \"${MARIADB_USER}:${MARIADB_GROUP}\" für Datenbank-Verzeichnis" >> ${logdir}/main.log +echo "## -" >> ${logdir}/main.log echo "chown -R ${MARIADB_USER}:${MARIADB_GROUP} ${MARIADB_DATA_DIR}" >> ${logdir}/main.log chown -R ${MARIADB_USER}:${MARIADB_GROUP} ${MARIADB_DATA_DIR} >> ${logdir}/main.log 2>&1 if [ "$?" = "0" ]; then @@ -834,6 +1314,8 @@ fi echononl "Setze Verzeichnisrechte \"700\" für Datenbank-Verzeichnis" echo "" >> ${logdir}/main.log +echo "## - Setze Verzeichnisrechte \"700\" für Datenbank-Verzeichnis" >> ${logdir}/main.log +echo "## -" >> ${logdir}/main.log echo "chmod 700 ${MARIADB_DATA_DIR}" >> ${logdir}/main.log chmod 700 ${MARIADB_DATA_DIR} >> ${logdir}/main.log 2>&1 if [ "$?" = "0" ]; then @@ -846,13 +1328,16 @@ fi echononl "Erstelle LOG Verzeichnis \"$MARIADB_LOG_DIR\".." echo "" >> ${logdir}/main.log +echo "## - Erstelle LOG Verzeichnis \"$MARIADB_LOG_DIR\"" >> ${logdir}/main.log +echo "## -" >> ${logdir}/main.log echo "mkdir -p $MARIADB_LOG_DIR" >> ${logdir}/main.log mkdir -p $MARIADB_LOG_DIR >> ${logdir}/main.log 2>&1 if [ "$?" = "0" ]; then echo_ok - _mariadb_log=${MARIADB_LOG_DIR}/mysql.log - _mariadb_error_log=${MARIADB_LOG_DIR}/mysql.err - _mariadb_slow_query_log=${MARIADB_LOG_DIR}/slow_query.log + mariadb_log=${MARIADB_LOG_DIR}/mysql.log + mariadb_error_log=${MARIADB_LOG_DIR}/mysql.err + mariadb_slow_query_log=${MARIADB_LOG_DIR}/slow_query.log + mariadb_groonga_log=${MARIADB_LOG_DIR}/groonga.log else echo_failed fatal Kann LOG Verzeichnis \"${MARIADB_LOG_DIR}\" nicht erstellen.. @@ -860,6 +1345,8 @@ fi echononl "Setze Besitzer \"${MARIADB_USER}:${MARIADB_GROUP}\" für LOG Verzeichnis" echo "" >> ${logdir}/main.log +echo "## - Setze Besitzer \"${MARIADB_USER}:${MARIADB_GROUP}\" für LOG Verzeichnis" >> ${logdir}/main.log +echo "## -" >> ${logdir}/main.log echo "chown -R ${MARIADB_USER}:${MARIADB_GROUP} ${MARIADB_LOG_DIR}" >> ${logdir}/main.log chown -R ${MARIADB_USER}:${MARIADB_GROUP} ${MARIADB_LOG_DIR} >> ${logdir}/main.log 2>&1 if [ "$?" = "0" ]; then @@ -871,6 +1358,8 @@ fi echononl "Setze Verzeichnisrechte \"2750\" für LOG Verzeichnis" echo "" >> ${logdir}/main.log +echo "## - Setze Verzeichnisrechte \"2750\" für LOG Verzeichnis" >> ${logdir}/main.log +echo "## -" >> ${logdir}/main.log echo "chmod 2750 ${MARIADB_LOG_DIR}" >> ${logdir}/main.log chmod 2750 ${MARIADB_LOG_DIR} >> ${logdir}/main.log 2>&1 if [ "$?" = "0" ]; then @@ -881,26 +1370,13 @@ else fi -#if [ -d "${MARIADB_SRC_BASE_DIR}/mariadb-$MARIADB_VERSION" ];then -# echononl "Verschiebe exitierendes Sourceverzeichnis ..." -# echo "" >> ${logdir}/main.log -# echo "mv ${MARIADB_SRC_BASE_DIR}/mariadb-$MARIADB_VERSION ${MARIADB_SRC_BASE_DIR}/mariadb-$MARIADB_VERSION.`date +\"%Y%m%d-%H%M\"`" >> ${logdir}/main.log -# mv ${MARIADB_SRC_BASE_DIR}/mariadb-$MARIADB_VERSION ${MARIADB_SRC_BASE_DIR}/mariadb-$MARIADB_VERSION.`date +"%Y%m%d-%H%M"` \ -# >> ${logdir}/main.log 2>&1 -# if [ "$?" = "0" ]; then -# echo_ok -# else -# echo_failed -# fatal Kann Sourceverzeichnis \"${MARIADB_SRC_BASE_DIR}/mariadb-$MARIADB_VERSION\" nicht verschieben.. -# fi -#fi - - if [ -d "${MARIADB_SRC_DIR}" ];then echononl "Verschiebe exitierendes Sourceverzeichnis ..." echo "" >> ${logdir}/main.log - echo "mv ${MARIADB_SRC_DIR} ${MARIADB_SRC_DIR}.`date +\"%Y%m%d-%H%M\"`" >> ${logdir}/main.log - mv ${MARIADB_SRC_DIR} ${MARIADB_SRC_DIR}.`date +"%Y%m%d-%H%M"` >> ${logdir}/main.log 2>&1 + echo "## - Verschiebe exitierendes Sourceverzeichnis" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "mv ${MARIADB_SRC_DIR} ${MARIADB_SRC_DIR}.${_backup_date}" >> ${logdir}/main.log + mv ${MARIADB_SRC_DIR} ${MARIADB_SRC_DIR}.$_backup_date >> ${logdir}/main.log 2>&1 if [ "$?" = "0" ]; then echo_ok else @@ -909,17 +1385,82 @@ if [ -d "${MARIADB_SRC_DIR}" ];then fi fi +if $INSTALL_SYSTEMD_SERVICE ; then + if [[ ! -d "$SYSTEMD_PID_DIR" ]] ; then + echononl "Create PID directory '$SYSTEMD_PID_DIR' .." + echo "" >> ${logdir}/main.log + echo "## - Create PID directory '$SYSTEMD_PID_DIR'" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "mkdir \"$SYSTEMD_PID_DIR\"" >> ${logdir}/main.log + + mkdir "$SYSTEMD_PID_DIR" >> ${logdir}/main.log 2>&1 + if [[ $? -eq 0 ]] ; then + echo_ok + else + echo_failed + error "Creating PID directory '$SYSTEMD_PID_DIR' failed!" + fi + + echononl "Change owner of PID directory '$SYSTEMD_PID_DIR'" + echo "" >> ${logdir}/main.log + echo "## - Change owner of PID directory '$SYSTEMD_PID_DIR'" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "chown $MARIADB_USER:${MARIADB_GROUP} \"${SYSTEMD_PID_DIR}\"" >> ${logdir}/main.log + + chown $MARIADB_USER:${MARIADB_GROUP} ${SYSTEMD_PID_DIR} >> ${logdir}/main.log + if [[ $? -eq 0 ]] ; then + echo_ok + else + echo_failed + error "Changing owner of PID directory '$SYSTEMD_PID_DIR' failed!" + fi + + fi +fi + + +## ----- +## - Basis Installation MariaDB +## ----- + +echo "" +echo "" +echo -e "\033[37m\033[1mBasis Installation MariaDB $MARIADB_VERSION\033[m" +echo "" -cd $MARIADB_SRC_BASE_DIR echo "" >> ${logdir}/main.log -echo "cd $MARIADB_SRC_BASE_DIR" >> ${logdir}/main.log +echo "" >> ${logdir}/main.log +echo "## -----" >> ${logdir}/main.log +echo "## - Basis Installation MariaDB $MARIADB_VERSION" >> ${logdir}/main.log +echo "## -----" >> ${logdir}/main.log + +## - This step is redundant and should never bee happend. +## - +if [ -d ${MARIADB_INSTALL_DIR} ];then + echononl "Verschiebe exitierendes Installationsverzeichnis ..." + echo "" >> ${logdir}/main.log + echo "## - Verschiebe exitierendes Installationsverzeichnis" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "mv $MARIADB_INSTALL_DIR $MARIADB_INSTALL_DIR.${_backup_date}" >> ${logdir}/main.log + mv $MARIADB_INSTALL_DIR $MARIADB_INSTALL_DIR.$_backup_date >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + warn "Something went wrong, because the moved directory should NOT exists at this time. + Maybe you run an fresh new installion but MariaDB was already installed. anyway.." + else + echo_failed + fatal Kann Installationsverzeichnis \"${MARIADB_INSTALL_DIR}\" nicht verschieben.. + fi +fi + -echo echononl "Entpacke $distfile ..." echo "" >> ${logdir}/main.log -echo "gunzip < $distfile | tar -xf -" >> ${logdir}/main.log +echo "## - Entpacke $distfile" >> ${logdir}/main.log +echo "## -" >> ${logdir}/main.log +echo "gunzip < \"${MARIADB_SRC_BASE_DIR}/$distfile\" | tar -C \"$MARIADB_SRC_BASE_DIR\" -xf -" >> ${logdir}/main.log -gunzip < $distfile | tar -xf - +gunzip < "${MARIADB_SRC_BASE_DIR}/$distfile" | tar -C "$MARIADB_SRC_BASE_DIR" -xf - if [ "$?" = "0" ]; then echo_ok else @@ -927,29 +1468,66 @@ else fatal Kann MariaDB Sourcearchiv \"${distfile}\" nicht entpacken.. fi -cd ${MARIADB_SRC_DIR} +echononl "Wechsle in das Verzeichnis '${MARIADB_SRC_DIR}'.." echo "" >> ${logdir}/main.log +echo "## - Wechsle in das Verzeichnis '${MARIADB_SRC_DIR}'" >> ${logdir}/main.log +echo "## -" >> ${logdir}/main.log echo "cd ${MARIADB_SRC_DIR}" >> ${logdir}/main.log - -if [ -d ${MARIADB_INSTALL_DIR} ];then - echononl "Verschiebe exitierendes Installationsverzeichnis ..." - echo "" >> ${logdir}/main.log - echo "mv $MARIADB_INSTALL_DIR $MARIADB_INSTALL_DIR.`date +\"%Y%m%d-%H%M\"`" >> ${logdir}/main.log - mv $MARIADB_INSTALL_DIR $MARIADB_INSTALL_DIR.`date +"%Y%m%d-%H%M"` >> ${logdir}/main.log 2>&1 - if [ "$?" = "0" ]; then - echo_ok - else - echo_failed - fatal Kann Installationsverzeichnis \"${MARIADB_INSTALL_DIR}\" nicht verschieben.. - fi +cd ${MARIADB_SRC_DIR} >> ${logdir}/main.log 2>&1 +if [ "$?" = "0" ]; then + echo_ok +else + echo_failed + fatal "Kann nicht in das Sourceverzeicnis '${MARIADB_SRC_DIR}' wechseln!" fi + +# - NOT supported (in contrast to original MySQL) +# - +# - -DINSTALL_SECURE_FILE_PRIVDIR=\"\" +# - -DDOWNLOAD_BOOST=1 +# - -DWITH_BOOST=$MARIADB_INSTALL_DIR +# - +# - -DSYSTEMD_PID_DIR=$SYSTEMD_PID_DIR" +# - +# - +# - Options enabled /not availabe at original MySQL) +# - +# - configured exactly as the binary releases from MariaDB +# - -DBUILD_CONFIG=mysql_release +# - creates libmysql* symbolic links: +# - -CONC_WITH_MYSQLCOMPAT=ON +# - groonga log file path +# - -GRN_LOG_PATH=${MARIADB_LOG_DIR}/groonga.log +# - +echononl "Erstelle Optionen für 'cmake'" +echo "" >> ${logdir}/main.log +echo "## - Erstelle Optionen für 'cmake'" >> ${logdir}/main.log +echo "## -" >> ${logdir}/main.log + +cmake_options=" + . + -DBUILD_CONFIG=mysql_release + -DCMAKE_INSTALL_PREFIX=$MARIADB_INSTALL_DIR + -DMYSQL_DATADIR=$MARIADB_DATA_DIR + -DENABLED_LOCAL_INFILE=ON + -DGRN_LOG_PATH=$mariadb_groonga_log + -DCONC_WITH_MYSQLCOMPAT=ON +" +if $INSTALL_SYSTEMD_SERVICE ; then + cmake_options="$cmake_options -DWITH_SYSTEMD=yes" +fi +echo "cmake_options=\"$cmake_options\"" >> ${logdir}/main.log +echo_ok + echononl "Konfiguriere MariaDB (cmake).." echo "" >> ${logdir}/main.log -echo "cmake -D CMAKE_INSTALL_PREFIX=$MARIADB_INSTALL_DIR -D MYSQL_DATADIR=$MARIADB_DATA_DIR . " >> ${logdir}/main.log -cmake -D CMAKE_INSTALL_PREFIX=$MARIADB_INSTALL_DIR \ - -D MYSQL_DATADIR=$MARIADB_DATA_DIR . \ - > ${logdir}/cmake-conf.log 2>&1 +echo "# - Konfiguriere MariaDB (cmake).." >> ${logdir}/main.log +echo "# -" >> ${logdir}/main.log +echo "# - See ${logdir}/cmake-conf.log" >> ${logdir}/main.log +echo "# -" >> ${logdir}/main.log +echo "cmake \$cmake_options " >> ${logdir}/main.log +cmake $cmake_options > ${logdir}/cmake-conf.log 2>&1 if [ "$?" = "0" ]; then echo_ok else @@ -957,8 +1535,12 @@ else fatal Konfiguration fehlgeschlagen. Siehe ${logdir}/cmake-conf.log .. fi -echononl "Kompiliere MariaDB" +echononl "Kompiliere MariaDB.." echo "" >> ${logdir}/main.log +echo "## - Kompiliere MariaDB" >> ${logdir}/main.log +echo "## -" >> ${logdir}/main.log +echo "## - See: ${logdir}/make.log" >> ${logdir}/main.log +echo "## -" >> ${logdir}/main.log echo "make" >> ${logdir}/main.log make > ${logdir}/make.log 2>&1 if [ "$?" = "0" ]; then @@ -968,8 +1550,12 @@ else fatal Kompilieren der MariaDB Sourcen ist fehlgeschlagen. Siehe ${logdir}/make.log .. fi -echononl "Installiere MariaDB" +echononl "Installiere MariaDB.." echo "" >> ${logdir}/main.log +echo "## - Installiere MariaDB" >> ${logdir}/main.log +echo "## -" >> ${logdir}/main.log +echo "## - See: ${logdir}/make_install.log" >> ${logdir}/main.log +echo "## -" >> ${logdir}/main.log echo "make install" >> ${logdir}/main.log make install > ${logdir}/make_install.log 2>&1 if [ "$?" = "0" ]; then @@ -979,23 +1565,56 @@ else fatal Installieren von MariaDB ist fehlgeschlagen. Siehe ${logdir}/make_install.log .. fi + +## ----- +## - Einbinden der MariaDB Installation in das System +## ----- + +echo "" +echo "" +echo -e "\033[37m\033[1mEinbinden der MariaDB $MARIADB_VERSION Installation in das System\033[m" +echo "" + +echo "" >> ${logdir}/main.log +echo "" >> ${logdir}/main.log +echo "## -----" >> ${logdir}/main.log +echo "## - Einbinden der MariaDB $MARIADB_VERSION Installation in das System" >> ${logdir}/main.log +echo "## -----" >> ${logdir}/main.log + echononl "Konfiguriere Manpages.." _done=false if [ -f /etc/manpath.config ];then if ! grep /usr/local/mysql/man /etc/manpath.config > /dev/null 2<&1 ; then + echo "## - Konfiguriere Manpages" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "## - Fuege folgend Zeilen am Ende der Datei \"/etc/manpath.config\" hinzu:" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "## - MANDATORY_MANPATH /usr/local/mysql/man /var/cache/man" >> ${logdir}/main.log + echo "## - MANPATH_MAP /usr/local/mysql/bin /usr/local/mysql/man" >> ${logdir}/main.log + echo "## - MANPATH_MAP /usr/local/mysql/bin /usr/local/mysql/man" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo >> /etc/manpath.config echo "MANDATORY_MANPATH /usr/local/mysql/man /var/cache/man" >> /etc/manpath.config echo "MANPATH_MAP /usr/local/mysql/bin /usr/local/mysql/man" >> /etc/manpath.config echo "MANDB_MAP /usr/local/mysql/man /var/cache/man" >> /etc/manpath.config - + _done=true fi elif [ -f /etc/man.conf];then if ! grep /opt/apache2/man /etc/man.conf > /dev/null 2<&1 ; then + echo "## - Konfiguriere Manpages" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "## - Fuege folgend Zeilen am Ende der Datei \"/etc/man.conf\" hinzu:" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "## - MANPATH /opt/mysql/man /var/cache/man" >> ${logdir}/main.log + echo "## - MANPATH_MAP /opt/mysql/bin /opt/apache2/man" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo >> /etc/man.conf echo "MANPATH /opt/mysql/man /var/cache/man" >> /etc/man.conf echo "MANPATH_MAP /opt/mysql/bin /opt/apache2/man" >> /etc/man.conf - + _done=true fi fi @@ -1005,82 +1624,35 @@ else echo_skipped fi - -if $SYMLINK_INITSCRIPT ; then - - if [ -h "/etc/init.d/mysql.server" ]; then - echononl "Entferne vorhandenen Symlink \"/etc/init.d/mysql.server\".." - echo "" >> ${logdir}/main.log - echo "rm /etc/init.d/mysql.server" >> ${logdir}/main.log - rm /etc/init.d/mysql.server >> ${logdir}/main.log 2>&1 - if [ "$?" = "0" ]; then - echo_ok - else - echo_failed - error Kann Symlink /etc/init.d/mysql.server nicht entfernen.. - fi - fi - - if [[ -f "/etc/init.d/mysql.server" ]]; then - echononl "Entferne Startscript \"/etc/init.d/mysql.server\".." - echo "" >> ${logdir}/main.log - echo "rm /etc/init.d/mysql.server" >> ${logdir}/main.log - rm /etc/init.d/mysql.server >> ${logdir}/main.log 2>&1 - if [ "$?" = "0" ]; then - echo_ok - else - echo_failed - error Kann Startscript /etc/init.d/mysql.server nicht entfernen.. - fi - fi - - echononl "Erstelle Symlink \"/etc/init.d/mysql.server\".." - echo "" >> ${logdir}/main.log - echo "ln -s $MARIADB_INSTALL_DIR/support-files/mysql.server /etc/init.d/mysql.server" >> ${logdir}/main.log - ln -s $MARIADB_INSTALL_DIR/support-files/mysql.server /etc/init.d/mysql.server >> ${logdir}/main.log 2>&1 - if [ "$?" = "0" ]; then - echo_ok - else - echo_failed - error "Kann Symlink $MARIADB_INSTALL_DIR/support-files/mysql.server --> /etc/init.d/mysql.server nicht erstellen.." - fi - - echononl "Setze ulimit im Startscript.." - echo "" >> ${logdir}/main.log - echo "sed -i \"1 s/\(.*\)/\1\n\nulimit -n \\\`ulimit -Hn\\\`\n/\" /etc/init.d/mysql.server" >> ${logdir}/main.log - sed -i "1 s/\(.*\)/\1\n\nulimit -n \`ulimit -Hn\`\n/" $(realpath /etc/init.d/mysql.server) >> ${logdir}/main.log 2>&1 - if [ "$?" = "0" ]; then - echo_ok - else - echo_failed - fatal "Kann \"ulimit\" im Startscript nicht setzen /etc/init.d/mysql.server nicht setzen.." - fi - -fi - ## - Symlink Installationsverzeichnis (i.d.R. /usr/local/mysql) ## - if $SYMLINK_INSTALL_DIR ; then - if [ -h `dirname $MARIADB_INSTALL_DIR`/mysql ]; then - echononl "Entferne vorhandenen Symlink `dirname $MARIADB_INSTALL_DIR`/mysql.." + echononl "Entferne vorhandenen Symlink `dirname $MARIADB_INSTALL_DIR`/mysql.." + if [[ -h "$(dirname $MARIADB_INSTALL_DIR)/mysql" ]]; then echo "" >> ${logdir}/main.log - echo "rm `dirname $MARIADB_INSTALL_DIR`/mysql" >> ${logdir}/main.log - rm `dirname $MARIADB_INSTALL_DIR`/mysql >> ${logdir}/main.log 2>&1 + echo "## - Entferne vorhandenen Symlink `dirname $MARIADB_INSTALL_DIR`/mysql" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "rm \"$(dirname $MARIADB_INSTALL_DIR)/mysql\"" >> ${logdir}/main.log + rm "$(dirname $MARIADB_INSTALL_DIR)/mysql" >> ${logdir}/main.log 2>&1 if [ "$?" = "0" ]; then echo_ok else echo_failed error Kann Symlink `dirname $MARIADB_INSTALL_DIR`/mysql nicht entfernen.. fi + else + echo_skipped fi - if [ -d `dirname $MARIADB_INSTALL_DIR`/mysql ]; then - echononl "Verschiebe Verzeichnis `dirname $MARIADB_INSTALL_DIR`/mysql ..." + echononl "Verschiebe Verzeichnis '$(dirname $MARIADB_INSTALL_DIR)/mysql' ..." + if [ -d "$(dirname $MARIADB_INSTALL_DIR)/mysql" ]; then echo "" >> ${logdir}/main.log - echo "mv `dirname $MARIADB_INSTALL_DIR`/mysql `dirname $MARIADB_INSTALL_DIR`/mysql.`date +\"%Y%m%d-%H%M\"`" \ + echo "## - Verschiebe Verzeichnis '$(dirname $MARIADB_INSTALL_DIR)/mysql'" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "mv \"$(dirname $MARIADB_INSTALL_DIR)/mysql)\" \"$(dirname $MARIADB_INSTALL_DIR)/mysql.$(date +"%Y%m%d-%H%M")" \ >> ${logdir}/main.log - mv `dirname $MARIADB_INSTALL_DIR`/mysql `dirname $MARIADB_INSTALL_DIR`/mysql.`date +"%Y%m%d-%H%M"` \ + mv "$(dirname $MARIADB_INSTALL_DIR)/mysql" "$(dirname $MARIADB_INSTALL_DIR)/mysql.$(date +"%Y%m%d-%H%M")" \ >> ${logdir}/main.log 2>&1 if [ "$?" = "0" ]; then echo_ok @@ -1088,12 +1660,16 @@ if $SYMLINK_INSTALL_DIR ; then echo_failed error Kann Installationsverzeichnis \"${MARIADB_INSTALL_DIR}\" nicht verschieben.. fi + else + echo_skipped fi - echononl "Erstelle Symlink `dirname $MARIADB_INSTALL_DIR`/mysql --> $MARIADB_INSTALL_DIR" + echononl "Erstelle Symlink $(dirname $MARIADB_INSTALL_DIR)/mysql --> $MARIADB_INSTALL_DIR" echo "" >> ${logdir}/main.log - echo "ln -s `basename $MARIADB_INSTALL_DIR` `dirname $MARIADB_INSTALL_DIR`/mysql" >> ${logdir}/main.log - ln -s `basename $MARIADB_INSTALL_DIR` `dirname $MARIADB_INSTALL_DIR`/mysql >> ${logdir}/main.log 2>&1 + echo "## - Erstelle Symlink $(dirname $MARIADB_INSTALL_DIR)/mysql --> $MARIADB_INSTALL_DIR" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "ln -s \"$(basename $MARIADB_INSTALL_DIR)\" \"$(dirname $MARIADB_INSTALL_DIR)/mysql\"" >> ${logdir}/main.log + ln -s "$(basename $MARIADB_INSTALL_DIR)" "$(dirname $MARIADB_INSTALL_DIR)/mysql" >> ${logdir}/main.log 2>&1 if [ "$?" = "0" ]; then echo_ok else @@ -1106,11 +1682,13 @@ fi ## - if $SYMLINK_DATA_DIR ; then - if [ -h `dirname $MARIADB_DATA_DIR`/mysql ]; then - echononl "Entferne vorhandenen Symlink `dirname $MARIADB_DATA_DIR`/mysql.." + if [ -h "$(dirname $MARIADB_DATA_DIR)/mysql" ]; then + echononl "Entferne vorhandenen Symlink '$(dirname $MARIADB_DATA_DIR)/mysql'.." echo "" >> ${logdir}/main.log - echo "rm `dirname $MARIADB_DATA_DIR`/mysql" >> ${logdir}/main.log - rm `dirname $MARIADB_DATA_DIR`/mysql >> ${logdir}/main.log 2>&1 + echo "## - Entferne vorhandenen Symlink '$(dirname $MARIADB_DATA_DIR)/mysql'" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "rm $(dirname $MARIADB_DATA_DIR)/mysql" >> ${logdir}/main.log + rm $(dirname $MARIADB_DATA_DIR)/mysql >> ${logdir}/main.log 2>&1 if [ "$?" = "0" ]; then echo_ok else @@ -1119,12 +1697,14 @@ if $SYMLINK_DATA_DIR ; then fi fi - if [ -d `dirname $MARIADB_DATA_DIR`/mysql ]; then - echononl "Verschiebe Verzeichnis `dirname $MARIADB_DATA_DIR`/mysql ..." + if [ -d "$(dirname $MARIADB_DATA_DIR)/mysql" ]; then + echononl "Verschiebe Verzeichnis '$(dirname $MARIADB_DATA_DIR)/mysql' ..." echo "" >> ${logdir}/main.log - echo "mv `dirname $MARIADB_DATA_DIR`/mysql `dirname $MARIADB_DATA_DIR`/mysql.`date +\"%Y%m%d-%H%M\"`" \ + echo "## - Verschiebe Verzeichnis '$(dirname $MARIADB_DATA_DIR)/mysql'" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "mv \"$(dirname $MARIADB_DATA_DIR)/mysql\" \"$(dirname $MARIADB_DATA_DIR)/mysql.$(date +"%Y%m%d-%H%M")" \ >> ${logdir}/main.log - mv `dirname $MARIADB_DATA_DIR`/mysql `dirname $MARIADB_DATA_DIR`/mysql.`date +"%Y%m%d-%H%M"` \ + mv "$(dirname $MARIADB_DATA_DIR)/mysql" "$(dirname $MARIADB_DATA_DIR)/mysql.$(date +"%Y%m%d-%H%M")" \ >> ${logdir}/main.log 2>&1 if [ "$?" = "0" ]; then echo_ok @@ -1136,32 +1716,38 @@ if $SYMLINK_DATA_DIR ; then echononl "Erstelle Symlink `dirname $MARIADB_DATA_DIR`/mysql --> $MARIADB_DATA_DIR" echo "" >> ${logdir}/main.log - echo "ln -s `basename $MARIADB_DATA_DIR` `dirname $MARIADB_DATA_DIR`/mysql" >> ${logdir}/main.log - ln -s `basename $MARIADB_DATA_DIR` `dirname $MARIADB_DATA_DIR`/mysql >> ${logdir}/main.log 2>&1 + echo "## - Erstelle Symlink `dirname $MARIADB_DATA_DIR`/mysql --> $MARIADB_DATA_DIR" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "ln -s \"$(basename $MARIADB_DATA_DIR)\" \"$(dirname $MARIADB_DATA_DIR)/mysql\"" >> ${logdir}/main.log + ln -s "$(basename $MARIADB_DATA_DIR)" "$(dirname $MARIADB_DATA_DIR)/mysql" >> ${logdir}/main.log 2>&1 if [ "$?" = "0" ]; then echo_ok else echo_failed - error Kann Symlink `basename $MARIADB_DATA_DIR` --> `dirname $MARIADB_DATA_DIR`/mysql nicht erstellen .. + error "Kann Symlink $(basename $MARIADB_DATA_DIR) --> $(dirname $MARIADB_DATA_DIR)/mysql nicht erstellen .." fi fi -echononl "Füge `dirname $MARIADB_INSTALL_DIR`/mysql/bin zur PATH Variable hinzu .." +_checkdir="$(dirname "$MARIADB_INSTALL_DIR")/mysql/bin" +echononl "Füge '$_checkdir' zur PATH Variable hinzu .." if [ -f /etc/profile ]; then - _mariadb_bin_dir="`dirname $MARIADB_INSTALL_DIR`/mysql/bin" - if ! grep -e "PATH=.*$_mariadb_bin_dir" /etc/profile > /dev/null 2<&1 ; then + if ! grep -e "$_checkdir" /etc/profile > /dev/null 2<&1 ; then echo "" >> ${logdir}/main.log - echo "perl -i -n -p -e \"s#^([ ]*export[ ]*PATH.*$)#check_dir=\$_mariadb_bin_dir\nif [ -d \\\"\\\\\\\$check_dir\\\" ];then\n PATH=\\\\\\\${check_dir}:\\\\\\\$PATH\nfi\n\n\1#\" /etc/profile" >> ${logdir}/main.log 2<&1 - perl -i -n -p -e "s#^([ ]*export[ ]*PATH.*$)#check_dir=$_mariadb_bin_dir\nif [ -d \"\\\$check_dir\" ];then\n PATH=\\\${check_dir}:\\\$PATH\nfi\n\n\1#" /etc/profile >> ${logdir}/main.log 2<&1 + echo "## - Füge `dirname $MARIADB_INSTALL_DIR`/mysql/bin zur PATH Variable hinzu" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "perl -i -n -p -e \"s#^([ ]*export[ ]*PATH.*$)#check_dir=\$_checkdir\nif [ -d \\\"\\\\\\\$check_dir\\\" ];then\n PATH=\\\\\\\${check_dir}:\\\\\\\$PATH\nfi\n\n\1#\" /etc/profile" >> ${logdir}/main.log 2<&1 + + perl -i -n -p -e "s#^([ ]*export[ ]*PATH.*$)#check_dir=$_checkdir\nif [ -d \"\\\$check_dir\" ];then\n PATH=\\\${check_dir}:\\\$PATH\nfi\n\n\1#" /etc/profile >> ${logdir}/main.log 2<&1 + if [ "$?" = "0" ]; then echo_ok else echo_failed fi - if ! echo "$PATH" | grep $_mariadb_bin_dir >> ${logdir}/main.log 2>&1 ; then - export PATH=${_mariadb_bin_dir}:$PATH + if ! echo "$PATH" | grep $_checkdir >> ${logdir}/main.log 2>&1 ; then + export PATH=${_checkdir}:$PATH fi else @@ -1172,8 +1758,30 @@ else fi -echo +## ----- +## - Konfiguration ( Teil 1) MariaDB Installation +## ----- + +echo "" +echo "" +echo -e "\033[37m\033[1mKonfiguration (Teil 1) der MariaDB $MARIADB_VERSION Installation\033[m" +echo "" + +echo "" >> ${logdir}/main.log +echo "" >> ${logdir}/main.log +echo "## -----" >> ${logdir}/main.log +echo "## - Konfiguration (Teil 1) der MariaDB $MARIADB_VERSION Installation" >> ${logdir}/main.log +echo "## -----" >> ${logdir}/main.log + + echononl "Erstelle Konfigurationsdatei /etc/ld.so.conf.d/mysql.conf.." +echo "" >> ${logdir}/main.log +echo "## - Erstelle Konfigurationsdatei /etc/ld.so.conf.d/mysql.conf" >> ${logdir}/main.log +echo "## -" >> ${logdir}/main.log +echo "cat << EOF >/etc/ld.so.conf.d/mysql.conf +`dirname $MARIADB_INSTALL_DIR`/mysql/lib +EOF" >> ${logdir}/main.log + cat << EOF >/etc/ld.so.conf.d/mysql.conf `dirname $MARIADB_INSTALL_DIR`/mysql/lib EOF @@ -1186,6 +1794,8 @@ fi echononl "Erstelle symbolische Links auf Libraries (ldconfig).." echo "" >> ${logdir}/main.log +echo "## - Erstelle symbolische Links auf Libraries (ldconfig)" >> ${logdir}/main.log +echo "## -" >> ${logdir}/main.log echo "ldconfig" >> ${logdir}/main.log ldconfig >> ${logdir}/main.log 2>&1 if [ "$?" = "0" ]; then @@ -1195,33 +1805,270 @@ else error "Der Befehl \"ldconfig\" ist fehgeschlagen" fi -if [ -f ${MARIADB_INSTALL_DIR}/my.cnf ]; then - echononl "Sichere Konfigurationsdatei.." +echo +echononl "Richte MariaDB Systemtabellen ein.." +if ! $UPDATE_MARIADB ; then + cd $MARIADB_INSTALL_DIR echo "" >> ${logdir}/main.log - echo "${MARIADB_INSTALL_DIR}/my.cnf ${MARIADB_INSTALL_DIR}" >> ${logdir}/main.log - mv ${MARIADB_INSTALL_DIR}/my.cnf ${MARIADB_INSTALL_DIR}/my.cnf.ORIG + echo "## - Richte MariaDB Systemtabellen ein" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "${MARIADB_INSTALL_DIR}/scripts/mysql_install_db \ " >> ${logdir}/main.log + echo " --user=$MARIADB_USER \ " >> ${logdir}/main.log + echo " --basedir=$MARIADB_INSTALL_DIR \ " >> ${logdir}/main.log + echo " --datadir=$MARIADB_DATA_DIR \ " >> ${logdir}/main.log + echo " --language=$MARIADB_INSTALL_DIR/share/german" >> ${logdir}/main.log + echo "" >> ${logdir}/main.log + + ${MARIADB_INSTALL_DIR}/scripts/mysql_install_db \ + --user=$MARIADB_USER \ + --basedir=$MARIADB_INSTALL_DIR \ + --datadir=$MARIADB_DATA_DIR \ + --lc-messages-dir=$MARIADB_INSTALL_DIR/share/german \ + >> ${logdir}/main.log 2>&1 if [ "$?" = "0" ]; then echo_ok else echo_failed - error Konnte Konfigurationsdatei ${MARIADB_INSTALL_DIR}/my.cnf nicht sichern.. + error Das Einrichten der MariaDB Systemtabellen ist fehlgeschlagen.. + + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/no]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Abbruch durch User" + fi +else + echo_skipped +fi + + +echononl "Create directory \"etc\".." +cd $MARIADB_INSTALL_DIR +echo "" >> ${logdir}/main.log +echo "## - Create directory \"etc\"" >> ${logdir}/main.log +echo "## -" >> ${logdir}/main.log +echo "cd $MARIADB_INSTALL_DIR" >> ${logdir}/main.log +echo "mkdir ${MARIADB_INSTALL_DIR}/etc" >> ${logdir}/main.log +mkdir ${MARIADB_INSTALL_DIR}/etc >> ${logdir}/main.log 2>&1 +if [ "$?" = "0" ]; then + echo_ok +else + echo_failed +fi + +echononl "Change permissions (755) to directory \"etc\".." +echo "" >> ${logdir}/main.log +echo "## - Change permissions (755) to directory \"etc\"" >> ${logdir}/main.log +echo "## -" >> ${logdir}/main.log +echo "chmod 755 ${MARIADB_INSTALL_DIR}/etc" >> ${logdir}/main.log +chmod 755 ${MARIADB_INSTALL_DIR}/etc >> ${logdir}/main.log 2>&1 +if [ "$?" = "0" ]; then + echo_ok +else + echo_failed +fi + + +echononl "Create directory \"mysql-files\".." +cd $MARIADB_INSTALL_DIR +echo "" >> ${logdir}/main.log +echo "## - Create directory \"mysql-files\"" >> ${logdir}/main.log +echo "## -" >> ${logdir}/main.log +echo "cd $MARIADB_INSTALL_DIR" >> ${logdir}/main.log +echo "mkdir ${MARIADB_INSTALL_DIR}/mysql-files" >> ${logdir}/main.log +mkdir ${MARIADB_INSTALL_DIR}/mysql-files >> ${logdir}/main.log 2>&1 +if [ "$?" = "0" ]; then + echo_ok +else + echo_failed +fi + +echononl "Change permissions (770) to directory \"mysql-files\".." +echo "" >> ${logdir}/main.log +echo "## - Change permissions (770) to directory \"mysql-files\"" >> ${logdir}/main.log +echo "## -" >> ${logdir}/main.log +echo "chmod 770 ${MARIADB_INSTALL_DIR}/mysql-files" >> ${logdir}/main.log +chmod 770 ${MARIADB_INSTALL_DIR}/mysql-files >> ${logdir}/main.log 2>&1 +if [ "$?" = "0" ]; then + echo_ok +else + echo_failed +fi + +echononl "Change owner ($MARIADB_USER) of directory 'mysql-files'.." +echo "" >> ${logdir}/main.log +echo "## - Change owner ($MARIADB_USER) of directory 'mysql-files'" >> ${logdir}/main.log +echo "## -" >> ${logdir}/main.log +echo "chown $MARIADB_USER ${MARIADB_INSTALL_DIR}/mysql-files" >> ${logdir}/main.log +chown $MARIADB_USER ${MARIADB_INSTALL_DIR}/mysql-files >> ${logdir}/main.log 2>&1 +if [ "$?" = "0" ]; then + echo_ok +else + echo_failed +fi + +echononl "Generate MariaDB SSL Certificate and RSA Key.." +echo "" >> ${logdir}/main.log +echo "## - Generate MariaDB SSL Certificate and RSA Key" >> ${logdir}/main.log +echo "## -" >> ${logdir}/main.log +echo "cd $MARIADB_INSTALL_DIR" >> ${logdir}/main.log +cd $MARIADB_INSTALL_DIR +echo "${MARIADB_INSTALL_DIR}/bin/mysql_ssl_rsa_setup --datadir=$MARIADB_DATA_DIR .." >> ${logdir}/main.log +if [[ -x "${MARIADB_INSTALL_DIR}/bin/mysql_ssl_rsa_setup" ]] ; then + ${MARIADB_INSTALL_DIR}/bin/mysql_ssl_rsa_setup --datadir=$MARIADB_DATA_DIR >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error "Generating MariaDB SSL Certificate and RSA Key failed" + + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/nno]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Abbruch durch User" + fi +else + echo_skipped + warn "Script for generating certificates (mysql_ssl_rsa_setup) is not supported" +fi + +echononl "Setze Besitzer/Gruppe für das Datenbankverzeichnis.." +echo "" >> ${logdir}/main.log +echo "## - Setze Besitzer/Gruppe für das Datenbankverzeichnis" >> ${logdir}/main.log +echo "## -" >> ${logdir}/main.log +echo "chown -R ${MARIADB_USER}:$MARIADB_GROUP $MARIADB_DATA_DIR" >> ${logdir}/main.log +chown -R ${MARIADB_USER}:$MARIADB_GROUP $MARIADB_DATA_DIR >> ${logdir}/main.log 2>&1 +if [ "$?" = "0" ]; then + echo_ok +else + echo_failed + error Konnte Besitzer/Gruppe für das Datenbankverzeichnis $MARIADB_DATA_DIR nicht setzen.. + + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/nno]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Abbruch durch User" +fi + + +_new_cnf_needed=false +if $UPDATE_MARIADB ; then + + _my_cnf_old= + if [[ "$CURRENT_VERSION" = "$MARIADB_VERSION" ]] ; then + if [[ -f "$(realpath ${MARIADB_CUR_INSTALL_DIR}).${_backup_date}/etc/my.cnf" ]]; then + _my_cnf_old="$(realpath ${MARIADB_CUR_INSTALL_DIR}).${_backup_date}/etc/my.cnf" + elif [[ -f "$(realpath ${MARIADB_CUR_INSTALL_DIR}).${_backup_date}/my.cnf" ]]; then + _my_cnf_old="$(realpath ${MARIADB_CUR_INSTALL_DIR}).${_backup_date}/my.cnf" + fi + else + if [[ -f "$(realpath ${MARIADB_CUR_INSTALL_DIR})/etc/my.cnf" ]]; then + _my_cnf_old="$(realpath ${MARIADB_CUR_INSTALL_DIR})/etc/my.cnf" + elif [[ -f "$(realpath ${MARIADB_CUR_INSTALL_DIR})/my.cnf" ]]; then + _my_cnf_old="$(realpath ${MARIADB_CUR_INSTALL_DIR})/my.cnf" + fi + fi + + echononl "Copy 'my.cnf from old installation to the new one.." + if [[ -f "$_my_cnf_old" ]] ; then + echo "" >> ${logdir}/main.log + echo "## - Copy 'my.cnf from old installation to the new one" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "cp -a \"$_my_cnf_old\" \"${MY_CNF_FILE}\"" >> ${logdir}/main.log + cp -a "$_my_cnf_old" "${MY_CNF_FILE}" >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + _new_cnf_needed=true + error "Konnte Konfigurationsdatei 'my.cnf' nicht vom alten in das neue Installations Verz.kopieren.." + + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/nno]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Abbruch durch User" + fi + else + echo_skipped + fi + + if [[ ! -f "$MY_CNF_FILE" ]] ; then + _new_cnf_needed=true + else + + proof_var="thread_concurrency" + echononl "Deaktiviere '${proof_var} .." + if grep -q -E "^\s*${proof_var}.*" "$MY_CNF_FILE" 2> /dev/null ; then + echo "" >> ${logdir}/main.log + echo "## - Deaktiviere '${proof_var} .." >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "perl -i -n -p -e \"s/^(\s*)(${proof_var}.*)/#\1\2/\" \"$MY_CNF_FILE\"" >> ${logdir}/main.log + perl -i -n -p -e "s/^(\s*)(${proof_var}.*)/#\1\2/" "$MY_CNF_FILE" >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + warn "Konnte '${proof_var}' nicht deaktivieren." + fi + else + echo_skipped + fi + + proof_var="innodb_additional_mem_pool_size" + echononl "Deaktiviere '${proof_var} .." + if grep -q -E "^\s*${proof_var}.*" "$MY_CNF_FILE" 2> /dev/null ; then + echo "" >> ${logdir}/main.log + echo "## - Deaktiviere '${proof_var} .." >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "perl -i -n -p -e \"s/^(\s*)(${proof_var}.*)/#\1\2/\" \"$MY_CNF_FILE\"" >> ${logdir}/main.log + perl -i -n -p -e "s/^(\s*)(${proof_var}.*)/#\1\2/" "$MY_CNF_FILE" >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + warn "Konnte '${proof_var}' nicht deaktivieren." + fi + else + echo_skipped + fi + fi fi -echononl "Erstelle Konfigurationsdatei ${MARIADB_INSTALL_DIR}/my.cnf.." -echo "" >> ${logdir}/main.log -echo "_number_cpus=`grep "^processor" /proc/cpuinfo | sort -u | wc -l`" >> ${logdir}/main.log -_number_cpus=`grep "^processor" /proc/cpuinfo | sort -u | wc -l` -echo "" >> ${logdir}/main.log -echo "let MARIADB_THREAD_CONCURRENCY=$_number_cpus*2" >> ${logdir}/main.log -let MARIADB_THREAD_CONCURRENCY=$_number_cpus*2 +if ! $UPDATE_MARIADB || $_new_cnf_needed ; then + echononl "Erstelle Konfigurationsdatei ${MARIADB_INSTALL_DIR}/etc/my.cnf.." -echo "" >> ${logdir}/main.log -echo "\$MARIADB_THREAD_CONCURRENCY = $MARIADB_THREAD_CONCURRENCY" >> ${logdir}/main.log + echo "" >> ${logdir}/main.log + echo "## - Erstelle Konfigurationsdatei ${MARIADB_INSTALL_DIR}/etc/my.cnf" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "_number_cpus=`grep "^processor" /proc/cpuinfo | sort -u | wc -l`" >> ${logdir}/main.log + _number_cpus=`grep "^processor" /proc/cpuinfo | sort -u | wc -l` -cat << EOF > ${MARIADB_INSTALL_DIR}/my.cnf + echo "" >> ${logdir}/main.log + echo "let MARIADB_THREAD_CONCURRENCY=$_number_cpus*2" >> ${logdir}/main.log + let MARIADB_THREAD_CONCURRENCY=$_number_cpus*2 + + echo "" >> ${logdir}/main.log + echo "\$MARIADB_THREAD_CONCURRENCY = $MARIADB_THREAD_CONCURRENCY" >> ${logdir}/main.log + + echo "cat << EOF > ${MARIADB_INSTALL_DIR}/etc/my.cnf # Example MySQL config file for very large systems. # # This is for a large system with memory of 1G-2G where the system runs mainly @@ -1235,7 +2082,7 @@ cat << EOF > ${MARIADB_INSTALL_DIR}/my.cnf # # In this file, you can use all long options that a program supports. # If you want to know which options a program supports, run the program -# with the "--help" option. +# with the \"--help\" option. # The following options will be passed to all MySQL clients [client] @@ -1250,8 +2097,8 @@ socket = $MARIADB_UNIX_SOCKET socket = $MARIADB_UNIX_SOCKET nice = 0 -open-files-limit = `ulimit -Hn` -innodb_open_files = `ulimit -Hn` +open-files-limit = $(ulimit -Hn) +innodb_open_files = $(ulimit -Hn) # The MySQL server @@ -1259,6 +2106,60 @@ innodb_open_files = `ulimit -Hn` port = $MARIADB_PORT socket = $MARIADB_UNIX_SOCKET + +## - sql-mode +## - +## - To be compartible with older programming on mysql 5.6 +## - +#sql-mode = \"ONLY_FULL_GROUP_BY,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\" + + +## - secure-file-priv +## - +## - This variable is used to limit the effect of data import and export operations, +## - such as those performed by the LOAD DATA and SELECT ... INTO OUTFILE statements +## - and the LOAD_FILE() function. These operations are permitted only to users who +## - have the FILE privilege. +## - +## - i.e.: GRANT FILE on *.* to piwik@localhost +## - +## - secure_file_priv may be set as follows: +## - +## - - If empty, the variable has no effect. (That means no restrictions). +## - This is not a secure setting. +## - - If set to the name of a directory, the server limits import and export +## - operations to work only with files in that directory. The directory +## - must exist; the server will not create it. +## - - If set to NULL, the server disables import and export operations. +## - This value is permitted as of MySQL 5.7.6. +## - +## - Since MySQL v 5.7.16 the default 'secure_file_priv' value has changed +## - +## - NULL (>= MySQL 5.7.16), empty (< MySQL 5.7.16) +## - +## - We use empty (\"\") +## - +## - Note: +## - We changed the default to empty (\"\") while building from source +## - using CMake option (-DINSTALL_SECURE_FILE_PRIVDIR=\"\"). So you can ignore +## - this option. +## - +#secure-file-priv = \"\" + + +## - local-infile +## - +## - This variable controls server-side LOCAL capability for LOAD DATA statements. +## - Depending on the local_infile setting, the server refuses or permits local data +## - loading by clients that have LOCAL enabled on the client side. +## - +## - You can check your 'local-infile' setting on mysql prompt: +## - +## - SHOW GLOBAL VARIABLES LIKE 'local_infile'; +## - +#local-infile = 1 + + ## - skip_external_locking ## - ## - Affects only MyISAM table access. @@ -1392,11 +2293,11 @@ explicit_defaults_for_timestamp = TRUE ## - erst ab für mysql 5.5.x ## - ## - lc-messages=de_DE -## - lc-messages-dir=`dirname $MARIADB_INSTALL_DIR`/mysql/share +## - lc-messages-dir=$(dirname $MARIADB_INSTALL_DIR)/mysql/share ## - ## - bis 5.1.x ## - -## - language=`dirname $MARIADB_INSTALL_DIR`/mysql/share/german +## - language=$(dirname $MARIADB_INSTALL_DIR)/mysql/share/german ## - @@ -1433,8 +2334,8 @@ concurrent_insert = 2 ## - ## - see also http://linux-vserver.org/Ulimit_Nofiles ## - -open-files-limit = `ulimit -Hn` -innodb_open_files = `ulimit -Hn` +open-files-limit = $(ulimit -Hn) +innodb_open_files = $(ulimit -Hn) ## ------------------------- @@ -1585,7 +2486,7 @@ sort_buffer_size = 2M ## - key_buffer_size ## - -## - key_buffer_size" is a MyISAM parameter ! +## - key_buffer_size is a MyISAM parameter ! ## - ## - Index blocks for MyISAM tables are buffered and are shared by all threads. ## - key_buffer_size is the size of the buffer used for index blocks. The key @@ -1724,13 +2625,13 @@ thread_stack = 262144 ## - name, MySQL uses host_name.err. If the file name has no extension, ## - the server adds an extension of .err. ## - -log-error = $_mariadb_error_log +log-error = $mariadb_error_log ## - Query Log ## - #general-log = on -#general_log_file = $_mariadb_log +#general_log_file = $mariadb_log ## - ft_min_word_len @@ -1862,7 +2763,7 @@ long_query_time = 1 ## - ## - Vorgabewert ist -slow.log ## - -slow_query_log_file = $_mariadb_slow_query_log +slow_query_log_file = $mariadb_slow_query_log ## - log-queries-not-using-indexes @@ -1939,6 +2840,7 @@ max_allowed_packet = 32M no-auto-rehash # Remove the next comment character if you are not familiar with SQL #safe-updates +local-infile = 1 [myisamchk] key_buffer_size = 256M @@ -1965,7 +2867,7 @@ write_buffer = 2M ## - ## - ## - Vorgabewert ist 4 -ft_min_word_len = 3 +#ft_min_word_len = 3 ## - angepasste Einstellungen ## ------------------------------------------ @@ -1974,29 +2876,915 @@ ft_min_word_len = 3 [mysqlhotcopy] interactive-timeout + +## - sql-mode +## - +## - To be compartible with older programming on mysql 5.6 +## - +#sql-mode = "ONLY_FULL_GROUP_BY,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" + +EOF" >> ${logdir}/main.log + + cat << EOF > ${MARIADB_INSTALL_DIR}/etc/my.cnf +# Example MySQL config file for very large systems. +# +# This is for a large system with memory of 1G-2G where the system runs mainly +# MySQL. +# +# You can copy this file to +# /etc/my.cnf to set global options, +# mysql-data-dir/my.cnf to set server-specific options (in this +# installation this directory is /var/lib/mysql) or +# ~/.my.cnf to set user-specific options. +# +# In this file, you can use all long options that a program supports. +# If you want to know which options a program supports, run the program +# with the "--help" option. + +# The following options will be passed to all MySQL clients +[client] +port = $MARIADB_PORT +socket = $MARIADB_UNIX_SOCKET + +# Here follows entries for some specific programs +# The following values assume you have at least 32M ram + +# This was formally known as [safe_mysqld]. Both versions are currently parsed. +[mysqld_safe] +socket = $MARIADB_UNIX_SOCKET +nice = 0 + +open-files-limit = $(ulimit -Hn) +innodb_open_files = $(ulimit -Hn) + + +# The MySQL server +[mysqld] +port = $MARIADB_PORT +socket = $MARIADB_UNIX_SOCKET + + +## - sql-mode +## - +## - To be compartible with older programming on mysql 5.6 +## - +#sql-mode = "ONLY_FULL_GROUP_BY,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" + + +## - secure-file-priv +## - +## - This variable is used to limit the effect of data import and export operations, +## - such as those performed by the LOAD DATA and SELECT ... INTO OUTFILE statements +## - and the LOAD_FILE() function. These operations are permitted only to users who +## - have the FILE privilege. +## - +## - i.e.: GRANT FILE on *.* to piwik@localhost +## - +## - secure_file_priv may be set as follows: +## - +## - - If empty, the variable has no effect. (That means no restrictions). +## - This is not a secure setting. +## - - If set to the name of a directory, the server limits import and export +## - operations to work only with files in that directory. The directory +## - must exist; the server will not create it. +## - - If set to NULL, the server disables import and export operations. +## - This value is permitted as of MySQL 5.7.6. +## - +## - Since MySQL v 5.7.16 the default 'secure_file_priv' value has changed +## - +## - NULL (>= MySQL 5.7.16), empty (< MySQL 5.7.16) +## - +## - We use empty ("") +## - +## - Note: +## - We changed the default to empty ("") while building from source +## - using CMake option (-DINSTALL_SECURE_FILE_PRIVDIR=""). So you can ignore +## - this option. +## - +#secure-file-priv = "" + + +## - local-infile +## - +## - This variable controls server-side LOCAL capability for LOAD DATA statements. +## - Depending on the local_infile setting, the server refuses or permits local data +## - loading by clients that have LOCAL enabled on the client side. +## - +## - You can check your 'local-infile' setting on mysql prompt: +## - +## - SHOW GLOBAL VARIABLES LIKE 'local_infile'; +## - +#local-infile = 1 + + +## - skip_external_locking +## - +## - Affects only MyISAM table access. +## - +## - This is OFF if mysqld uses external locking (system locking), +## - ON if external locking is disabled. +## - +## - Default: ON +## - +skip-external-locking + + +# Don't listen on a TCP/IP port at all. This can be a security enhancement, +# if all processes that need to connect to mysqld run on the same host. +# All interaction with mysqld must be made via Unix sockets or named pipes. +# Note that using this option without enabling named pipes on Windows +# (via the "enable-named-pipe" option) will render mysqld useless! +# +#skip-networking + + +# Instead of skip-networking the default is now to listen only on +# localhost which is more compatible and is not less secure. +# +#bind-address = 127.0.0.1 +bind-address = 127.0.0.1 + + +# Replication Master Server (default) +# binary logging is required for replication +#log-bin=mysql-bin + +# required unique id between 1 and 2^32 - 1 +# defaults to 1 if master-host is not set +# but will not function as a master if omitted +server-id = 1 + +# Replication Slave (comment out master section to use this) +# +# To configure this host as a replication slave, you can choose between +# two methods : +# +# 1) Use the CHANGE MASTER TO command (fully described in our manual) - +# the syntax is: +# +# CHANGE MASTER TO MASTER_HOST=, MASTER_PORT=, +# MASTER_USER=, MASTER_PASSWORD= ; +# +# where you replace , , by quoted strings and +# by the master's port number (3306 by default). +# +# Example: +# +# CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306, +# MASTER_USER='joe', MASTER_PASSWORD='secret'; +# +# OR +# +# 2) Set the variables below. However, in case you choose this method, then +# start replication for the first time (even unsuccessfully, for example +# if you mistyped the password in master-password and the slave fails to +# connect), the slave will create a master.info file, and any later +# change in this file to the variables' values below will be ignored and +# overridden by the content of the master.info file, unless you shutdown +# the slave server, delete master.info and restart the slaver server. +# For that reason, you may want to leave the lines below untouched +# (commented) and instead use CHANGE MASTER TO (see above) +# +# required unique id between 2 and 2^32 - 1 +# (and different from the master) +# defaults to 2 if master-host is set +# but will not function as a slave if omitted +#server-id = 2 +# +# The replication master for this slave - required +#master-host = +# +# The username the slave will use for authentication when connecting +# to the master - required +#master-user = +# +# The password the slave will authenticate with when connecting to +# the master - required +#master-password = +# +# The port the master is listening on. +# optional - defaults to 3306 +#master-port = +# +# binary logging - not required for slaves, but recommended +#log-bin=mysql-bin +# +# binary logging format - mixed recommended +#binlog_format=mixed + +# Point the following paths to different dedicated disks +#tmpdir = /tmp/ +#log-update = /path-to-dedicated-directory/hostname + + +## - max_connections +## - +## - Die zulässige Anzahl nebenläufiger Clientverbindungen. Wenn dieser Wert erhöht +## - wird, erhöht sich auch die Anzahl der Dateideskriptoren, die mysqld benötigt. +## - +## - Vorgabewert ist 100 +## - +#max_connections = 300 + + +## - explicit_defaults_for_timestamp +## - +## - This variable was added in MySQL 5.6.6 +## - +## - In MySQL, the TIMESTAMP data type differs in nonstandard ways +## - from other data types. See MySQL Dokumentation. +## - +## - [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. +## - Please use --explicit_defaults_for_timestamp server option (see +## - documentation for more details). +## - +## - As indicated by the warning, to turn off the nonstandard behaviors, +## - enable the new . +## - +explicit_defaults_for_timestamp = TRUE + + +## - MySQL Fehlermeldungen +## - +## - !! Notice +## - erst ab für mysql 5.5.x +## - +## - lc-messages=de_DE +## - lc-messages-dir=$(dirname $MARIADB_INSTALL_DIR)/mysql/share +## - +## - bis 5.1.x +## - +## - language=$(dirname $MARIADB_INSTALL_DIR)/mysql/share/german +## - + + +## - low-priority-updates +## - +## - Give table-modifying operations (INSERT, REPLACE, DELETE, +## - UPDATE) lower priority than selects. +## - +## - +low-priority-updates = 1 + + +## - concurrent_insert +## - +## - If activated (1 or AUTO, the default), MySQL permits INSERT +## - and SELECT statements to run concurrently for MyISAM tables +## - that have no free blocks in the middle of the data file. +## - +## - If set to 2 or ALWAYS, MySQL enables concurrent inserts for +## - all MyISAM tables, even those that have holes. For a table with +## - a hole, new rows are inserted at the end of the table if it is +## - in use by another thread. Otherwise, MySQL acquires a normal +## - write lock and inserts the row into the hole. +## - +concurrent_insert = 2 + + +## - open-files-limit +## - +## - put the following lines into /etc/security/limits.conf +## - +## - @staff hard nofile 32768 +## - root hard nofile 32768 +## - +## - see also http://linux-vserver.org/Ulimit_Nofiles +## - +open-files-limit = $(ulimit -Hn) +innodb_open_files = $(ulimit -Hn) + + +## ------------------------- +## InnoDB specific variables + +## - innodb_file_per_table +## - +## - When innodb_file_per_table is enabled (the default in 5.6.6 and higher), +## - InnoDB stores the data and indexes for each newly created table in a +## - separate .ibd file, rather than in the system tablespace. +## - +innodb_file_per_table + +## - innodb_data_home_dir +## - +## - Default: MySQL data directory +## - +#innodb_data_home_dir = /data/mysql + +#innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend + +## - innodb_log_group_home_dir +## - +## - The directory path to the InnoDB redo log files, whose number +## - is specified by innodb_log_files_in_group. +## - +## - If you do not specify any InnoDB log variables, the default is +## - to create two files named ib_logfile0 and ib_logfile1 in the MySQL +## - data directory. Their size is given by the size of the +## - innodb_log_file_size system variable. +## - +#innodb_log_group_home_dir = /var/lib/mysql/ + +## - innodb_buffer_pool_size +## - +## - The size in bytes of the buffer pool, the memory area where InnoDB +## - caches table and index data. +## - +## - You can set .._buffer_pool_size up to 50 - 80 % +## - of RAM but beware of setting memory usage too high +## - +## - Note: +## - When the size of the buffer pool is greater than 1GB, setting +## - innodb_buffer_pool_instances to a value greater than 1 can improve +## - the scalability on a busy server. +## - +## - default: 134217728 (128M) +## - +#innodb_buffer_pool_size = 384M +#innodb_buffer_pool_size = 1024M + + +## - innodb_additional_mem_pool_size +## - +## - The size in bytes of a memory pool InnoDB uses to store data dictionary +## - information and other internal data structures. +## - +## - Default: 8388608 (8M) +## - +#innodb_additional_mem_pool_size = 20M +#innodb_additional_mem_pool_size = 40M + + +## - innodb_buffer_pool_instances +## - +## - The number of regions that the InnoDB buffer pool is divided into. +## - +## - Note: +## - For systems with buffer pools in the multi-gigabyte range, dividing +## - the buffer pool into separate instances can improve concurrency, by +## - reducing contention as different threads read and write to cached pages. +## - +## - Default: 1 +## - +#innodb_buffer_pool_instances = 1 + + +## - innodb_log_file_size +## - +## - The size in bytes of each log file in a log group. +## - +## - Default: 5242880 (5M) +## - +## (Set .._log_file_size to 25 % of buffer pool size) +## - +#innodb_log_file_size = 100M +#innodb_log_file_size = 256M + +## - innodb_log_buffer_size +## - +## - The size in bytes of the buffer that InnoDB uses to write to the +## - log files on disk. +## - +## - Default: 8388608 (8M) +## - +#innodb_log_buffer_size = 8M +#innodb_log_buffer_size = 32M + +## - innodb_flush_log_at_trx_commit +## - +## - Controls the balance between strict ACID compliance for commit +## - operations, and higher performance that is possible when +## - commit-related I/O operations are rearranged and done in batches. +## - You can achieve better performance by changing the default value, +## - but then you can lose up to one second worth of transactions in a crash. +## - +## - In case of extrem slowly restores set +## - +## - innodb_flush_log_at_trx_commit = 2 +## - innodb_log_file_size = 256M +## - +## - Also try to add (befor DROP/CREATE/INSET Statements) to the dumpfile: +## - +## - ... +## - SET FOREIGN_KEY_CHECKS=0; +## - SET unique_checks=0; +## - SET AUTOCOMMIT=0; +## - +## - DROP TABLE IF EXISTS.. +## - ... +## - +#innodb_flush_log_at_trx_commit = 1 +#innodb_flush_log_at_trx_commit = 2 + +## - innodb_lock_wait_timeout +## - +## - The length of time in seconds an InnoDB transaction waits for a row +## - lock before giving up. +## - +## - Default: 50 +## - +#innodb_lock_wait_timeout = 50 + +## InnoDB specific variables +## ------------------------- + + +## - sort_buffer_size +## - +## - Each session that needs to do a sort allocates a buffer of this size. +## - sort_buffer_size is not specific to any storage engine and applies +## - in a general manner for optimization. +## - +## - Default: 2097152 (2M) +## - +sort_buffer_size = 2M + + +## - key_buffer_size +## - +## - key_buffer_size is a MyISAM parameter +## - +## - Index blocks for MyISAM tables are buffered and are shared by all threads. +## - key_buffer_size is the size of the buffer used for index blocks. The key +## - buffer is also known as the key cache. +## - +## - Default: 8388608 (8M) +## - +key_buffer_size = 384M + + +## - read_buffer_size +## - +## - Each thread that does a sequential scan for a MyISAM table allocates +## - a buffer of this size (in bytes) for each table it scans. If you do +## - many sequential scans, you might want to increase this value. +## - +## - Default: 131072 (128K) +## - +read_buffer_size = 2M + +## - read_rnd_buffer_size +## - +## - This variable is used for reads from MyISAM tables, and, for any +## - storage engine, for Multi-Range Read optimization. +## - +## - Default: 262144 (256K) +## - +read_rnd_buffer_size = 8M + + +## - myisam_sort_buffer_size +## - +## - The size of the buffer that is allocated when sorting MyISAM indexes +## - during a REPAIR TABLE or when creating indexes with CREATE INDEX or +## - ALTER TABLE. +## - +## - Default: 8388608 (8M) +## - +myisam_sort_buffer_size = 64M + + +## - max_allowed_packet +## - +## - The maximum size of one packet or any generated/intermediate string, or +## - any parameter sent by the mysql_stmt_send_long_data() C API function. +## +## - Default: 4MB (MySQL 5.6.6), 1MB before that. +## - +#max_allowed_packet = 4M +max_allowed_packet = 32M + + +## - table_open_cache +## - +## - The number of open tables for all threads. Increasing this value +## - increases the number of file descriptors that mysqld requires. +## - +## - You can check whether you need to increase the table cache by checking +## - the Opened_tables status variable. If the value of Opened_tables is large +## - and you do not use FLUSH TABLES often (which just forces all tables to be +## - closed and reopened), then you should increase the value of the +## - table_open_cache variable. +## - +table_open_cache = 512 + +## - table_definition_cache +## - +## - The number of table definitions (from .frm files) that can be stored +## - in the definition cache. +## - +## - Default: (400 + (table_open_cache / 2) since 5.6.8, 400 before +## - +#table_definition_cache = 1680 + +## - max_connect_errors +## - +## - Default: 100 (5.6.6), 10 (before) +## - +max_connect_errors = 999999 + +## - thread_concurrency +## - +## - NOTE: +## - This variable is specific to Solaris 8 and earlier systems. +## - +## - This variable is deprecated as of MySQL 5.6.1 and is removed in MySQL 5.7. +## - You should remove this from MySQL configuration files whenever you see it +## - unless they are for Solaris 8 or earlier +## - +## - (Try number of CPU's*2 for thread_concurrency) +## - +#thread_concurrency = 16 + +## - thread_cache_size +## - +## - How many threads the server should cache for reuse. When a client +## - disconnects, the client's threads are put in the cache if there are +## - fewer than thread_cache_size threads there. +## - +## - Default: 8 + (max_connections / 100) (5.6.8) , 0 (before) +## - +thread_cache_size = 8 + +## - thread_stack +## - +## - The stack size for each thread. Many of the limits detected by +## - the crash-me test are dependent on this value. +## - +## - The default of 192KB (256KB for 64-bit systems) is large enough +## - for normal operation. If the thread stack size is too small, it +## - limits the complexity of the SQL statements that the server can handle, +## - the recursion depth of stored procedures, and other memory-consuming +## - actions. +## - Default: 262144 (256K) +## - +thread_stack = 262144 + + +## - Unbenutze Datenbank Engines deaktivieren +## - + +## - skip-innodb +## - +## - Deaktiviert die Unterstützung für InnoDB +## - +## - Sincs version 5.5, you have to set default-storage-engine +## - to MyISAM, if using skip-innodb +## - +#default-storage-engine=MyISAM +#skip-innodb + + +## - log-error +## - +## - Log errors and startup messages to this file. If you omit the file +## - name, MySQL uses host_name.err. If the file name has no extension, +## - the server adds an extension of .err. +## - +log-error = $mariadb_error_log + + +## - Query Log +## - +#general-log = on +#general_log_file = $mariadb_log + + +## - ft_min_word_len +## - +## - Die minimale Länge des Wortes, das in einem FULLTEXT-Index enthalten sein darf. +## - +## - Notice! +## - if you set +## - [mysqld] +## - ft_min_word_len=3 +## - +## - you should also set +## - [myisamchk] +## - ft_min_word_len=3 +## - +## - +## - Vorgabewert ist 4 +#ft_min_word_len = 3 + +## - ft_stopword_file +## - +## - Datei, aus der die Liste der Stoppwörter für die Volltextsuche ausgelesen wird. +## - Es werden alle Wörter aus der Datei verwendet; Kommentare hingegen werden nicht +## - berücksichtigt. Standardmäßig wird eine eingebaute Liste mit Stoppwörtern (wie +## - in der Datei myisam/ft_static.c definiert) verwendet. Wird diesee Variable auf den +## - Leer-String gesetzt (''), wird die Ausfilterung von Stoppwörtern deaktiviert. +## - +## - Hinweis: Wird diese Variable geändern oder den Inhalt der Stoppwortdatei selbst, +## - müssen die FULLTEXT-Indizes neu erstellt werden (REPAIR TABLE tbl_name QUICK. ). +## - +#ft_stopword_file = /usr/local/mysql/stopwords_utf8_iso8859-15.txt + + + +## ------------- +## - query cache + + +## - query_cache_type +## - +## - 0 : verhindert das Speichern von Abfragen im und +## - das Abrufen aus dem Cache +## - 1 : gestattet das Speichern von Abfragen im Cache. +## - Ausgenommen sind Anweisungen, die mit +## - SELECT SQL_NO_CACHE beginnen. +## - 2 : speichert nur diejenigen Anweisungen im Cache, +## - die mit SELECT SQL_CACHE beginnen. +query_cache_type = 1 + + +## - query_cache_limit +## - +## - Gibt die maximale Größe einzelner Abfrageergebnisse an, die im +## - Cache gespeichert werden können. +## - +## - Vorgeabewert ist 1Mbyte +## - +query_cache_limit = 4M + + +## - query_cache_min_res_unit +## - +## - Die im Abfrage-Cache abgelegten Ergebnisse, werden nicht am Stück +## - verwaltet. Der Abfrage-Cache reserviert Blöcke zur Speicherung dieser +## - Daten nach Bedarf, d. h. wenn ein Block voll ist, wird der nächste +## - zugewiesen. Da der Speicherreservierungsvorgang (in zeitlicher Hinsicht) +## - aufwändig ist, reserviert der Abfrage-Cache die Blöcke mit einer +## - Mindestgröße, die durch die Systemvariable query_cache_min_res_unit +## - festgelegt wird. Wird eine Abfrage ausgeführt, dann wird der letzte +## - Ergebnisblock auf die tatsächliche Datengröße zugeschnitten, sodass +## - unbenutzter Speicher freigegeben wird. +## - +## - Siehe auch http://dev.mysql.com/doc/refman/5.1/de/query-cache-configuration.html +## - +## - Vorgabewert ist 4Kbyte +## - +query_cache_min_res_unit = 8K + + +## - query_cache_size +## - +## - Die Größe des Abfrage-Caches. +## - +## - Wird query_cache_size auf einen Wert größer Null gesetzt, so ist zu beachten, +## - dass der Abfrage-Cache eine Mindestgröße von ca. 40 Kbyte benötigt, um seine +## - Strukturen zuzuweisen. (Der exakte Wert hängt von der Systemarchitektur ab.) +## - Wird der Wert zu niedrig angesetzt, wird eine Warnung ausgegeben. +## - +## - Vorgabewert ist 0, d. h. der Abfrage-Cache ist vorgabeseitig deaktiviert. +## - +#query_cache_size = 32M +query_cache_size = 128M + +## - query cache +## ------------- + + +## -------------- +## - slow queries + +## - slow_query_log +## - +## - Gibt an, ob das Logging für langsame Abfragen eingeschaltet (1 oder ON) +## - bzw ausgeschaltet (0 oder OFF) ist. +## - +## - Vorgabewert ist 0 oder OFF +## - +slow_query_log = 1 + + +## - long_query_time +## - +## - Wenn eine Abfrage länger dauert als durch diese Variable (in Sekunden) angegeben, +## - erhöht der Server die Statusvariable Slow_queries entsprechend. Wird die Option +## - --log-slow-queries verwendet, wird die Abfrage in der Logdatei für langsame Abfragen +## - protokolliert. Dieser Wert wird als Echtzeit (nicht als Prozessorzeit) gemessen, d. h. +## - eine Abfrage, die bei einem System mit geringer Belastung den Schwellwert +## - unterschreitet, kann bei einem stark belasteten System bereits darüber liegen. +## - Der Mindestwert ist 1. +## - +## - Vorgabewert ist 10 +## - +long_query_time = 1 + + +## - slow_query_log_file +## - +## - Name der Logdatei, in die langsame Abfragen gespeichert werden. +## - +## - Vorgabewert ist -slow.log +## - +slow_query_log_file = $mariadb_slow_query_log + + +## - log-queries-not-using-indexes +## - +## - Gibt an, ob Abfragen, die keine Indizes benutzen in der Logdatei +## - für langsame Abfragen mitgespeichert werden sollen. +## - +## - Vorgabewert ist 0 +## - +#log_queries_not_using_indexes = 1 +log_queries_not_using_indexes = 0 + +## - slow queries +## -------------- + +## - join_buffer_size +## - +## - Die Größe des Puffers, der für Joins benutzt wird, die keine Indizes verwenden +## - und deswegen vollständige Tabellenscans durchführen. Normalerweise besteht die +## - beste Möglichkeit der Realisierung schneller Joins darin, Indizes hinzuzufügen. +## - Erhöhen Sie den Wert von join_buffer_size, um einen schnelleren vollständigen +## - Join zu implementieren, wenn das Hinzufügen von Indizes nicht möglich ist. Für +## - jeden vollständigen Join zwischen zwei Tabellen wird ein Join-Puffer hinzugefügt. +## - Für einen komplexen Join zwischen mehreren Tabellen, für den Indizes nicht verwendet +## - werden, sind unter Umständen mehrere Join-Puffer erforderlich. +## - +## - Wird die Option --log-slow-queries (ON) verwendet, werden Abfragen, die keine +## - Indizes verwenden, in das Log für langsame Abfragen geschrieben. +## - +## - Vorgabewert ist 128K +## - +#join_buffer_size = 384K + + + +## - max_heap_table_size +## - +## - Diese Variable bestimmt die maximale Größe, auf die MEMORY-Tabellen anwachsen dürfen. +## - Der Wert der Variable wird zur Berechnung von MAX_ROWS-Werte für MEMORY-Tabellen +## - verwendet. Die Einstellung der Variable hat keine Auswirkungen auf bereits vorhandene +## - MEMORY-Tabellen, sofern diese nicht mit einer Anweisung wie CREATE TABLE neu erstellt +## - oder mit ALTER TABLE oder TRUNCATE TABLE modifiziert werden. +## - +## - Vorgabewert ist 16Mbyte +## - +#max_heap_table_size = 96M + + +## - tmp_table_size +## - +## - Überschreitet eine temporäre Tabelle im Arbeitsspeicher diese Größe, wandelt MySQL +## - sie automatisch in eine MyISAM-Tabelle auf der Festplatte um. +## - +## - Werden viele erweiterte GROUP-BY-Anfragen ausgeführt (und ist genügend Speicher +## - vorhanden), so sollte diese Variable erhöht werden. +## +## - Default: 16777216 (16M) +## - +## - Note: +## - Effective in-memory tmp_table_size is limited to max_heap_table_size. +## - +#tmp_table_size = 96M + + +## - angepasste Einstellungen +## ------------------------------------------ + + +[mysqldump] +quick +max_allowed_packet = 32M + +[mysql] +no-auto-rehash +# Remove the next comment character if you are not familiar with SQL +#safe-updates +local-infile = 1 + +[myisamchk] +key_buffer_size = 256M +sort_buffer_size = 256M +read_buffer = 2M +write_buffer = 2M + + +## ------------------------------------------ +## - angepasste Einstellungen + +## - ft_min_word_len +## - +## - Die minimale Länge des Wortes, das in einem FULLTEXT-Index enthalten sein darf. +## - +## - Notice! +## - if you set +## - [mysqld] +## - ft_min_word_len=3 +## - +## - you should also set +## - [myisamchk] +## - ft_min_word_len=3 +## - +## - +## - Vorgabewert ist 4 +#ft_min_word_len = 3 + +## - angepasste Einstellungen +## ------------------------------------------ + + +[mysqlhotcopy] +interactive-timeout + + +## - sql-mode +## - +## - To be compartible with older programming on mysql 5.6 +## - +#sql-mode = "ONLY_FULL_GROUP_BY,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" + EOF -if [ "$?" = "0" ]; then - echo_ok -else - echo_failed - error Konnte Konfigurationsdatei \"${MARIADB_INSTALL_DIR}/my.cnf\" nicht erstellen.. + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error Konnte Konfigurationsdatei \"${MARIADB_INSTALL_DIR}/etc/my.cnf\" nicht erstellen.. + fi + fi -echononl "Kopiere \"stopwords_utf8_iso8859-15.txt\" -> ${MARIADB_INSTALL_DIR}.." +if [[ ! -d "/etc/mysql" ]]; then + + echononl "Erstelle Verzeichnis '/etc/mysql' .." + echo "" >> ${logdir}/main.log + echo "## - Erstelle Verzeichnis '/etc/mysql' .." >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "mkdir \"/etc/mysql\"" >> ${logdir}/main.log + mkdir "/etc/mysql" >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error "Konnte Verzeichnis '/etc/mysql' nicht erstellen" + fi + +else + + if [[ -f "/etc/mysql/my.cnf" ]]; then + echononl "Backup Symlink/Datei '/etc/mysql/my.cnf' .." + echo "" >> ${logdir}/main.log + echo "## - Backup Symlink/Datei '/etc/mysql/my.cnf' .." >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "mv \"/etc/mysql/my.cnf\" \"/etc/mysql/my.cnf.${_backup_date}\"" >> ${logdir}/main.log + mv "/etc/mysql/my.cnf" "/etc/mysql/my.cnf.${_backup_date}" >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error "Konnte Symlink/Datei '/etc/mysql/my.cnf' nicht sichern." + fi + fi + +fi + +echononl "Erstelle Symlink /etc/mysql/my.cnf --> ${MARIADB_INSTALL_DIR}/etc/my.cnf" +echo "" >> ${logdir}/main.log +echo "## - Erstelle Symlink /etc/mysql/my.cnf --> ${MARIADB_INSTALL_DIR}/etc/my.cnf" >> ${logdir}/main.log +echo "## -" >> ${logdir}/main.log +echo "ln -s \"$(dirname \"${MARIADB_INSTALL_DIR}\")/mysql/etc/my.cnf\" \"/etc/mysql/\"" >> ${logdir}/main.log +ln -s "$(dirname "${MARIADB_INSTALL_DIR}")/mysql/etc/my.cnf" "/etc/mysql/my.cnf" >> ${logdir}/main.log 2>&1 +if [ "$?" = "0" ]; then + echo_ok +else + echo_failed + error "Konnte Symlink /etc/mysql/my.cnf --> ${MARIADB_INSTALL_DIR}/etc/my.cnf nicht erstellen." +fi + + +echononl "Kopiere 'stopwords_utf8_iso8859-15.txt' -> ${MARIADB_INSTALL_DIR}.." if [ -f "${MARIADB_SRC_BASE_DIR}/stopwords_utf8_iso8859-15.txt" ];then + echo "" >> ${logdir}/main.log + echo "## - Kopiere 'stopwords_utf8_iso8859-15.txt' -> ${MARIADB_INSTALL_DIR}" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "cp ${MARIADB_SRC_BASE_DIR}/stopwords_utf8_iso8859-15.txt ${MARIADB_INSTALL_DIR}" >> ${logdir}/main.log + cp ${MARIADB_SRC_BASE_DIR}/stopwords_utf8_iso8859-15.txt ${MARIADB_INSTALL_DIR} if [ "$?" = "0" ]; then echo_ok echononl "Aktiviere Stopword Datei.." - echo "" >> ${logdir}/main.log - echo "perl -i -n -p -e \"s/^(\s*#\s*)(ft_stopword_file.*)/#\1\2\n\2/\" /usr/local/mysql/my.cnf" >> ${logdir}/main.log - perl -i -n -p -e "s/^(\s*#\s*)(ft_stopword_file.*)/#\1\2\n\2/" /usr/local/mysql/my.cnf >> ${logdir}/main.log 2>&1 - if [ "$?" = "0" ]; then - echo_ok + if ! grep -q -E "^\s*ft_stopword_file.*" "${MARIADB_INSTALL_DIR}/etc/my.cnf" 2> /dev/null ; then + echo "" >> ${logdir}/main.log + echo "## - Aktiviere Stopword Datei" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "perl -i -n -p -e \"s/^(\s*#\s*)(ft_stopword_file.*)/#\1\2\n\2/\" ${MARIADB_INSTALL_DIR}/etc/my.cnf" >> ${logdir}/main.log + perl -i -n -p -e "s/^(\s*#\s*)(ft_stopword_file.*)/#\1\2\n\2/" ${MARIADB_INSTALL_DIR}/etc/my.cnf >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + warn "Konnte Stopword Datei \"stopwords_utf8_iso8859-15.txt\" nicht aktivieren." + fi else - echo_failed - warn "Konnte Stopword Datei \"stopwords_utf8_iso8859-15.txt\" nicht aktivieren." + echo_skipped fi else @@ -2008,263 +3796,594 @@ else warn "Konnte ${MARIADB_SRC_BASE_DIR}/stopwords_utf8_iso8859-15.txt finden." fi -echo -echononl "Richte MySQL Systemtabellen ein.." -cd $MARIADB_INSTALL_DIR -echo "" >> ${logdir}/main.log -echo "./scripts/mysql_install_db \ " >> ${logdir}/main.log -echo " --user=$MARIADB_USER \ " >> ${logdir}/main.log -echo " --basedir=$MARIADB_INSTALL_DIR \ " >> ${logdir}/main.log -echo " --datadir=$MARIADB_DATA_DIR \ " >> ${logdir}/main.log -echo " --language=$MARIADB_INSTALL_DIR/share/german" >> ${logdir}/main.log -echo "" >> ${logdir}/main.log -./scripts/mysql_install_db \ - --basedir=$MARIADB_INSTALL_DIR \ - --datadir=$MARIADB_DATA_DIR \ - --user=$MARIADB_USER \ - >> ${logdir}/main.log 2>&1 -if [ "$?" = "0" ]; then - echo_ok -else - echo_failed - fatal Das Einrichten der MySQL Systemtabellen ist fehlgeschlagen.. -fi +if $INSTALL_SYSTEMD_SERVICE ; then -echononl "Create directory \"mysql-files\".." -cd $MARIADB_INSTALL_DIR -echo "" >> ${logdir}/main.log -echo "mkdir mysql-files" >> ${logdir}/main.log -mkdir mysql-files >> ${logdir}/main.log 2>&1 -if [ "$?" = "0" ]; then - echo_ok -else - echo_failed -fi + echononl "Kopiere Service File nach '/etc/systemd/system'.." + echo "" >> ${logdir}/main.log + echo "## - Kopiere Service File nach '/etc/systemd/system'" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "cp \"${MARIADB_INSTALL_DIR}/support-files/systemd/mariadb.service\" /etc/systemd/system/$MARIADB_SERVICE_FILE" >> ${logdir}/main.log + cp "${MARIADB_INSTALL_DIR}/support-files/systemd/mariadb.service" /etc/systemd/system/$MARIADB_SERVICE_FILE >> ${logdir}/main.log 2>&1 -echononl "Change rights (770) to directory \"mysql-files\".." -echo "chmod 770 mysql-files" >> ${logdir}/main.log -chmod 770 ${MARIADB_INSTALL_DIR}/mysql-files >> ${logdir}/main.log 2>&1 -if [ "$?" = "0" ]; then - echo_ok -else - echo_failed -fi + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "Kopieren Service File nach '/etc/systemd/system/${MARIADB_SERVICE_FILE}' failed!" -echononl "Change owner ($MARIADB_USER) of directory \"mysql-files\".." -echo "chown $MARIADB_USER mysql-files" >> ${logdir}/main.log -chown $MARIADB_USER ${MARIADB_INSTALL_DIR}/mysql-files >> ${logdir}/main.log 2>&1 -if [ "$?" = "0" ]; then - echo_ok -else - echo_failed -fi + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/nno]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Abbruch durch User" + fi -echononl "Generate MySQL SSL Certificate and RSA Key.." -cd $MARIADB_INSTALL_DIR -if [[ -x "$MARIADB_INSTALL_DIRbin/mysql_ssl_rsa_setup" ]] ; then - echo "bin/mysql_ssl_rsa_setup --datadir=$MARIADB_DATA_DIR .." >> ${logdir}/main.log - bin/mysql_ssl_rsa_setup --datadir=$MARIADB_DATA_DIR >> ${logdir}/main.log 2>&1 + echononl "Set open_files_limit (LimitNOFILE) to $(ulimit -Hn) .." + echo "" >> ${logdir}/main.log + echo "## - Set open_files_limit (LimitNOFILE) to $(ulimit -Hn) .." >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + + if grep -q -E "^\s*LimitNOFILE\s*=" /etc/systemd/system/$MARIADB_SERVICE_FILE ; then + echo "perl -i -n -p -e \"s/^(\s*LimitNOFILE\s*=.*)/#\1\nLimitNOFILE = $(ulimit -Hn)/\" /etc/systemd/system/$MARIADB_SERVICE_FILE" >> ${logdir}/main.log + perl -i -n -p -e "s/^(\s*LimitNOFILE\s*=.*)/#\1\nLimitNOFILE = $(ulimit -Hn)/" \ + /etc/systemd/system/$MARIADB_SERVICE_FILE >> ${logdir}/main.log 2>&1 + _retval=$? + else + echo "LimitNOFILE = $(ulimit -Hn)" >> /etc/systemd/system/$MARIADB_SERVICE_FILE + _retval=$? + fi + if [ "$_retval" = "0" ]; then + echo_ok + else + echo_failed + error "Setting open_files_limit (LimitNOFILE) to $(ulimit -Hn) failed!" + fi + + echononl "Aktiviere den MariaDB Datenbank Service für den automatischem Start.." + echo "" >> ${logdir}/main.log + echo "## - Aktiviere den MariaDB Datenban Service für den automatischem Start" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "systemctl enable $MARIADB_SERVICE_FILE" >> ${logdir}/main.log + systemctl enable $MARIADB_SERVICE_FILE >> ${logdir}/main.log 2>&1 if [ "$?" = "0" ]; then echo_ok else echo_failed + error "Aktivieren des MariaDB Datenbank Service für den automatischem Start fehgeschalgen!" fi -else - echo_skipped - warn "Script for generating certificates (mysql_ssl_rsa_setup) is not supported" -fi -echononl "Setze Besitzer/Gruppe für das Datenbankverzeichnis.." -echo "" >> ${logdir}/main.log -echo "chown -R ${MARIADB_USER}:$MARIADB_GROUP $MARIADB_DATA_DIR" >> ${logdir}/main.log -chown -R ${MARIADB_USER}:$MARIADB_GROUP $MARIADB_DATA_DIR >> ${logdir}/main.log 2>&1 -if [ "$?" = "0" ]; then - echo_ok -else - echo_failed - error Konnte Besitzer/Gruppe für das Datenbankverzeichnis $MARIADB_DATA_DIR nicht setzen.. -fi - - -if ! $UPDATE_MARIADB ; then - - echononl "Starte MySQL Server beim Booten" + echononl "Run 'systemctl daemon-reload' to reload units." echo "" >> ${logdir}/main.log - if $SYSTEMD_EXISTS ; then - echo "systemctl enable mysql.server" >> ${logdir}/main.log - systemctl enable mysql.server >> ${logdir}/main.log 2>&1 - echo "systemctl daemon-reload" >> ${logdir}/main.log - systemctl daemon-reload >> ${logdir}/main.log 2>&1 + echo "## - Run 'systemctl daemon-reload' to reload units." >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "systemctl daemon-reload" >> ${logdir}/main.log + systemctl daemon-reload >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok else - echo "update-rc.d mysql.server defaults" >> ${logdir}/main.log - update-rc.d mysql.server defaults >> ${logdir}/main.log 2>&1 + echo_failed + error "Run 'systemctl daemon-reload' failed!" + fi + + +else + + if [ -h "/etc/init.d/${MARIADB_SYSV_INIT_SCRIPT}" ]; then + echononl "Entferne vorhandenen Symlink \"/etc/init.d/${MARIADB_SYSV_INIT_SCRIPT}\".." + echo "" >> ${logdir}/main.log + echo "## - Entferne vorhandenen Symlink \"/etc/init.d/${MARIADB_SYSV_INIT_SCRIPT}\"" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "rm /etc/init.d/${MARIADB_SYSV_INIT_SCRIPT}" >> ${logdir}/main.log + rm /etc/init.d/${MARIADB_SYSV_INIT_SCRIPT} >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error Kann Symlink /etc/init.d/${MARIADB_SYSV_INIT_SCRIPT} nicht entfernen.. + fi + fi + + if [ -f "/etc/init.d/${MARIADB_SYSV_INIT_SCRIPT}" ]; then + echononl "Entferne vorhandenen Datei \"/etc/init.d/${MARIADB_SYSV_INIT_SCRIPT}\".." + echo "" >> ${logdir}/main.log + echo "## - Entferne vorhandenen Datei \"/etc/init.d/${MARIADB_SYSV_INIT_SCRIPT}\"" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "rm /etc/init.d/${MARIADB_SYSV_INIT_SCRIPT}" >> ${logdir}/main.log + rm /etc/init.d/${MARIADB_SYSV_INIT_SCRIPT} >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error Kann Datei /etc/init.d/${MARIADB_SYSV_INIT_SCRIPT} nicht entfernen.. + fi + fi + + + echononl "Erstelle Symlink \"/etc/init.d/${MARIADB_SYSV_INIT_SCRIPT}\".." + echo "" >> ${logdir}/main.log + echo "## - Erstelle Symlink \"/etc/init.d/${MARIADB_SYSV_INIT_SCRIPT}\"" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "ln -s \"$(dirname $MARIADB_INSTALL_DIR)/mysql/support-files/${MARIADB_SYSV_INIT_SCRIPT}\" \"/etc/init.d/${MARIADB_SYSV_INIT_SCRIPT}\"" >> ${logdir}/main.log + ln -s "$(dirname $MARIADB_INSTALL_DIR)/mysql/support-files/${MARIADB_SYSV_INIT_SCRIPT}" /etc/init.d/${MARIADB_SYSV_INIT_SCRIPT} >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error "Kann Symlink $MARIADB_INSTALL_DIR/support-files/${MARIADB_SYSV_INIT_SCRIPT} --> /etc/init.d/${MARIADB_SYSV_INIT_SCRIPT} nicht erstellen.." + fi + + echononl "Setze ulimit im Startscript.." + echo "" >> ${logdir}/main.log + echo "## - Setze ulimit im Startscript" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "sed -i \"1 s/\(.*\)/\1\n\nulimit -n \\\`ulimit -Hn\\\`\n/\" /etc/init.d/${MARIADB_SYSV_INIT_SCRIPT}" >> ${logdir}/main.log + sed -i "1 s/\(.*\)/\1\n\nulimit -n \`ulimit -Hn\`\n/" $(realpath /etc/init.d/${MARIADB_SYSV_INIT_SCRIPT}) >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error "Kann \"ulimit\" im Startscript nicht setzen /etc/init.d/${MARIADB_SYSV_INIT_SCRIPT} nicht setzen.." + fi + + echononl "Aktiviere den MariaDB Datenbank Service für den automatischem Start" + echo "" >> ${logdir}/main.log + echo "## - Aktiviere den MariaDB Datenbank Service für den automatischem Start" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + if $SYSTEMD_EXISTS ; then + echo "systemctl enable ${MARIADB_SYSV_INIT_SCRIPT}" >> ${logdir}/main.log + systemctl enable ${MARIADB_SYSV_INIT_SCRIPT} >> ${logdir}/main.log 2>&1 + else + echo "update-rc.d ${MARIADB_SYSV_INIT_SCRIPT} defaults" >> ${logdir}/main.log + update-rc.d ${MARIADB_SYSV_INIT_SCRIPT} defaults >> ${logdir}/main.log 2>&1 fi if [ "$?" = "0" ]; then echo_ok else echo_failed if $SYSTEMD_EXISTS ; then - error "Konnte \"mysql.server\" im systemd nicht enablen.." + error "Konnte \"${MARIADB_SYSV_INIT_SCRIPT}\" im systemd nicht aktivieren.." else - error "Konnte MySQL Init Script Links (autom. boot) nicht erstellen.." + error "Konnte MariaDB Run Level Links (autom. boot) nicht erstellen.." fi fi - echononl "Starte MySQL Datenbankserver.." - echo "" >> ${logdir}/main.log + echononl "Run 'systemctl daemon-reload' to reload units." if $SYSTEMD_EXISTS ; then - echo "systemctl start mysql.server" >> ${logdir}/main.log - systemctl start mysql.server >> ${logdir}/main.log 2>&1 + echo "" >> ${logdir}/main.log + echo "## - Run 'systemctl daemon-reload' to reload units." >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "systemctl daemon-reload" >> ${logdir}/main.log + systemctl daemon-reload >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error "Run 'systemctl daemon-reload' failed!" + fi else - echo "/etc/init.d/mysql.server start" >> ${logdir}/main.log - /etc/init.d/mysql.server start >> ${logdir}/main.log 2>&1 + echo_skipped + fi + +fi + + +## ----- +## - Starte MariaDB Datenbank Service +## ----- + +echo "" +echo "" +echo -e "\033[37m\033[1mStarte MariaDB Datenbank Service\033[m" +echo "" + +echo "" >> ${logdir}/main.log +echo "" >> ${logdir}/main.log +echo "## -----" >> ${logdir}/main.log +echo "## - Starte MariaDB Datenbank Service" >> ${logdir}/main.log +echo "## -----" >> ${logdir}/main.log + +echononl "Starte MariaDB Datenbankserver.." +echo "" >> ${logdir}/main.log +echo "## - Starte MariaDB Datenbankserver" >> ${logdir}/main.log +echo "## -" >> ${logdir}/main.log +if $INSTALL_SYSTEMD_SERVICE ; then + echo "systemctl start \"$MARIADB_SERVICE_FILE\"" >> ${logdir}/main.log + systemctl start "$MARIADB_SERVICE_FILE" >> ${logdir}/main.log 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error Konnte MariaDB Datenbankserver nicht starten.. + + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/nno]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Abbruch durch User" + + fi +else + if $SYSTEMD_EXISTS ; then + echo "systemctl start ${MARIADB_SYSV_INIT_SCRIPT}" >> ${logdir}/main.log + systemctl start ${MARIADB_SYSV_INIT_SCRIPT} >> ${logdir}/main.log 2>&1 + else + echo "/etc/init.d/${MARIADB_SYSV_INIT_SCRIPT} start" >> ${logdir}/main.log + /etc/init.d/${MARIADB_SYSV_INIT_SCRIPT} start >> ${logdir}/main.log 2>&1 fi if [ "$?" = "0" ]; then echo_ok else echo_failed - error Konnte MySQL Datenbankserver nicht starten.. + error Konnte MariaDB Datenbankserver nicht starten.. + + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/nno]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Abbruch durch User" + fi fi -sleep 5 -echononl "Run \"mysql_upgrade -uroot\".." +sleep 2 + + + +## ----- +## - Konfiguration ( Teil 2) MariaDB Installation +## ----- + +echo "" +echo "" +echo -e "\033[37m\033[1mKonfiguration (Teil 2) der MariaDB $MARIADB_VERSION Installation\033[m" +echo "" + echo "" >> ${logdir}/main.log -echo "${MARIADB_INSTALL_DIR}/bin/mysql_upgrade -uroot" >> ${logdir}/main.log -${MARIADB_INSTALL_DIR}/bin/mysql_upgrade -uroot >> ${logdir}/main.log 2>&1 -if [ "$?" = "0" ]; then - echo_ok -else - echo_failed - error "Script \"mysql_upgrade -uroot\" failed!" -fi - -echononl "Delete empty User in table mysql.user.." echo "" >> ${logdir}/main.log -echo "${MARIADB_INSTALL_DIR}/bin/mysql -uroot mysql -N -s -e \"DELETE FROM user where User = ''\"" >> ${logdir}/main.log -${MARIADB_INSTALL_DIR}/bin/mysql -uroot mysql -N -s -e "DELETE FROM user where User = ''" >> ${logdir}/main.log 2>&1 -if [ "$?" = "0" ]; then - echo_ok -else - echo_failed - error "Deleting empty User in table mysql.user failed!" -fi +echo "## -----" >> ${logdir}/main.log +echo "## - Konfiguration (Teil 2) der MariaDB $MARIADB_VERSION Installation" >> ${logdir}/main.log +echo "## -----" >> ${logdir}/main.log -echononl "Delete database \"test\".." -echo "" >> ${logdir}/main.log -echo "${MARIADB_INSTALL_DIR}/bin/mysql -uroot mysql -N -s -e \"DROP DATABASE test\"" >> ${logdir}/main.log -${MARIADB_INSTALL_DIR}/bin/mysql -uroot mysql -N -s -e "DROP DATABASE test" >> ${logdir}/main.log 2>&1 -if [ "$?" = "0" ]; then - echo_ok -else - echo_failed - error "Dropping Database \"test\" failed!" -fi +if ! $UPDATE_MARIADB ; then -echononl "Delete entries for test database in table mysql.db" -echo "" >> ${logdir}/main.log -echo "${MARIADB_INSTALL_DIR}/bin/mysql -uroot mysql -N -s -e \"DELETE FROM db where Db LIKE 'test%'\"" >> ${logdir}/main.log -${MARIADB_INSTALL_DIR}/bin/mysql -uroot mysql -N -s -e "DELETE FROM db where Db LIKE 'test%'" >> ${logdir}/main.log 2>&1 -if [ "$?" = "0" ]; then - echo_ok -else - echo_failed - error "Deleting empty User in table mysql.user failed!" -fi + ## - Delete rows with empty 'User' from table mysql.user + ## - + echononl "Delete rows with empty 'User' from table mysql.user.." + echo "" >> ${logdir}/main.log + echo "## - Delete rows with empty 'User' from table mysql.user" >> ${logdir}/main.log + echo "## - " >> ${logdir}/main.log + echo "${MARIADB_INSTALL_DIR}/bin/mysql -uroot mysql -N -s -e \"DELETE FROM user where User = ''\"" >> ${logdir}/main.log + ${MARIADB_INSTALL_DIR}/bin/mysql -uroot mysql -N -s -e "DELETE FROM user where User = ''" >> ${logdir}/main.log 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "Deleting rows with empty 'User' from table mysql.user failed!" -#echononl "Setze root Passwort (authentication_string) für den MySQL Zugang" -#echo "" >> ${logdir}/main.log -#echo "${MARIADB_INSTALL_DIR}/bin/mysql -uroot mysql -N -s -e \"UPDATE user set authentication_string = password('$MARIADB_ROOT_PW')\"" >> ${logdir}/main.log -#${MARIADB_INSTALL_DIR}/bin/mysql -uroot mysql -N -s -e "UPDATE user set authentication_string = password('$MARIADB_ROOT_PW')" \ -# >> ${logdir}/main.log 2>&1 -#if [ "$?" = "0" ]; then -# echo_ok -#else -# echo_failed -# error Konnte MySQL root Zugang fü den MySQL Server nicht setzen.. -#fi + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/nno]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Abbruch durch User" + fi -echononl "Setze root Passwort (password) für den MySQL Zugang" -echo "" >> ${logdir}/main.log -echo "${MARIADB_INSTALL_DIR}/bin/mysql -uroot mysql -N -s -e \"UPDATE user set Password = password('$MARIADB_ROOT_PW')\"" >> ${logdir}/main.log -${MARIADB_INSTALL_DIR}/bin/mysql -uroot mysql -N -s -e "UPDATE user set Password = password('$MARIADB_ROOT_PW')" \ - >> ${logdir}/main.log 2>&1 -if [ "$?" = "0" ]; then - echo_ok -else - echo_failed - error Konnte MySQL root Zugang fü den MySQL Server nicht setzen.. -fi + ## - Drop database test + ## - + if [[ -d "${MARIADB_DATA_DIR}/test" ]]; then + echononl "Delete database 'test'.." + echo "" >> ${logdir}/main.log + echo "## - Delete database 'test'.." >> ${logdir}/main.log + echo "## - " >> ${logdir}/main.log + echo "${MARIADB_INSTALL_DIR}/bin/mysql -uroot mysql -N -s -e \"DROP DATABASE test\"" >> ${logdir}/main.log + ${MARIADB_INSTALL_DIR}/bin/mysql -uroot mysql -N -s -e "DROP DATABASE test" >> ${logdir}/main.log 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "Deleting database 'test' failed!" + + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/nno]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Abbruch durch User" + fi + + echononl "Delete rows concerning database 'test' from table 'mysql.db'.." + echo "" >> ${logdir}/main.log + echo "## - Delete rows concerning database 'test' from table 'mysql.db'.." >> ${logdir}/main.log + echo "## - " >> ${logdir}/main.log + echo "${MARIADB_INSTALL_DIR}/bin/mysql -uroot mysql -N -s -e \"DELETE FROM db WHERE Db LIKE 'test%'\"" >> ${logdir}/main.log + ${MARIADB_INSTALL_DIR}/bin/mysql -uroot mysql -N -s -e "DELETE FROM db WHERE Db LIKE 'test%'" >> ${logdir}/main.log 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error "Deleting rows concerning database 'test' from table 'mysql.db' failed!" + + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/nno]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Abbruch durch User" + fi + fi + + ## - Set root password + ## - + echononl "Setze root Passwort für den MariaDB Zugang" + echo "" >> ${logdir}/main.log + echo "## - Setze root Passwort für den MariaDB Zugang" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "${MARIADB_INSTALL_DIR}/bin/mysql -uroot mysql -N -s -e \"UPDATE user SET Password = password('$MARIADB_ROOT_PW') WHERE User = 'root'\"" >> ${logdir}/main.log + + ${MARIADB_INSTALL_DIR}/bin/mysql -uroot mysql -N -s -e "UPDATE user SET Password = password('$MARIADB_ROOT_PW') WHERE User = 'root'" \ + >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error Konnte root Passwort für den MariaDB Server nicht setzen.. + + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/nno]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Abbruch durch User" + fi + + ## - Flush privileges + ## - + echononl "Neu Einlesen der Berechtigung (MariaDB Server).." + echo "" >> ${logdir}/main.log + echo "## - Neu Einlesen der Berechtigung (MariaDB Server)" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "${MARIADB_INSTALL_DIR}/bin/mysql -uroot mysql -N -s -e \"FLUSH PRIVILEGES\"" >> ${logdir}/main.log + ${MARIADB_INSTALL_DIR}/bin/mysql -uroot mysql -N -s -e "FLUSH PRIVILEGES" >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error Das Laden/Erneuern der Berechtigungen für die MariaDB Datenbank ist fehlgeschlagen.. + + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/nno]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Abbruch durch User" + fi -echononl "Neu Einlesen der Berechtigung (MySQL Server).." -echo "" >> ${logdir}/main.log -echo "${MARIADB_INSTALL_DIR}/bin/mysql -uroot mysql -N -s -e \"FLUSH PRIVILEGES\"" >> ${logdir}/main.log -${MARIADB_INSTALL_DIR}/bin/mysql -uroot mysql -N -s -e "FLUSH PRIVILEGES" >> ${logdir}/main.log 2>&1 -if [ "$?" = "0" ]; then - echo_ok else - echo_failed - error Das Laden/Erneuern der Berechtigungen für die MySQL Datenbank ist fehlgeschlagen.. + + ## - Run mysql_upgrade + ## - + echononl "Run 'mysql_upgrade -uroot' - this may take some (long) time.." + echo "" >> ${logdir}/main.log + echo "## - Run 'mysql_upgrade -uroot' - this may take some (long) time" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "${MARIADB_INSTALL_DIR}/bin/MARIADB_upgrade -uroot -p$MARIADB_ROOT_PW" >> ${logdir}/main.log + ${MARIADB_INSTALL_DIR}/bin/mysql_upgrade -uroot -p$MARIADB_ROOT_PW >> ${logdir}/main.log 2>&1 + ret_val=$? + if [[ $ret_val -eq 0 ]] ; then + echo_ok + elif [[ $ret_val -eq 2 ]] ; then + echo_skipped + warn "Return Code was '2' - it means MariaDB is already upgraded to ${MARIADB_VERSION}" + else + echo_failed + error "Script \"mysql_upgrade -uroot\" failed!" + + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/nno]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Abbruch durch User" + fi + fi -echo -echononl "Erstelle Passwort für maintance (MySQL) User.." -echo "" >> ${logdir}/main.log -PW_GEN=`which pwgen` -if [ -z "$PW_GEN" ]; then - echo "_maint_passwd=\`cat /dev/urandom|tr -dc \"a-zA-Z0-9-_\$\?\" | fold -w16 | head -n 1\`" >> ${logdir}/main.log - _maint_passwd=`cat /dev/urandom|tr -dc "a-zA-Z0-9-_\$\?" | fold -w16 | head -n 1` >> ${logdir}/main.log 2>&1 -else - echo "_maint_passwd=\`$PW_GEN -v -B 16 1\`" >> ${logdir}/main.log - _maint_passwd=`$PW_GEN -v -B 16 1` >> ${logdir}/main.log 2>&1 -fi -if [ "$?" = "0" ]; then - echo_ok -else - echo_failed - error Konnte Passwort für maintance \(MySQL\) User nicht erstellen.. + +_sys_maint_cnf_needed=false +if $UPDATE_MARIADB ; then + echononl "Copy 'sys-maint.cnf from old installation to the new one.." + echo "" >> ${logdir}/main.log + echo "## - Copy 'sys-maint.cnf from old installation to the new one" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + if [[ "$CURRENT_VERSION" = "$MARIADB_VERSION" ]] ; then + echo "cp -a \"$MARIADB_INSTALL_DIR.$_backup_date/sys-maint.cnf\" \"${MARIADB_INSTALL_DIR}/sys-maint.cnf\"" \ + >> ${logdir}/main.log + cp -a $MARIADB_INSTALL_DIR.$_backup_date/sys-maint.cnf "${MARIADB_INSTALL_DIR}/sys-maint.cnf" \ + >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + _sys_maint_cnf_needed=true + error "Konnte Konfigurationsdatei 'sys-maint.cnf' nicht vom alten in das neue Installations Verz.kopieren.." + + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/nno]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Abbruch durch User" + fi + else + echo "cp -a \"$(realpath ${MARIADB_CUR_INSTALL_DIR}/sys-maint.cnf)\" \"${MARIADB_INSTALL_DIR}/sys-maint.cnf\"" \ + >> ${logdir}/main.log + cp -a "$(realpath ${MARIADB_CUR_INSTALL_DIR}/sys-maint.cnf)" "${MARIADB_INSTALL_DIR}/sys-maint.cnf" \ + >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + _sys_maint_cnf_needed=true + error "Konnte Konfigurationsdatei 'sys-maint.cnf' nicht vom alten in das neue Installations Verz.kopieren.." + + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/nno]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Abbruch durch User" + fi + fi + + if [[ ! -f "${MARIADB_INSTALL_DIR}/sys-maint.cnf" ]] ; then + _sys_maint_cnf_needed=true + fi fi -_maint_user=sys-maint -echononl "Erstelle maintance MySQL User \"${_maint_user}\" - localhost.." -echo "" >> ${logdir}/main.log -echo "${MARIADB_INSTALL_DIR}/bin/mysql -uroot -p$MARIADB_ROOT_PW mysql -N -s -e \"GRANT ALL ON *.* TO '${_maint_user}'@'localhost' IDENTIFIED BY '$_maint_passwd'\"" >> ${logdir}/main.log -${MARIADB_INSTALL_DIR}/bin/mysql -uroot -p$MARIADB_ROOT_PW mysql -N -s -e "GRANT ALL ON *.* TO '${_maint_user}'@'localhost' IDENTIFIED BY '$_maint_passwd'" >> ${logdir}/main.log 2>&1 -if [ "$?" = "0" ]; then - echo_ok -else - echo_failed - error Konnte \(MySQL\) User \"${_maint_user}\" nicht erstellen.. -fi +if ! $UPDATE_MARIADB || $_sys_maint_cnf_needed ; then + echo + echononl "Erstelle Passwort für maintance (MariaDB) User.." + echo "" >> ${logdir}/main.log + echo "## - Erstelle Passwort für maintance (MariaDB) User" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + PW_GEN=`which pwgen` + if [ -z "$PW_GEN" ]; then + echo "_maint_passwd=\`cat /dev/urandom|tr -dc \"a-zA-Z0-9-_\$\?\" | fold -w16 | head -n 1\`" >> ${logdir}/main.log + _maint_passwd=`cat /dev/urandom|tr -dc "a-zA-Z0-9-_\$\?" | fold -w16 | head -n 1` >> ${logdir}/main.log 2>&1 + else + echo "_maint_passwd=\`$PW_GEN -v -B 16 1\`" >> ${logdir}/main.log + _maint_passwd=`$PW_GEN -v -B 16 1` >> ${logdir}/main.log 2>&1 + fi + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error Konnte Passwort für maintance \(MariaDB\) User nicht erstellen.. -echononl "Give \"Grant\" permission to MySQL User \"${_maint_user}\".." -echo "" >> ${logdir}/main.log -echo "${MARIADB_INSTALL_DIR}/bin/mysql -uroot -p$MARIADB_ROOT_PW mysql -N -s -e \"UPDATE user SET Grant_priv = 'y' WHERE user = '${_maint_user}';\"" >> ${logdir}/main.log -${MARIADB_INSTALL_DIR}/bin/mysql -uroot -p$MARIADB_ROOT_PW mysql -N -s -e "UPDATE user SET Grant_priv = 'y' WHERE user = '${_maint_user}';" >> ${logdir}/main.log 2>&1 -if [ "$?" = "0" ]; then - echo_ok -else - echo_failed - error Giving \"Grant\"-permission to \(MySQL\) User \"${_maint_user}\" failed -fi + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/nno]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Abbruch durch User" + fi -echononl "Neu Einlesen der Berechtigung (MySQL Server).." -echo "" >> ${logdir}/main.log -echo "${MARIADB_INSTALL_DIR}/bin/mysql -uroot -p$MARIADB_ROOT_PW mysql -N -s -e \"FLUSH PRIVILEGES\"" >> ${logdir}/main.log -${MARIADB_INSTALL_DIR}/bin/mysql -uroot -p$MARIADB_ROOT_PW mysql -N -s -e "FLUSH PRIVILEGES" >> ${logdir}/main.log 2>&1 -if [ "$?" = "0" ]; then - echo_ok -else - echo_failed - error Das Laden/Erneuern der Berechtigungen für die MySQL Datenbank ist fehlgeschlagen.. -fi + _maint_user=sys-maint + echononl "Erstelle maintance MariaDB User '${_maint_user}' - localhost.." + echo "" >> ${logdir}/main.log + echo "## - Erstelle maintance MariaDB User '${_maint_user}' - localhost" >> ${logdir}/main.log + echo "" >> ${logdir}/main.log + echo "${MARIADB_INSTALL_DIR}/bin/mysql -uroot -p$MARIADB_ROOT_PW mysql -N -s -e \"GRANT ALL ON *.* TO '${_maint_user}'@'localhost' IDENTIFIED BY '$_maint_passwd'\"" >> ${logdir}/main.log + ${MARIADB_INSTALL_DIR}/bin/mysql -uroot -p$MARIADB_ROOT_PW mysql -N -s -e "GRANT ALL ON *.* TO '${_maint_user}'@'localhost' IDENTIFIED BY '$_maint_passwd'" >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error Konnte \(MariaDB\) User \"${_maint_user}\" nicht erstellen.. + + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/nno]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Abbruch durch User" + fi + + echononl "Give 'Grant' permission to MariaDB User '${_maint_user}'.." + echo "" >> ${logdir}/main.log + echo "## - Give 'Grant' permission to MariaDB User '${_maint_user}'" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "${MARIADB_INSTALL_DIR}/bin/mysql -uroot -p$MARIADB_ROOT_PW mysql -N -s -e \"UPDATE user SET Grant_priv = 'y' WHERE user = '${_maint_user}';\"" >> ${logdir}/main.log + ${MARIADB_INSTALL_DIR}/bin/mysql -uroot -p$MARIADB_ROOT_PW mysql -N -s -e "UPDATE user SET Grant_priv = 'y' WHERE user = '${_maint_user}';" >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error Giving \"Grant\"-permission to \(MariaDB\) User \"${_maint_user}\" failed + + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/nno]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Abbruch durch User" + fi + + echononl "Neu Einlesen der Berechtigung (MariaDB Server).." + echo "" >> ${logdir}/main.log + echo "## - Neu Einlesen der Berechtigung (MariaDB Server)" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "${MARIADB_INSTALL_DIR}/bin/mysql -uroot -p$MARIADB_ROOT_PW mysql -N -s -e \"FLUSH PRIVILEGES\"" >> ${logdir}/main.log + ${MARIADB_INSTALL_DIR}/bin/mysql -uroot -p$MARIADB_ROOT_PW mysql -N -s -e "FLUSH PRIVILEGES" >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error Das Laden/Erneuern der Berechtigungen für die MariaDB Datenbank ist fehlgeschlagen.. + + echononl "continue anyway [yes/no]: " + read OK + OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')" + while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do + echononl "Wrong entry! - repeat [yes/nno]: " + read OK + done + [[ $OK = "yes" ]] || fatal "Abbruch durch User" + fi -_maint_conf_file=${MARIADB_INSTALL_DIR}/sys-maint.cnf -echononl "Erstelle ${_maint_conf_file}.." -cat << EOF > ${MARIADB_INSTALL_DIR}/sys-maint.cnf + echononl "Erstelle '${MARIADB_INSTALL_DIR}/sys-maint.cnf'.." + echo "" >> ${logdir}/main.log + echo "## - Erstelle '${MARIADB_INSTALL_DIR}/sys-maint.cnf'" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "cat << EOF > ${MARIADB_INSTALL_DIR}/sys-maint.cnf +[client] +host = localhost +user = $_maint_user +password = $_maint_passwd +socket = $MARIADB_UNIX_SOCKET +[mysql_upgrade] +host = localhost +user = $_maint_user +password = $_maint_passwd +socket = $MARIADB_UNIX_SOCKET +basedir = /usr +EOF" >> ${logdir}/main.log + + cat << EOF > ${MARIADB_INSTALL_DIR}/sys-maint.cnf [client] host = localhost user = $_maint_user @@ -2277,19 +4396,25 @@ password = $_maint_passwd socket = $MARIADB_UNIX_SOCKET basedir = /usr EOF -if [ "$?" = "0" ]; then - echo_ok -else - echo_failed - error Konnte Konfigurationsdatei \"${MARIADB_INSTALL_DIR}/sys-maint.cnf\" nicht erstellen.. + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + error Konnte Konfigurationsdatei \"${MARIADB_INSTALL_DIR}/sys-maint.cnf\" nicht erstellen.. + fi fi -echononl "Erstelle Logrotate Definitionsdatei /etc/logrotate.d/mysql.." -cat << EOF > /etc/logrotate.d/mysql -$_mariadb_log -$_mariadb_error_log -$_mariadb_slow_query_log +sys_maint_file="$(dirname $MARIADB_INSTALL_DIR)/mysql/sys-maint.cnf" +echononl "Erstelle Logrotate Definitionsdatei '/etc/logrotate.d/mysql'.." +echo "" >> ${logdir}/main.log +echo "## - Erstelle Logrotate Definitionsdatei /etc/logrotate.d/mysql" >> ${logdir}/main.log +echo "## -" >> ${logdir}/main.log +echo "cat << EOF > /etc/logrotate.d/mysql +$mariadb_log +$mariadb_error_log +$mariadb_slow_query_log +$mariadb_groonga_log { daily rotate 7 @@ -2298,9 +4423,33 @@ $_mariadb_slow_query_log compress sharedscripts postrotate - MYSQL="`dirname $MARIADB_INSTALL_DIR`/mysql/bin/mysql --defaults-file=$_maint_conf_file" - MYADMIN="`dirname $MARIADB_INSTALL_DIR`/mysql/bin/mysqladmin --defaults-file=$_maint_conf_file" - if [ -z "\`\$MYADMIN ping 2>/dev/null\`" ]; then + MYSQL=\"$(dirname $MARIADB_INSTALL_DIR)/mysql/bin/mysql --defaults-file=$sys_maint_file\" + MYADMIN=\"$(dirname $MARIADB_INSTALL_DIR)/mysql/bin/mysqladmin --defaults-file=$sys_maint_file\" + if [ -z \"\$(\$MYADMIN ping 2>/dev/null)\" ]; then + echo "Warning: no mysqld running or missing sys-maint user?" + else + \$MYSQL -e 'select @@global.long_query_time into @lqt_save; set global long_query_time=2000; select sleep(2); FLUSH LOGS; select sleep(2); set global long_query_time=@lqt_save;' > /dev/null + fi + endscript +} +EOF" >> ${logdir}/main.log + +cat << EOF > /etc/logrotate.d/mysql +$mariadb_log +$mariadb_error_log +$mariadb_slow_query_log +$mariadb_groonga_log +{ + daily + rotate 7 + missingok + create 644 $MARIADB_USER $MARIADB_GROUP + compress + sharedscripts + postrotate + MYSQL="$(dirname $MARIADB_INSTALL_DIR)/mysql/bin/mysql --defaults-file=$sys_maint_file" + MYADMIN="$(dirname $MARIADB_INSTALL_DIR)/mysql/bin/mysqladmin --defaults-file=$sys_maint_file" + if [ -z "\$(\$MYADMIN ping 2>/dev/null)" ]; then echo "Warning: no mysqld running or missing sys-maint user?" else \$MYSQL -e 'select @@global.long_query_time into @lqt_save; set global long_query_time=2000; select sleep(2); FLUSH LOGS; select sleep(2); set global long_query_time=@lqt_save;' > /dev/null @@ -2315,6 +4464,35 @@ else error Konnte Logrotate Definitionsdatei \"/etc/logrotate.d/mysql\" nicht erstellen.. fi - echo -exit +echononl "Reenable crontab for user root .." +if $_crontab_found ; then + echo "" >> ${logdir}/main.log + echo "Reenable crontab for user root" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "crontab -u root $_CRONTAB_BAKUP_FILE" >> ${logdir}/main.log + crontab -u root $_CRONTAB_BAKUP_FILE >> ${logdir}/main.log 2>&1 + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + fi + + echononl "Remove crontab backup file .." + echo "" >> ${logdir}/main.log + echo "## - Remove crontab backup file" >> ${logdir}/main.log + echo "## -" >> ${logdir}/main.log + echo "rm $_CRONTAB_BAKUP_FILE" >> ${logdir}/main.log + rm -f $_CRONTAB_BAKUP_FILE + if [ "$?" = "0" ]; then + echo_ok + else + echo_failed + fi +else + echo_skipped +fi + +info "See '${logdir}/main.log' for more details." + +clean_up 0