Browse Source

Getting server status is now consistent

Both tmux and ts3 status gathering are the same/ Now call a file called
check_status.sh this returns the server status as 0 or 1
pull/820/merge
Daniel Gibbs 9 years ago
parent
commit
3bbfb0dbe5
  1. 10
      lgsm/functions/check.sh
  2. 22
      lgsm/functions/check_status.sh
  3. 6
      lgsm/functions/command_backup.sh
  4. 6
      lgsm/functions/command_console.sh
  5. 96
      lgsm/functions/command_details.sh
  6. 17
      lgsm/functions/command_monitor.sh
  7. 67
      lgsm/functions/command_start.sh
  8. 5
      lgsm/functions/command_validate.sh
  9. 7
      lgsm/functions/core_functions.sh
  10. 19
      lgsm/functions/update_check.sh

10
lgsm/functions/check.sh

@ -2,7 +2,7 @@
# LGSM fn_check function
# Author: Daniel Gibbs
# Website: http://gameservermanagers.com
lgsm_version="060316"
lgsm_version="060516"
# Description: Overall function for managing checks.
# Runs checks that will either halt on or fix an issue.
@ -70,3 +70,11 @@ do
check_config.sh
fi
done
local allowed_commands_array=( command_details.sh command_monitor.sh command_start.sh command_stop.sh command_ts3_server_pass.sh update_check.sh command_details.sh command_validate.sh )
for allowed_command in "${allowed_commands_array[@]}"
do
if [ "${allowed_command}" == "${function_selfname}" ]; then
check_status.sh
fi
done

22
lgsm/functions/check_status.sh

@ -0,0 +1,22 @@
#!/bin/bash
# LGSM check_status function
# Author: Daniel Gibbs
# Website: http://gameservermanagers.com
lgsm_version="060516"
# Description: Checks the proccess status of the server. Either online or offline.
if [ "${gamename}" == "Teamspeak 3" ]; then
# 1: Server is running
# 0: Server seems to have died
# 0: No server running (ts3server.pid is missing)
status=$(./ts3server_startscript.sh status servercfgfullpathfile=${servercfgfullpath})
if [ "${status}" == "Server is running" ]; then
status=1
else
status=0
ts3error=$(./ts3server_startscript.sh status servercfgfullpathfile=${servercfgfullpath})
fi
else
status=$(tmux list-sessions 2>&1 | awk '{print $1}' | grep -Ec "^${servicename}:")
fi

6
lgsm/functions/command_backup.sh

@ -2,7 +2,7 @@
# LGSM command_backup.sh function
# Author: Daniel Gibbs
# Website: http://gameservermanagers.com
lgsm_version="190316"
lgsm_version="060516"
# Description: Creates a .tar.gz file in the backup directory.
@ -24,8 +24,8 @@ while true; do
esac
done
echo ""
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:")
if [ "${tmuxwc}" -eq 1 ]; then
check_status.sh
if [ "${status}" != "0" ]; then
echo ""
fn_printwarningnl "${servicename} is currently running."
sleep 1

6
lgsm/functions/command_console.sh

@ -2,7 +2,7 @@
# LGSM command_console.sh function
# Author: Daniel Gibbs
# Website: http://gameservermanagers.com
lgsm_version="271215"
lgsm_version="060516"
# Description: Gives access to the server tmux console.
@ -27,8 +27,8 @@ esac
done
fn_print_dots "Starting"
sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:")
if [ "${tmuxwc}" -eq 1 ]; then
check_status.sh
if [ "${status}" != "0" ]; then
fn_print_ok_nl "Starting"
fn_scriptlog "accessed"
sleep 1

96
lgsm/functions/command_details.sh

@ -2,7 +2,7 @@
# LGSM command_details.sh function
# Author: Daniel Gibbs
# Website: http://gameservermanagers.com
lgsm_version="230216"
lgsm_version="060516"
# Description: Displays server infomation.
@ -12,6 +12,16 @@ function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
# This applies to all engines
fn_details_os(){
#
# Distro Details
# =====================================
# Distro: Ubuntu 14.04.4 LTS
# Arch: x86_64
# Kernel: 3.13.0-79-generic
# Hostname: hostname
# tmux: tmux 1.8
# GLIBC: 2.19
echo -e ""
echo -e "\e[93mDistro Details\e[0m"
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
@ -26,6 +36,16 @@ printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
}
fn_details_performance(){
#
# Performance
# =====================================
# Uptime: 55d, 3h, 38m
# Avg Load: 1.00, 1.01, 0.78
#
# Mem: total used free
# Physical: 741M 656M 85M
# Swap: 0B 0B 0B
echo -e ""
echo -e "\e[93mPerformance\e[0m"
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
@ -42,6 +62,15 @@ echo -e ""
}
fn_details_disk(){
#
# Storage
# =====================================
# Filesystem: /dev/disk/by-uuid/320c8edd-a2ce-4a23-8c9d-e00a7af2d6ff
# Total: 15G
# Used: 8.4G
# Available: 5.7G
# Serverfiles: 961M
echo -e ""
echo -e "\e[93mStorage\e[0m"
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
@ -58,74 +87,77 @@ printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
}
fn_details_gameserver(){
echo -e ""
#
# Quake Live Server Details
# =====================================
# Server name: ql-server
# Server IP: 1.2.3.4:27960
# RCON password: CHANGE_ME
# Server password: NOT SET
# Slots: 16
# Status: OFFLINE
## server details
echo -e ""
echo -e "\e[92m${gamename} Server Details\e[0m"
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
{
# server name
# Server name
echo -e "\e[34mServer name:\t\e[0m${servername}"
# server ip
# Server ip
echo -e "\e[34mServer IP:\t\e[0m${ip}:${port}"
# rcon password
if [ -n "${rconpassword}" ]; then
echo -e "\e[34mRCON password:\t\e[0m${rconpassword}"
fi
# server password
# Server password
if [ -n "${serverpassword}" ]; then
echo -e "\e[34mServer password:\t\e[0m${serverpassword}"
fi
# admin password
# RCON password
if [ -n "${rconpassword}" ]; then
echo -e "\e[34mRCON password:\t\e[0m${rconpassword}"
fi
# Admin password
if [ -n "${adminpassword}" ]; then
echo -e "\e[34mAdmin password:\t\e[0m${adminpassword}"
fi
# slots
# Stats password (Quake Live)
if [ -n "${statspassword}" ]; then
echo -e "\e[34mStats password:\t\e[0m${statspassword}"
fi
# Slots
if [ -n "${slots}" ]; then
echo -e "\e[34mSlots:\t\e[0m${slots}"
fi
# game mode
# Game mode
if [ -n "${gamemode}" ]; then
echo -e "\e[34mGame mode:\t\e[0m${gamemode}"
fi
# game world
# Game world
if [ -n "${gameworld}" ]; then
echo -e "\e[34mGame world:\t\e[0m${gameworld}"
fi
# tick rate
# Tick rate
if [ -n "${tickrate}" ]; then
echo -e "\e[34mTick rate:\t\e[0m${tickrate}"
fi
# online status
if [ "${gamename}" == "Teamspeak 3" ]; then
info_ts3status.sh
if [ "${ts3status}" = "Server seems to have died" ]||[ "${ts3status}" = "No server running (ts3server.pid is missing)" ]; then
echo -e "\e[34mStatus:\t\e[0;31mOFFLINE\e[0m"
else
echo -e "\e[34mStatus:\t\e[0;32mONLINE\e[0m"
# teamspeak dbplugin
if [ -n "${dbplugin}" ]; then
echo -e "\e[34mdbplugin:\t\e[0m${dbplugin}"
fi
else
pid=$(tmux list-sessions 2>&1 | awk '{print $1}' | grep -Ec "^${servicename}:")
if [ "${pid}" == "0" ]; then
# online status
if [ "${status}" == "0" ]; then
echo -e "\e[34mStatus:\t\e[0;31mOFFLINE\e[0m"
else
echo -e "\e[34mStatus:\t\e[0;32mONLINE\e[0m"
fi
fi
# teamspeak dbplugin
if [ -n "${dbplugin}" ]; then
echo -e "\e[34mdbplugin:\t\e[0m${dbplugin}"
fi
} | column -s $'\t' -t
echo -e ""

17
lgsm/functions/command_monitor.sh

@ -2,7 +2,7 @@
# LGSM command_monitor.sh function
# Author: Daniel Gibbs
# Website: http://gameservermanagers.com
lgsm_version="271215"
lgsm_version="060516"
# Description: Monitors server by checking for running proccesses
# then passes to monitor_gsquery.sh.
@ -22,8 +22,7 @@ fn_monitor_check_lockfile(){
fn_monitor_check_update(){
# Monitor will not check if update is running.
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)
if [ "${updatecheck}" >= "1" ]; then
if [ "$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)" >= "1" ]; then
fn_print_info_nl "SteamCMD is currently checking for updates"
fn_scriptlog "SteamCMD is currently checking for updates"
sleep 1
@ -49,17 +48,16 @@ fn_monitor_email_notification(){
}
fn_monitor_teamspeak3(){
info_ts3status.sh
if [ "${ts3status}" = "Server is running" ]; then
if [ "${status}" != "0" ]; then
fn_print_ok "Checking session: "
fn_print_ok_eol_nl
fn_scriptlog "Checking session: OK"
exit
else
fn_print_fail "Checking session: ${ts3status}: "
fn_print_fail "Checking session: ${ts3error}: "
fn_print_fail_eol_nl
fn_scriptlog "Checking session: ${ts3status}: FAIL"
failurereason="${ts3status}"
fn_scriptlog "Checking session: ${ts3error}: FAIL"
failurereason="${ts3error}"
fn_monitor_email_notification
fi
fn_scriptlog "Monitor is starting ${servername}"
@ -69,8 +67,7 @@ fn_monitor_teamspeak3(){
fn_monitor_tmux(){
# checks that tmux session is running
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:")
if [ "${tmuxwc}" == "1" ]; then
if [ "${status}" != "0" ]; then
fn_print_ok "Checking session: OK"
fn_print_ok_eol_nl
fn_scriptlog "Checking session: OK"

67
lgsm/functions/command_start.sh

@ -2,7 +2,7 @@
# LGSM command_start.sh function
# Author: Daniel Gibbs
# Website: http://gameservermanagers.com
lgsm_version="070116"
lgsm_version="060516"
# Description: Starts the server.
@ -10,16 +10,6 @@ local modulename="Starting"
function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
fn_start_teamspeak3(){
check.sh
info_ts3status.sh
if [ "${ts3status}" != "Server is running" ]; then
# Will check for updates is updateonstart is yes
if [ "${updateonstart}" == "yes" ]||[ "${updateonstart}" == "1" ]||[ "${updateonstart}" == "on" ]; then
update_check.sh
fi
fi
if [ ! -e "${servercfgfullpath}" ]; then
fn_print_warn_nl "${servercfgfullpath} is missing"
fn_scriptlog "${servercfgfullpath} is missing"
@ -35,13 +25,11 @@ fn_start_teamspeak3(){
touch "${servercfgfullpath}"
fi
logs.sh
fn_print_dots "${servername}"
fn_scriptlog "${servername}"
sleep 1
if [ "${ts3status}" == "Server is running" ]; then
check_status.sh
if [ "${status}" != "0" ]; then
fn_print_info_nl "${servername} is already running"
fn_scriptlog "${servername} is already running"
exit
@ -57,8 +45,8 @@ fn_start_teamspeak3(){
./ts3server_startscript.sh start inifile="${servercfgfullpath}" > /dev/null 2>&1
fi
sleep 1
info_ts3status.sh
if [ "${ts3status}" = "Server seems to have died" ]||[ "${ts3status}" = "No server running (ts3server.pid is missing)" ]; then
check_status.sh
if [ "${status}" == "0" ]; then
fn_print_fail_nl "Unable to start ${servername}"
fn_scriptlog "Unable to start ${servername}"
echo -e " Check log files: ${rootdir}/log"
@ -70,25 +58,13 @@ fn_start_teamspeak3(){
}
fn_start_tmux(){
check.sh
fix.sh
info_config.sh
fn_parms
logs.sh
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:")
# Will check for updates if updateonstart is yes
if [ "${tmuxwc}" -eq 0 ]; then
if [ "${updateonstart}" == "yes" ]||[ "${updateonstart}" == "1" ]||[ "${updateonstart}" == "on" ]; then
update_check.sh
fi
fi
fn_print_dots "${servername}"
fn_scriptlog "${servername}"
sleep 1
if [ "${tmuxwc}" -eq 0 ]; then
# Log rotation
check_status.sh
if [ "${status}" == "0" ]; then
fn_scriptlog "Rotating log files"
if [ "${engine}" == "unreal2" ]; then
mv "${gamelog}" "${gamelogdate}"
@ -97,7 +73,9 @@ if [ "${tmuxwc}" -eq 0 ]; then
mv "${consolelog}" "${consolelogdate}"
fi
if [ "${tmuxwc}" -eq 1 ]; then
# If server is already running exit
check_status.sh
if [ "${status}" != "0" ]; then
fn_print_info_nl "${servername} is already running"
fn_scriptlog "${servername} is already running"
exit
@ -107,19 +85,24 @@ fi
date > "${rootdir}/${lockselfname}"
cd "${executabledir}"
tmux new-session -d -s "${servicename}" "${executable} ${parms}" 2> "${scriptlogdir}/.${servicename}-tmux-error.tmp"
# tmux pipe-pane not supported in tmux versions < 1.6
if [ "$(tmux -V|sed "s/tmux //"|sed -n '1 p'|tr -cd '[:digit:]')" -lt "16" ]; then
echo "Console logging disabled: Tmux => 1.6 required" >> "${consolelog}"
echo "http://gameservermanagers.com/tmux-upgrade" >> "${consolelog}"
echo "Currently installed: $(tmux -V)" >> "${consolelog}"
# Console logging disabled: Bug in tmux 1.8 breaks logging
elif [ "$(tmux -V|sed "s/tmux //"|sed -n '1 p'|tr -cd '[:digit:]')" -eq "18" ]; then
echo "Console logging disabled: Bug in tmux 1.8 breaks logging" >> "${consolelog}"
echo "http://gameservermanagers.com/tmux-upgrade" >> "${consolelog}"
echo "Currently installed: $(tmux -V)" >> "${consolelog}"
# Console logging enable or not set
elif [ "${consolelogging}" == "on" ]||[ -z "${consolelogging}" ]; then
touch "${consolelog}"
tmux pipe-pane -o -t "${servicename}" "exec cat >> '${consolelog}'"
# Console logging disabled
elif [ "${consolelogging}" == "off" ]; then
touch "${consolelog}"
@ -127,9 +110,10 @@ elif [ "${consolelogging}" == "off" ]; then
fn_scriptlog "Console logging disabled by user"
fi
sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:")
# If the server fails to start
if [ "${tmuxwc}" -eq 0 ]; then
check_status.sh
if [ "${status}" == "0" ]; then
fn_print_fail_nl "Unable to start ${servername}"
fn_scriptlog "Unable to start ${servername}"
sleep 1
@ -181,6 +165,19 @@ rm "${scriptlogdir}/.${servicename}-tmux-error.tmp"
echo -en "\n"
}
check.sh
fix.sh
info_config.sh
fn_parms
logs.sh
# Will check for updates is updateonstart is yes
if [ "${status}" == "0" ]; then
if [ "${updateonstart}" == "yes" ]||[ "${updateonstart}" == "1" ]||[ "${updateonstart}" == "on" ]; then
update_check.sh
fi
fi
if [ "${gamename}" == "Teamspeak 3" ]; then
fn_start_teamspeak3
else

5
lgsm/functions/command_validate.sh

@ -36,9 +36,8 @@ fix.sh
fn_scriptlog "Checking complete"
}
check.sh
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:")
if [ "${tmuxwc}" -eq 1 ]; then
check_status.sh
if [ "${status}" != "0" ]; then
command_stop.sh
fn_validation
command_start.sh

7
lgsm/functions/core_functions.sh

@ -2,7 +2,7 @@
# LGSM core_functions.sh function
# Author: Daniel Gibbs
# Website: http://gameservermanagers.com
lgsm_version="020516"
lgsm_version="060516"
# Description: Defines all functions to allow download and execution of functions using fn_fetch_function.
# This function is called first before any other function. Without this file other functions would not load.
@ -207,6 +207,11 @@ functionfile="${FUNCNAME}"
fn_fetch_function
}
check_status.sh(){
functionfile="${FUNCNAME}"
fn_fetch_function
}
check_steamcmd.sh(){
functionfile="${FUNCNAME}"
fn_fetch_function

19
lgsm/functions/update_check.sh

@ -2,7 +2,7 @@
# LGSM update_check.sh function
# Author: Daniel Gibbs
# Website: http://gameservermanagers.com
lgsm_version="060216"
lgsm_version="060516"
# Description: Checks if a server update is available.
@ -88,9 +88,10 @@ if [ "${requestrestart}" -ge "1" ]; then
echo -ne "Applying update...\r"
sleep 1
echo -ne "\n"
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:")
unset updateonstart
if [ "${tmuxwc}" -eq 1 ]; then
check_status.sh
if [ "${status}" != "0" ]; then
command_stop.sh
update_dl.sh
command_start.sh
@ -156,9 +157,9 @@ if [ "${currentbuild}" != "${availablebuild}" ]; then
fn_scriptlog "Available build: ${availablebuild}"
fn_scriptlog "${currentbuild} > ${availablebuild}"
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:")
unset updateonstart
if [ "${tmuxwc}" -eq 1 ]; then
info_status.sh
if [ "${status}" != "0" ]; then
command_stop.sh
update_dl.sh
command_start.sh
@ -281,9 +282,10 @@ if [ "${currentbuilddigit}" -ne "${availablebuilddigit}" ]; then
fn_scriptlog "Current build: ${currentbuild}"
fn_scriptlog "Available build: ${availablebuild}"
fn_scriptlog "${currentbuild} > ${availablebuild}"
unset updateonstart
info_ts3status.sh
if [ "${ts3status}" = "No server running (ts3server.pid is missing)" ]; then
check_status.sh
if [ "${status}" == "0" ]; then
update_dl.sh
command_start.sh
sleep 5
@ -312,8 +314,7 @@ if [ "${gamename}" == "Teamspeak 3" ]; then
elif [ "${engine}" == "goldsource" ]||[ "${forceupdate}" == "1" ]; then
# Goldsource servers bypass checks as fn_steamcmdcheck does not work for appid 90 servers.
# forceupdate bypasses checks
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:")
if [ "${tmuxwc}" -eq 1 ]; then
if [ "${status}" != "0" ]; then
command_stop.sh
update_dl.sh
command_start.sh

Loading…
Cancel
Save