#!/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 . declare -i METHOD_START=2 usage() { cat << EOF usage:$0 [options] Prepare and launch server khanat options: -h, --help : Show this help -d, --debug : Show debug message --screen : start khanat with screen --opennel-manager : (default) start khanat with OpenNel-Manager --bash : launch bash (doesn't start khanat) EOF } 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 } function create_default_file_for_opennel_manager() { create_dir_gameserver '/home/gameserver/log/khanat' || exit 2 create_dir_gameserver '/home/gameserver/khanat/server/gpms' || 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 ;; --screen) METHOD_START=0 shift ;; --bash) METHOD_START=1 shift ;; --opennel-manager) METHOD_START=2 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 [ -f /home/gameserver/opennelmanager.flag ] then rm /home/gameserver/opennelmanager.flag || exit 2 fi if [[ $METHOD_START -eq 0 ]] then 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 msg_debug "launch bash" bash elif [[ $METHOD_START -eq 2 ]] then msg_debug "start with OpenNelManager" touch /home/gameserver/opennelmanager.flag # Disable Color grep -e '^StdDisplayerColor' /home/gameserver/khanat/server/common.cfg >/dev/null if [[ $? -eq 0 ]] then sed -i 's/StdDisplayerColor.*/StdDisplayerColor = 0;/g' /home/gameserver/khanat/server/common.cfg else echo -en "\n// ---- Disable color\nStdDisplayerColor = 0;\n" >> /home/gameserver/khanat/server/common.cfg fi # Start OpenNelManager create_default_file_for_opennel_manager 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 (METHOD_START:$METHOD_START)' exit 2 fi ###################### # ######################