timed_task.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!bin/bash
  2. echo "start"
  3. serverPath=/server
  4. task_log_path=${serverPath}/timed_task.log
  5. #zone_id=$(awk '{print $1}' ${serverPath}/config.txt)
  6. zone_id=$(awk 'NR==1{split($0,a,"=");print a[2]}' ${serverPath}/config.txt)
  7. echo $zone_id
  8. cur_time=$(date "+%Y-%m-%d %H:%M:%S")
  9. echo "当前执行开服:${zone_id}区开始时间为:${cur_time}" >> $task_log_path
  10. #1:execute install
  11. sh ${serverPath}/srv_install.sh $zone_id
  12. cur_time=$(date "+%Y-%m-%d %H:%M:%S")
  13. echo "${cur_time}=>srv_install.sh ${zone_id}" >> $task_log_path
  14. #4:update
  15. db_user="root"
  16. db_password="wch123.com"
  17. db_name="sdk"
  18. table_name="game_server"
  19. index1=Tap
  20. index2=区
  21. server_name="$index1$zone_id$index2"
  22. server_name2="寻道$((zone_id - 180))区"
  23. #mapserver() {
  24. # server_name=$index1$zone_id$index2
  25. # echo $server_name
  26. #}
  27. echo $server_name
  28. mongodb_name=$((350001 + zone_id))
  29. port=$((8191 + zone_id))
  30. wss="wss://game-gfyx.muzigame.com/bin/${port}"
  31. update_sql="insert into game_server(id,name,status,ip,port,tag,tips,white_list,open_time,db_name, megre_server,wss,sid)values(${zone_id},'${server_name}', 1,'118.145.139.78',${port},1,'','',0,'ckwy_fy_S${mongodb_name=$}',0,'',${zone_id});"
  32. if [ $zone_id -ge 180 ]; then
  33. update_sql="${update_sql}insert into game_server(id,name,status,ip,port,tag,tips,white_list,open_time,db_name, megre_server,wss,sid) values($((2000 + zone_id)),'${server_name2}', 1,'118.145.139.78',${port},14,'','',0,'ckwy_fy_S${mongodb_name=$}',0,'${wss}',$((zone_id - 180)));"
  34. fi
  35. mysql -u $db_user -p$db_password $db_name -e "$update_sql"
  36. cur_time=$(date "+%Y-%m-%d %H:%M:%S")
  37. echo "${cur_time}=>update sql:${update_sql}" >> $task_log_path
  38. #5:add 1
  39. ((zone_id++))
  40. cur_time=$(date "+%Y-%m-%d %H:%M:%S")
  41. echo "${cur_time}=>zone_id++ ${zone_id}" >> $task_log_path
  42. #6:save id
  43. sed -i "1c\zone_start_id=${zone_id}" ${serverPath}/config.txt
  44. sed -i "2c\port=${port}" ${serverPath}/config.txt
  45. cur_time=$(date "+%Y-%m-%d %H:%M:%S")
  46. echo "${cur_time}=>zone_id++ ${zone_id}" >> $task_log_path
  47. cur_time=$(date "+%Y-%m-%d %H:%M:%S")
  48. echo "当前执行开服:${zone_id}区结束时间为:${cur_time}" >> $task_log_path
  49. echo $zone_id