mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-29 23:25:59 +00:00
90 lines
3.2 KiB
Bash
Executable file
90 lines
3.2 KiB
Bash
Executable file
#!/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 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 General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://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
|
|
}
|
|
|
|
#####################
|
|
# 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 recoginze"
|
|
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)
|
|
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
|
|
|
|
mkdir -p /home/gameserver/database/ || exit 2
|
|
chown gameserver:$(id -g -n gameserver) /home/gameserver/database/ || exit 2
|
|
|
|
mkdir -p /home/gameserver/log/mysql || exit 2
|
|
chown -R gameserver:$(id -g -n gameserver) /home/gameserver/log || exit 2
|
|
|
|
chown gameserver:$(id -g -n gameserver) /var/run/mysqld/ || exit 2
|
|
|
|
####################################
|
|
# End
|
|
####################################
|
|
msg_info "$(basename $0) => END"
|