2017-11-21 21:10:28 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# Prepare/Configure MySQL
|
|
|
|
# Copyright (C) 2017 AleaJactaEst
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
usage()
|
|
|
|
{
|
|
|
|
cat << EOF
|
|
|
|
usage:$0 [options]
|
|
|
|
prepare mysql (create directory, update configuration)
|
|
|
|
|
|
|
|
options:
|
|
|
|
-h, --help : Show this help
|
|
|
|
-d, --debug : Show debug message
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2018-04-05 20:34:26 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2017-11-21 21:10:28 +00:00
|
|
|
#####################
|
|
|
|
# MAIN
|
|
|
|
#####################
|
|
|
|
source /opt/servercontainer_function.sh
|
|
|
|
msg_info "$(basename $0) => START"
|
|
|
|
|
|
|
|
while test $# -gt 0
|
|
|
|
do
|
|
|
|
case "$1" in
|
|
|
|
-h|--help)
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
-d|--debug)
|
|
|
|
set_debug 1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
msg_error "options '$1' not recognize"
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
####################################
|
|
|
|
# Load Environment
|
|
|
|
####################################
|
|
|
|
msg_debug "Load environment"
|
|
|
|
if [[ ! -f /opt/khanat_config.sh ]]
|
|
|
|
then
|
|
|
|
echo "ERROR - missing /opt/khanat_config.sh"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
source /opt/khanat_config.sh
|
|
|
|
|
|
|
|
msg_debug "Create database for account gameserver"
|
|
|
|
# Create database on gameserver account (and change directory database)
|
2018-04-05 20:34:26 +00:00
|
|
|
if [ $(get_debian_version) -lt 9 ]
|
|
|
|
then
|
2018-07-26 07:35:31 +00:00
|
|
|
msg_info "[$(basename $0):$LINENO] update mysql configuration /etc/mysql/my.cnf"
|
2018-04-05 20:34:26 +00:00
|
|
|
# old configuration mysql (on debian 8-)
|
|
|
|
update_mysql_config '/etc/mysql/my.cnf'
|
|
|
|
else
|
2018-07-26 07:35:31 +00:00
|
|
|
msg_info "[$(basename $0):$LINENO] update mysql configuration /etc/mysql/mariadb.conf.d/50-server.cnf"
|
2018-04-05 20:34:26 +00:00
|
|
|
# For mariadb (on debian 9)
|
|
|
|
update_mysql_config '/etc/mysql/mariadb.conf.d/50-server.cnf'
|
|
|
|
fi
|
2017-11-21 21:10:28 +00:00
|
|
|
|
2018-04-22 19:12:51 +00:00
|
|
|
mkdir -p /home/gameserver/database/ || exit 2
|
2017-11-21 21:10:28 +00:00
|
|
|
chown gameserver:$(id -g -n gameserver) /home/gameserver/database/ || exit 2
|
|
|
|
|
2018-04-22 19:12:51 +00:00
|
|
|
mkdir -p /home/gameserver/log/mysql || exit 2
|
2017-11-21 21:10:28 +00:00
|
|
|
chown -R gameserver:$(id -g -n gameserver) /home/gameserver/log || exit 2
|
|
|
|
|
2018-04-22 19:12:51 +00:00
|
|
|
mkdir -p /var/run/mysqld || exit 2
|
2017-11-21 21:10:28 +00:00
|
|
|
chown gameserver:$(id -g -n gameserver) /var/run/mysqld/ || exit 2
|
|
|
|
|
|
|
|
####################################
|
|
|
|
# End
|
|
|
|
####################################
|
|
|
|
msg_info "$(basename $0) => END"
|