update script mysql (to manage debian 8 or 9)

This commit is contained in:
AleaJactaEst 2018-04-05 22:34:26 +02:00
parent 07e05605f6
commit 6eda63e517
3 changed files with 59 additions and 10 deletions

View file

@ -125,7 +125,13 @@ sleep 1
msg_debug "configure password root for database" msg_debug "configure password root for database"
/usr/bin/mysqladmin -u root password '' || exit 2 /usr/bin/mysqladmin -u root password '' || exit 2
if [ $(get_debian_version) -lt 9 ]
then
mysql -u root -e "GRANT ALL PRIVILEGES on *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '"$(awk '{if($1 == "password"){print $3;exit 0}}' /etc/mysql/debian.cnf)"' WITH GRANT OPTION; FLUSH PRIVILEGES;" || exit 2 mysql -u root -e "GRANT ALL PRIVILEGES on *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '"$(awk '{if($1 == "password"){print $3;exit 0}}' /etc/mysql/debian.cnf)"' WITH GRANT OPTION; FLUSH PRIVILEGES;" || exit 2
else
msg_debug "nothing"
#mysql -u root -e "GRANT ALL PRIVILEGES on *.* TO 'debian-sys-maint'@'localhost' WITH GRANT OPTION; FLUSH PRIVILEGES;"
fi
#################################### ####################################
# Stop Database # Stop Database

View file

@ -230,6 +230,26 @@ function wait_all_job()
return $code return $code
} }
######################
# Debian information
######################
function get_debian_info()
{
cat /etc/debian_version
}
function get_debian_version()
{
local DEBIAN_INFO=$(get_debian_info)
echo ${DEBIAN_INFO%%.*}
}
function get_debian_release()
{
local DEBIAN_INFO=$(get_debian_info)
echo ${DEBIAN_INFO#*.}
}
###################### ######################
# #
###################### ######################

View file

@ -28,6 +28,30 @@ options:
EOF EOF
} }
update_mysql_config()
{
if [ -z "$1" ]
then
msg_error "missing configuration file"
return
fi
if [ -f "$1" ]
then
msg_debug "update configuration $1"
sed -i -r 's/^user[[:space:]]+=[[:space:]]+(.*)/user = gameserver/g' $1 || exit 2
sed -i -r 's/^datadir[[:space:]]+=[[:space:]]+(.*)/datadir = \/home\/gameserver\/database/g' $1 || exit 2
sed -i -r 's/^log_error[[:space:]]+=[[:space:]]+(.*)/log_error = \/home\/gameserver\/log\/mysql\/error\.log/g' $1 || exit 2
sed -i -r 's/^(#*)general_log_file[[:space:]]+=(.*)/general_log_file = \/home\/gameserver\/log\/mysql\/mysql\.log/g' $1 || exit 2
sed -i -r 's/^(#*)general_log[[:space:]]+=(.*)/general_log = 1/g' $1 || exit 2
sed -i -r 's/^(#*)slow_query_log_file[[:space:]]+=(.*)/slow_query_log_file = \/home\/gameserver\/log\/mysql\/mysql-slow\.log/g' $1 || exit 2
sed -i -r 's/^(#*)slow_query_log[[:space:]]+=(.*)/slow_query_log = 1/g' $1 || exit 2
sed -i -r 's/^(#*)long_query_time[[:space:]]+=(.*)/long_query_time = 2/g' $1 || exit 2
sed -i -r 's/^(#*)log_queries_not_using_indexes(.*)/log_queries_not_using_indexes/g' $1 || exit 2
else
msg_debug "nothing for $1"
fi
}
##################### #####################
# MAIN # MAIN
##################### #####################
@ -66,15 +90,14 @@ source /opt/khanat_config.sh
msg_debug "Create database for account gameserver" msg_debug "Create database for account gameserver"
# Create database on gameserver account (and change directory database) # Create database on gameserver account (and change directory database)
sed -i -r 's/^user[[:space:]]+=[[:space:]]+(.*)/user = gameserver/g' /etc/mysql/my.cnf || exit 2 if [ $(get_debian_version) -lt 9 ]
sed -i -r 's/^datadir[[:space:]]+=[[:space:]]+(.*)/datadir = \/home\/gameserver\/database/g' /etc/mysql/my.cnf || exit 2 then
sed -i -r 's/^log_error[[:space:]]+=[[:space:]]+(.*)/log_error = \/home\/gameserver\/log\/mysql\/error\.log/g' /etc/mysql/my.cnf || exit 2 # old configuration mysql (on debian 8-)
sed -i -r 's/^(#*)general_log_file[[:space:]]+=(.*)/general_log_file = \/home\/gameserver\/log\/mysql\/mysql\.log/g' /etc/mysql/my.cnf || exit 2 update_mysql_config '/etc/mysql/my.cnf'
sed -i -r 's/^(#*)general_log[[:space:]]+=(.*)/general_log = 1/g' /etc/mysql/my.cnf || exit 2 else
sed -i -r 's/^(#*)slow_query_log_file[[:space:]]+=(.*)/slow_query_log_file = \/home\/gameserver\/log\/mysql\/mysql-slow\.log/g' /etc/mysql/my.cnf || exit 2 # For mariadb (on debian 9)
sed -i -r 's/^(#*)slow_query_log[[:space:]]+=(.*)/slow_query_log = 1/g' /etc/mysql/my.cnf || exit 2 update_mysql_config '/etc/mysql/mariadb.conf.d/50-server.cnf'
sed -i -r 's/^(#*)long_query_time[[:space:]]+=(.*)/long_query_time = 2/g' /etc/mysql/my.cnf || exit 2 fi
sed -i -r 's/^(#*)log_queries_not_using_indexes(.*)/log_queries_not_using_indexes/g' /etc/mysql/my.cnf || exit 2
mkdir -p /home/gameserver/database/ || exit 2 mkdir -p /home/gameserver/database/ || exit 2
chown gameserver:$(id -g -n gameserver) /home/gameserver/database/ || exit 2 chown gameserver:$(id -g -n gameserver) /home/gameserver/database/ || exit 2