khanat-server-docker-NeL/server/debian/common/servercontainer_launch_auto.sh
2017-11-22 21:24:24 +01:00

309 lines
9.2 KiB
Bash
Executable file

#!/bin/bash
#
# Prepare and launch server khanat
# 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 and launch server khanat
options:
-h, --help : Show this help
-d, --debug : Show debug message
--start-khanat-with-screen : start with screen
--show-khanat-log : Show khanat log (after start)
--show-all-log : Show all log (after start) [apache, mysql, khanat]
--show-status-nagios : show status (ater start)
--show-status : show status (ater start)
--bash-after-start : command bash after start
EOF
}
status_program()
{
pid=$(cat /home/gameserver/khanat/server/$1/$1.pid)
ps -p $pid >/dev/null
if [[ $? -eq 0 ]]
then
pidstate="ok"
else
pidstate="ko"
fi
state=$(cat /home/gameserver/khanat/server/$1/$1.state)
echo "$1 $2 [$state] pid:$pid => $pidstate"
}
status_all()
{
# aes : admin_executor_service.log
status_program 'aes' 'ryzom_admin_service'
# bms_master : backup_service.log
status_program 'bms_master' 'ryzom_backup_service'
# bms_pd_master
# status_program 'bms_pd_master' 'ryzom_backup_service'
# egs : entities_game_service.log
status_program 'egs' 'ryzom_entities_game_service'
# gpms : gpm_service.log
status_program 'gpms' 'ryzom_gpm_service'
# ios : input_output_service.log
status_program 'ios' 'ryzom_ios_service'
# rns : naming_service.log
status_program 'rns' 'ryzom_naming_service'
# rws : welcome_service.log
status_program 'rws' 'ryzom_welcome_service'
# ts : tick_service.log
status_program 'ts' 'ryzom_tick_service'
# ms : mirror_service.log
status_program 'ms' 'ryzom_mirror_service'
# ais_newbyland : ai_service.log
status_program 'ais_newbyland' 'ryzom_ai_service'
# mfs : mail_forum_service.log
status_program 'mfs' 'ryzom_mail_forum_service'
# su : shard_unifier_service.log
status_program 'su' 'ryzom_shard_unifier_service'
# fes : frontend_service.log
status_program 'fes' 'ryzom_frontend_service'
# sbs : session_browser_server.log
status_program 'sbs' 'ryzom_session_browser_service'
# lgs : logger_service.log
status_program 'lgs' 'ryzom_logger_service'
# mos
# status_program 'mos' 'ryzom_monitor_service'
# pdss
#status_program 'pdss' 'ryzom_pd_support_service'
# ras : admin_service.log
status_program 'ras' 'ryzom_admin_service'
}
function create_default_file_for_screen()
{
# on scrren mode, we launch with root right
# But file are created on root, so , to solve that, we generate directory and file before
create_dir_gameserver '/home/gameserver/khanat/server/bms_master'
create_dir_gameserver '/home/gameserver/khanat/server/rws'
create_dir_gameserver '/home/gameserver/khanat/server/save_shard/characters_offline_commands'
create_dir_gameserver '/home/gameserver/khanat/server/save_shard/characters'
create_dir_gameserver '/home/gameserver/khanat/server/save_shard/characters/002'
create_dir_gameserver '/home/gameserver/khanat/server/save_shard/ai_script_data'
create_dir_gameserver '/home/gameserver/khanat/server/save_shard/sale_store'
create_dir_gameserver '/home/gameserver/khanat/server/save_shard/www'
create_dir_gameserver '/home/gameserver/khanat/server/save_shard/www/302'
create_dir_gameserver '/home/gameserver/khanat/server/save_shard/www/302/ke'
create_dir_gameserver '/home/gameserver/khanat/server/save_shard/www/302/ke/kem'
create_dir_gameserver '/home/gameserver/khanat/server/save_shard/totems'
create_dir_gameserver '/home/gameserver/khanat/server/save_shard/logs'
create_dir_gameserver '/home/gameserver/khanat/server/save_shard/sdb'
create_dir_gameserver '/home/gameserver/khanat/server/pds'
create_dir_gameserver '/home/gameserver/khanat/server/pds/00000000'
create_dir_gameserver '/home/gameserver/khanat/server/pds/00000000/logs'
create_dir_gameserver '/home/gameserver/khanat/server/gpms'
create_dir_gameserver '/home/gameserver/khanat/server/aes'
create_dir_gameserver '/home/gameserver/khanat/server/lgs'
create_dir_gameserver '/home/gameserver/khanat/server/data_shard/primitive_cache'
create_dir_gameserver '/home/gameserver/khanat/server/su'
create_dir_gameserver '/home/gameserver/khanat/server/ms'
create_dir_gameserver '/home/gameserver/khanat/server/egs'
create_dir_gameserver '/home/gameserver/khanat/server/data_shard_local'
create_dir_gameserver '/home/gameserver/khanat/server/data_shard_local/statistics'
create_dir_gameserver '/home/gameserver/khanat/server/fes'
create_dir_gameserver '/home/gameserver/khanat/server/mfs'
create_dir_gameserver '/home/gameserver/khanat/server/ras'
create_dir_gameserver '/home/gameserver/khanat/server/ios'
create_dir_gameserver '/home/gameserver/khanat/server/sbs'
create_dir_gameserver '/home/gameserver/khanat/server/ais_newbyland'
create_dir_gameserver '/home/gameserver/khanat/server/rns'
create_dir_gameserver '/home/gameserver/khanat/server/ts'
}
#####################
# MAIN
#####################
source /opt/ext/servercontainer_function.sh
msg_info "START : $(basename $0)"
while test $# -gt 0
do
case "$1" in
-h|--help)
usage
exit 1
;;
-d|--debug)
set_debug 1
shift
;;
--start-khanat-with-screen)
METHOD_START=0
shift
;;
--show-khanat-log)
METHOD_START=1
shift
;;
--show-all-log)
METHOD_START=3
shift
;;
--show-status-nagios)
METHOD_START=2
shift
;;
--show-status)
METHOD_START=4
shift
;;
--bash-after-start)
METHOD_START=5
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
if [[ ! -f /home/gameserver/.bashrc ]]
then
echo "ERROR - missing /home/gameserver/.bashrc"
exit 2
fi
source /home/gameserver/.bashrc
#####################
# Start mysql, apache & ssh
#####################
msg_debug "Start mysql, apache & ssh"
sudo /etc/init.d/mysql restart
sudo /etc/init.d/apache2 restart
sudo /etc/init.d/ssh restart
#####################
# Update configuration with new IP
#####################
msg_debug "Update configuration with new IP"
tmp=$(hostname -I)
export addressip=${tmp//[[:blank:]]/}
sudo sed -i -r 's/(FSListenHost)(.*)(=)(.*)(;)/FSListenHost = "'"$addressip"'";/g' $KHANAT_PATH/server/frontend_service.cfg || exit 2
#####################
# Reconfigure database
#####################
msg_debug "Reconfigure database : Configure Domain"
## Configure Domain
sudo mysql -u root -e "use nel;
UPDATE nel.domain
SET backup_patch_url = '$addressip:23001'
, patch_urls = '$addressip/patch'
, login_address = '$addressip:49998'
, session_manager_address = '$addressip:49999'
, web_host = '$addressip:30000'
, web_host_php = '$addressip:40916'
WHERE domain_id = 12;" || exit 2
# Configure nel.shard
msg_debug "Reconfigure database : Configure nel.shard"
sudo mysql -u root -e "use nel;
UPDATE nel.shard
SET WsAddr = '$addressip:'
WHERE ShardId = 302;" || exit 2
# Configure nel_tool.neltool_domains
msg_debug "Reconfigure database : Configure nel_tool.neltool_domains"
sudo mysql -u root -e "use nel;
UPDATE nel_tool.neltool_domains
SET domain_as_host = '$addressip'
WHERE domain_id = 12;" || exit 2
#####################
# Start khanat
#####################
msg_debug "Start khanat"
if [[ $METHOD_START -eq 0 ]]
then
source /home/gameserver/.bashrc; export RYZOM_PATH=$KHANAT_PATH; cd "$RYZOM_PATH"; $KHANAT_HOME/khanat/tools/scripts/linux/shard start
elif [[ $METHOD_START -eq 1 ]]
then
/opt/ext/servercontainer_launch_service.sh
sleep 10
tail -n+0 -f /home/gameserver/log/khanat/log.log
elif [[ $METHOD_START -eq 2 ]]
then
/opt/ext/servercontainer_launch_service.sh
sleep 10
watch cat /home/gameserver/khanat/server/aes_nagios_report.txt
elif [[ $METHOD_START -eq 3 ]]
then
/opt/ext/servercontainer_launch_service.sh
sleep 10
tail -n+0 -f /home/gameserver/log/apache2/* /home/gameserver/log/mysql/* /home/gameserver/log/khanat/*
elif [[ $METHOD_START -eq 4 ]]
then
/opt/ext/servercontainer_launch_service.sh
sleep 10
watch /opt/ext/servercontainer_launch_status.sh --no-color
elif [[ $METHOD_START -eq 5 ]]
then
/opt/ext/servercontainer_launch_service.sh
#sleep 10
bash
else
msg_error 'Bad option'
exit 2
fi
######################
#
######################