khanat-code-old/dist/docker/server/debian/common/servercontainer_launch_auto.sh
2017-10-09 22:11:54 +02:00

267 lines
6.6 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 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 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'
}
#####################
# 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 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
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:]]/}
sed -i -r 's/(FSListenHost)(.*)(=)(.*)(;)/FSListenHost = "'"$addressip"'";/g' $KHANAT_PATH/server/frontend_service.cfg || exit 2
#####################
# Reconfigure database
#####################
msg_debug "Reconfigure database"
## Configure Domain
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
mysql -u root -e "use nel;
UPDATE nel.shard
SET WsAddr = '$addressip:'
WHERE ShardId = 302;" || exit 2
# Configure nel_tool.neltool_domains
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; echo ".$RYZOM_PATH."; $KHANAT_HOME/khanat/tools/scripts/linux/shard start
elif [[ $METHOD_START -eq 1 ]]
then
su -c /opt/ext/servercontainer_launch_service.sh gameserver
sleep 10
tail -n+0 -f /home/gameserver/log/khanat/log.log
elif [[ $METHOD_START -eq 2 ]]
then
su -c /opt/ext/servercontainer_launch_service.sh gameserver
sleep 10
watch cat /home/gameserver/khanat/server/aes_nagios_report.txt
elif [[ $METHOD_START -eq 3 ]]
then
su -c /opt/ext/servercontainer_launch_service.sh gameserver
sleep 10
tail -n+0 -f /home/gameserver/log/apache2/* /home/gameserver/log/mysql/* /home/gameserver/log/khanat/*
elif [[ $METHOD_START -eq 4 ]]
then
su -c /opt/ext/servercontainer_launch_service.sh gameserver
sleep 10
watch /opt/ext/servercontainer_launch_status.sh --no-color
elif [[ $METHOD_START -eq 5 ]]
then
#su -c /opt/ext/servercontainer_launch_service.sh gameserver
#sleep 10
bash
else
msg_error 'Bad option'
exit 2
fi
######################
#
######################