From 6ecc912163b5ce192558141b4f59f1f31420c306 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sat, 5 Sep 2020 12:26:30 +0100 Subject: [PATCH] remove default --- lgsm/functions/command_dev_query_raw.sh | 154 ++++++++++++----------- lgsm/functions/command_monitor.sh | 157 ++++++++++++------------ 2 files changed, 156 insertions(+), 155 deletions(-) diff --git a/lgsm/functions/command_dev_query_raw.sh b/lgsm/functions/command_dev_query_raw.sh index a66dbba4a..6e1e4d5e5 100644 --- a/lgsm/functions/command_dev_query_raw.sh +++ b/lgsm/functions/command_dev_query_raw.sh @@ -13,89 +13,87 @@ check.sh info_config.sh info_parms.sh - - - echo -e "" - echo -e "Query Port - Raw Output" - echo -e "==================================================================" - echo -e "" - echo -e "QUERY IP" - for queryip in "${queryips[@]}" - do - echo -e "${queryip}" - done - echo -e "=================================" - echo -e "Ports" - echo -e "=================================" - echo -e "" - echo -e "PORT: ${port}" - echo -e "QUERY PORT: ${queryport}" - echo -e "" - echo -e "Gamedig Raw Output" - echo -e "=================================" +echo -e "" +echo -e "Query Port - Raw Output" +echo -e "==================================================================" +echo -e "" +echo -e "QUERY IP" +for queryip in "${queryips[@]}" +do + echo -e "${queryip}" +done +echo -e "=================================" +echo -e "Ports" +echo -e "=================================" +echo -e "" +echo -e "PORT: ${port}" +echo -e "QUERY PORT: ${queryport}" +echo -e "" +echo -e "Gamedig Raw Output" +echo -e "=================================" +echo -e "" +if [ ! "$(command -v gamedig 2>/dev/null)" ]; then + fn_print_failure_nl "gamedig not installed" +fi +if [ ! "$(command -v jq 2>/dev/null)" ]; then + fn_print_failure_nl "jq not installed" +fi +for queryip in "${queryips[@]}" +do + query_gamedig.sh + echo -e "${gamedigcmd}" + echo"" + echo "${gamedigraw}" | jq +done +echo -e "" +echo -e "gsquery Raw Output" +echo -e "=================================" +echo -e "" +for queryip in "${queryips[@]}" +do + echo -e "./query_gsquery.py -a \"${queryip}\" -p \"${queryport}\" -e \"${querytype}\"" echo -e "" - if [ ! "$(command -v gamedig 2>/dev/null)" ]; then - fn_print_failure_nl "gamedig not installed" + if [ ! -f "${functionsdir}/query_gsquery.py" ]; then + fn_fetch_file_github "lgsm/functions" "query_gsquery.py" "${functionsdir}" "chmodx" "norun" "noforce" "nomd5" fi - if [ ! "$(command -v jq 2>/dev/null)" ]; then - fn_print_failure_nl "jq not installed" - fi - for queryip in "${queryips[@]}" - do - query_gamedig.sh - echo -e "${gamedigcmd}" - echo"" - echo "${gamedigraw}" | jq - done - echo -e "" - echo -e "gsquery Raw Output" - echo -e "=================================" - echo -e "" - for queryip in "${queryips[@]}" - do - echo -e "./query_gsquery.py -a \"${queryip}\" -p \"${queryport}\" -e \"${querytype}\"" - echo -e "" - if [ ! -f "${functionsdir}/query_gsquery.py" ]; then - fn_fetch_file_github "lgsm/functions" "query_gsquery.py" "${functionsdir}" "chmodx" "norun" "noforce" "nomd5" - fi - "${functionsdir}"/query_gsquery.py -a "${queryip}" -p "${queryport}" -e "${querytype}" - done + "${functionsdir}"/query_gsquery.py -a "${queryip}" -p "${queryport}" -e "${querytype}" +done +echo -e "" +echo -e "TCP Raw Output" +echo -e "=================================" +echo -e "" +for queryip in "${queryips[@]}" +do + echo -e "bash -c 'exec 3<> /dev/tcp/'${queryip}'/'${queryport}''" echo -e "" - echo -e "TCP Raw Output" - echo -e "=================================" + timeout 3 bash -c 'exec 3<> /dev/tcp/'${queryip}'/'${queryport}'' + querystatus="$?" echo -e "" - for queryip in "${queryips[@]}" - do - echo -e "bash -c 'exec 3<> /dev/tcp/'${queryip}'/'${queryport}''" - echo -e "" - timeout 3 bash -c 'exec 3<> /dev/tcp/'${queryip}'/'${queryport}'' - querystatus="$?" - echo -e "" - if [ "${querystatus}" == "0" ]; then - echo -e "TCP query PASS" - else - echo -e "TCP query FAIL" - fi - done - echo -e "" - echo -e "Game Port - Raw Output" - echo -e "==================================================================" + if [ "${querystatus}" == "0" ]; then + echo -e "TCP query PASS" + else + echo -e "TCP query FAIL" + fi +done +echo -e "" +echo -e "Game Port - Raw Output" +echo -e "==================================================================" +echo -e "" +echo -e "TCP Raw Output" +echo -e "=================================" +echo -e "" +for queryip in "${queryips[@]}" +do + echo -e "bash -c 'exec 3<> /dev/tcp/'${queryip}'/'${port}''" echo -e "" - echo -e "TCP Raw Output" - echo -e "=================================" + timeout 3 bash -c 'exec 3<> /dev/tcp/'${queryip}'/'${port}'' + querystatus="$?" echo -e "" - for queryip in "${queryips[@]}" - do - echo -e "bash -c 'exec 3<> /dev/tcp/'${queryip}'/'${port}''" - echo -e "" - timeout 3 bash -c 'exec 3<> /dev/tcp/'${queryip}'/'${port}'' - querystatus="$?" - echo -e "" - if [ "${querystatus}" == "0" ]; then - echo -e "TCP query PASS" - else - echo -e "TCP query FAIL" - fi - done + if [ "${querystatus}" == "0" ]; then + echo -e "TCP query PASS" + else + echo -e "TCP query FAIL" + fi +done exitcode=0 core_exit.sh diff --git a/lgsm/functions/command_monitor.sh b/lgsm/functions/command_monitor.sh index 3f8b48334..ab8b91892 100644 --- a/lgsm/functions/command_monitor.sh +++ b/lgsm/functions/command_monitor.sh @@ -99,88 +99,91 @@ fn_monitor_query(){ # Query will wait up to 60 seconds to confirm server is down as server can become non-responsive during map changes. totalseconds=0 for queryattempt in {1..5}; do - fn_print_dots "Querying port: ${querymethod}: ${queryip}:${queryport} : ${totalseconds}/${queryattempt}: " - fn_print_querying_eol - fn_script_log_info "Querying port: ${querymethod}: ${queryip}:${queryport} : ${queryattempt} : QUERYING" - # querydelay - if [ "$(cat "${lockdir}/${selfname}.lock")" -gt "$(date "+%s" -d "${querydelay} mins ago")" ]; then - fn_print_ok "Querying port: ${querymethod}: ${queryip}:${queryport} : ${totalseconds}/${queryattempt}: " - fn_print_delay_eol_nl - fn_script_log_info "Querying port: ${querymethod}: ${queryip}:${queryport} : ${queryattempt} : DELAY" - fn_script_log_info "Query bypassed: ${gameservername} started less than ${querydelay} minutes ago" - fn_script_log_info "Server started: $(date -d @$(cat "${lockdir}/${selfname}.lock"))" - fn_script_log_info "Current time: $(date)" - monitorpass=1 - core_exit.sh - # will use query method selected in fn_monitor_loop - # gamedig - elif [ "${querymethod}" == "gamedig" ]; then - query_gamedig.sh - # gsquery - elif [ "${querymethod}" == "gsquery" ]; then - fn_query_gsquery - #tcp query - elif [ "${querymethod}" == "tcp" ]; then - fn_query_tcp - fi + for queryip in "${queryips[@]}" + do + fn_print_dots "Querying port: ${querymethod}: ${queryip}:${queryport} : ${totalseconds}/${queryattempt}: " + fn_print_querying_eol + fn_script_log_info "Querying port: ${querymethod}: ${queryip}:${queryport} : ${queryattempt} : QUERYING" + # querydelay + if [ "$(cat "${lockdir}/${selfname}.lock")" -gt "$(date "+%s" -d "${querydelay} mins ago")" ]; then + fn_print_ok "Querying port: ${querymethod}: ${queryip}:${queryport} : ${totalseconds}/${queryattempt}: " + fn_print_delay_eol_nl + fn_script_log_info "Querying port: ${querymethod}: ${queryip}:${queryport} : ${queryattempt} : DELAY" + fn_script_log_info "Query bypassed: ${gameservername} started less than ${querydelay} minutes ago" + fn_script_log_info "Server started: $(date -d @$(cat "${lockdir}/${selfname}.lock"))" + fn_script_log_info "Current time: $(date)" + monitorpass=1 + core_exit.sh + # will use query method selected in fn_monitor_loop + # gamedig + elif [ "${querymethod}" == "gamedig" ]; then + query_gamedig.sh + # gsquery + elif [ "${querymethod}" == "gsquery" ]; then + fn_query_gsquery + #tcp query + elif [ "${querymethod}" == "tcp" ]; then + fn_query_tcp + fi - if [ "${querystatus}" == "0" ]; then - # Server query OK. - fn_print_ok "Querying port: ${querymethod}: ${queryip}:${queryport} : ${totalseconds}/${queryattempt}: " - fn_print_ok_eol_nl - fn_script_log_pass "Querying port: ${querymethod}: ${queryip}:${queryport} : ${queryattempt}: OK" - monitorpass=1 if [ "${querystatus}" == "0" ]; then - # Add query data to log. - if [ "${gdname}" ]; then - fn_script_log_info "Server name: ${gdname}" - fi - if [ "${gdplayers}" ]; then - fn_script_log_info "Players: ${gdplayers}/${gdmaxplayers}" - fi - if [ "${gdbots}" ]; then - fn_script_log_info "Bots: ${gdbots}" - fi - if [ "${gdmap}" ]; then - fn_script_log_info "Map: ${gdmap}" - fi - if [ "${gdgamemode}" ]; then - fn_script_log_info "Game Mode: ${gdgamemode}" - fi + # Server query OK. + fn_print_ok "Querying port: ${querymethod}: ${queryip}:${queryport} : ${totalseconds}/${queryattempt}: " + fn_print_ok_eol_nl + fn_script_log_pass "Querying port: ${querymethod}: ${queryip}:${queryport} : ${queryattempt}: OK" + monitorpass=1 + if [ "${querystatus}" == "0" ]; then + # Add query data to log. + if [ "${gdname}" ]; then + fn_script_log_info "Server name: ${gdname}" + fi + if [ "${gdplayers}" ]; then + fn_script_log_info "Players: ${gdplayers}/${gdmaxplayers}" + fi + if [ "${gdbots}" ]; then + fn_script_log_info "Bots: ${gdbots}" + fi + if [ "${gdmap}" ]; then + fn_script_log_info "Map: ${gdmap}" + fi + if [ "${gdgamemode}" ]; then + fn_script_log_info "Game Mode: ${gdgamemode}" + fi - # send LinuxGSM stats if monitor is OK. - if [ "${stats}" == "on" ]||[ "${stats}" == "y" ]; then - info_stats.sh - fi - fi - core_exit.sh - else - # Server query FAIL. - fn_print_fail "Querying port: ${querymethod}: ${queryip}:${queryport} : ${totalseconds}/${queryattempt}: " - fn_print_fail_eol - fn_script_log_warn "Querying port: ${querymethod}: ${queryip}:${queryport} : ${queryattempt}: FAIL" - # Monitor will try gamedig (if supported) for first 30s then gsquery before restarting. - if [ "${querymethod}" == "gsquery" ]||[ "${querymethod}" == "tcp" ]; then - # gsquery will fail if longer than 60s - if [ "${totalseconds}" -ge "59" ]; then - # Monitor will FAIL if over 60s and trigger gane server reboot. - fn_print_fail "Querying port: ${querymethod}: ${queryip}:${queryport} : ${totalseconds}/${queryattempt}: " - fn_print_fail_eol_nl - fn_script_log_warn "Querying port: ${querymethod}: ${queryip}:${queryport} : ${queryattempt}: FAIL" - # Send alert if enabled. - alert="restartquery" - alert.sh - command_restart.sh - fn_firstcommand_reset - core_exit.sh + # send LinuxGSM stats if monitor is OK. + if [ "${stats}" == "on" ]||[ "${stats}" == "y" ]; then + info_stats.sh + fi fi - elif [ "${querymethod}" == "gamedig" ]; then - # gamedig will fail and try gsquery if longer than 30s - if [ "${totalseconds}" -ge "29" ]; then - break + core_exit.sh + else + # Server query FAIL. + fn_print_fail "Querying port: ${querymethod}: ${queryip}:${queryport} : ${totalseconds}/${queryattempt}: " + fn_print_fail_eol + fn_script_log_warn "Querying port: ${querymethod}: ${queryip}:${queryport} : ${queryattempt}: FAIL" + # Monitor will try gamedig (if supported) for first 30s then gsquery before restarting. + if [ "${querymethod}" == "gsquery" ]||[ "${querymethod}" == "tcp" ]; then + # gsquery will fail if longer than 60s + if [ "${totalseconds}" -ge "59" ]; then + # Monitor will FAIL if over 60s and trigger gane server reboot. + fn_print_fail "Querying port: ${querymethod}: ${queryip}:${queryport} : ${totalseconds}/${queryattempt}: " + fn_print_fail_eol_nl + fn_script_log_warn "Querying port: ${querymethod}: ${queryip}:${queryport} : ${queryattempt}: FAIL" + # Send alert if enabled. + alert="restartquery" + alert.sh + command_restart.sh + fn_firstcommand_reset + core_exit.sh + fi + elif [ "${querymethod}" == "gamedig" ]; then + # gamedig will fail and try gsquery if longer than 30s + if [ "${totalseconds}" -ge "29" ]; then + break + fi fi fi - + done # Second counter will wait for 15s before breaking loop. for seconds in {1..15}; do fn_print_fail "Querying port: ${querymethod}: ${queryip}:${queryport} : ${totalseconds}/${queryattempt}: ${cyan}WAIT${default}" @@ -190,7 +193,7 @@ for queryattempt in {1..5}; do break fi done - fi + done }