diff --git a/server/debian/common/servercontainer_configure_mysql.sh b/server/debian/common/servercontainer_configure_mysql.sh index 05b43a1..04ee2e1 100755 --- a/server/debian/common/servercontainer_configure_mysql.sh +++ b/server/debian/common/servercontainer_configure_mysql.sh @@ -125,7 +125,13 @@ sleep 1 msg_debug "configure password root for database" /usr/bin/mysqladmin -u root password '' || 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 +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 +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 diff --git a/server/debian/common/servercontainer_function.sh b/server/debian/common/servercontainer_function.sh index 5584b0c..ec8fcdb 100755 --- a/server/debian/common/servercontainer_function.sh +++ b/server/debian/common/servercontainer_function.sh @@ -230,6 +230,26 @@ function wait_all_job() 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#*.} +} + ###################### # ###################### diff --git a/server/debian/common/servercontainer_init_mysql.sh b/server/debian/common/servercontainer_init_mysql.sh index a383e10..8a41296 100755 --- a/server/debian/common/servercontainer_init_mysql.sh +++ b/server/debian/common/servercontainer_init_mysql.sh @@ -28,6 +28,30 @@ options: 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 ##################### @@ -66,15 +90,14 @@ source /opt/khanat_config.sh msg_debug "Create database for account gameserver" # 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 -sed -i -r 's/^datadir[[:space:]]+=[[:space:]]+(.*)/datadir = \/home\/gameserver\/database/g' /etc/mysql/my.cnf || exit 2 -sed -i -r 's/^log_error[[:space:]]+=[[:space:]]+(.*)/log_error = \/home\/gameserver\/log\/mysql\/error\.log/g' /etc/mysql/my.cnf || exit 2 -sed -i -r 's/^(#*)general_log_file[[:space:]]+=(.*)/general_log_file = \/home\/gameserver\/log\/mysql\/mysql\.log/g' /etc/mysql/my.cnf || exit 2 -sed -i -r 's/^(#*)general_log[[:space:]]+=(.*)/general_log = 1/g' /etc/mysql/my.cnf || exit 2 -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 -sed -i -r 's/^(#*)slow_query_log[[:space:]]+=(.*)/slow_query_log = 1/g' /etc/mysql/my.cnf || exit 2 -sed -i -r 's/^(#*)long_query_time[[:space:]]+=(.*)/long_query_time = 2/g' /etc/mysql/my.cnf || exit 2 -sed -i -r 's/^(#*)log_queries_not_using_indexes(.*)/log_queries_not_using_indexes/g' /etc/mysql/my.cnf || exit 2 +if [ $(get_debian_version) -lt 9 ] +then + # old configuration mysql (on debian 8-) + update_mysql_config '/etc/mysql/my.cnf' +else + # For mariadb (on debian 9) + update_mysql_config '/etc/mysql/mariadb.conf.d/50-server.cnf' +fi mkdir -p /home/gameserver/database/ || exit 2 chown gameserver:$(id -g -n gameserver) /home/gameserver/database/ || exit 2