khanat-server-docker-NeL/server/debian/common/servercontainer_launch_auto.sh

341 lines
11 KiB
Bash
Raw Normal View History

#!/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 screen 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' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/rws' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/save_shard/characters_offline_commands' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/save_shard/characters' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/save_shard/characters/002' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/save_shard/ai_script_data' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/save_shard/sale_store' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/save_shard/www' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/save_shard/www/302' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/save_shard/www/302/ke' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/save_shard/www/302/ke/kem' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/save_shard/totems' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/save_shard/logs' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/save_shard/sdb' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/pds' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/pds/00000000' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/pds/00000000/logs' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/gpms' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/aes' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/lgs' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/data_shard/primitive_cache' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/su' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/ms' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/egs' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/data_shard_local' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/data_shard_local/statistics' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/fes' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/mfs' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/ras' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/ios' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/sbs' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/ais_newbyland' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/rns' || exit 2
create_dir_gameserver '/home/gameserver/khanat/server/ts' || exit 2
}
#####################
# 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
;;
2018-08-05 11:36:12 +00:00
--start-with-manager)
METHOD_START=6
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
#####################
# Update configuration
#####################
msg_debug "Update configuration with new path"
newpath="$KHANAT_PATH/server/common/"
newpath=${newpath//\//\\\/}
for filecfg in $KHANAT_PATH/server/*.cfg
do
msg_debug "[$(basename $0):$LINENO] update $filecfg"
#sudo sed -i -r "s/..\/common\//$newpath/g" $filecfg
#sudo sed -i -r "s/..\/common\//common\//g" $filecfg
done
#####################
# 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"
2018-08-05 11:36:12 +00:00
rm /home/gameserver/opennelmanager.flag || echo ""
if [[ $METHOD_START -eq 0 ]]
then
2018-08-05 11:36:12 +00:00
msg_debug "start with screen"
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
2018-08-05 11:36:12 +00:00
msg_debug "start with show-khanat-log"
/opt/ext/servercontainer_launch_service.sh
sleep 10
tail -n+0 -f /home/gameserver/log/khanat/log.log
elif [[ $METHOD_START -eq 2 ]]
then
2018-08-05 11:36:12 +00:00
msg_debug "start with show-status-nagios"
/opt/ext/servercontainer_launch_service.sh
sleep 10
watch cat /home/gameserver/khanat/server/aes_nagios_report.txt
elif [[ $METHOD_START -eq 3 ]]
then
2018-08-05 11:36:12 +00:00
msg_debug "start with show-all-log"
/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
2018-08-05 11:36:12 +00:00
msg_debug "start with "
/opt/ext/servercontainer_launch_service.sh
sleep 10
watch /opt/ext/servercontainer_launch_status.sh --no-color
elif [[ $METHOD_START -eq 5 ]]
then
2018-08-05 11:36:12 +00:00
msg_debug "start with show-status"
/opt/ext/servercontainer_launch_service.sh
#sleep 10
bash
2018-08-05 11:36:12 +00:00
elif [[ $METHOD_START -eq 6 ]]
then
msg_debug "start with OpenNelManager"
touch /home/gameserver/opennelmanager.flag
python3 -m pymanager.manager -c /home/gameserver/khanat/khaganat.cfg --log DEBUG --filelog /home/gameserver/log/khanat/OpenNelManager.log --launch-program &
#sleep 10
#screen -t terminal /bin/bash -l
/bin/bash -l
else
msg_error 'Bad option'
exit 2
fi
######################
#
######################