Просмотр исходного кода

feat(ts3server): converted to use tmux (#2565)

Daniel Gibbs 6 лет назад
Родитель
Сommit
f622fe5ddf

+ 10 - 2
lgsm/config-default/config-lgsm/ts3server/_default.cfg

@@ -11,6 +11,11 @@
 
 #### LinuxGSM Settings ####
 
+## Server Start Command | https://docs.linuxgsm.com/configuration/start-parameters#additional-parameters
+fn_parms(){
+parms="inifile=${servercfgfullpath} pid_file=ts3server.pid"
+}
+
 ## Notification Alerts
 # (on|off)
 
@@ -100,7 +105,7 @@ sleeptime="0.5"
 # 8: 7 Days to Die
 # 9: Gold Source
 # 10: Teamspeak 3
-stopmode="10"
+stopmode="2"
 
 ## LinuxGSM Server Details
 # Do not edit
@@ -115,7 +120,7 @@ glibc="2.17"
 ## Server Specific Directories
 systemdir="${serverfiles}"
 executabledir="${serverfiles}"
-executable="./ts3server_startscript.sh"
+executable="./ts3server"
 servercfg="${servicename}.ini"
 servercfgdefault="ts3server.ini"
 servercfgdir="${serverfiles}"
@@ -128,9 +133,12 @@ backupdir="${lgsmdir}/backup"
 logdir="${rootdir}/log"
 gamelogdir="${serverfiles}/logs"
 lgsmlogdir="${logdir}/script"
+consolelogdir="${logdir}/console"
 lgsmlog="${lgsmlogdir}/${servicename}-script.log"
+consolelog="${consolelogdir}/${servicename}-console.log"
 alertlog="${lgsmlogdir}/${servicename}-alert.log"
 postdetailslog="${lgsmlogdir}/${servicename}-postdetails.log"
 
 ## Logs Naming
 lgsmlogdate="${lgsmlogdir}/${servicename}-script-$(date '+%Y-%m-%d-%H:%M:%S').log"
+consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%Y-%m-%d-%H:%M:%S').log"

+ 10 - 15
lgsm/functions/check_deps.sh

@@ -337,13 +337,10 @@ fn_deps_build_debian(){
 	# LinuxGSM requirements.
 	array_deps_required=( curl wget ca-certificates file bsdmainutils util-linux python3 tar bzip2 gzip unzip binutils bc jq )
 
-	# All servers except ts3 require tmux.
-	if [ "${shortname}" != "ts3" ]; then
-		if [ "$(command -v tmux 2>/dev/null)" ]; then
-			tmuxcheck=1 # Added for users compiling tmux from source to bypass check.
-		else
-			array_deps_required+=( tmux )
-		fi
+	if [ "$(command -v tmux 2>/dev/null)" ]; then
+		tmuxcheck=1 # Added for users compiling tmux from source to bypass check.
+	else
+		array_deps_required+=( tmux )
 	fi
 
 	# All servers except ts3, mumble, GTA and minecraft servers require libstdc++6 and lib32gcc1.
@@ -400,7 +397,7 @@ fn_deps_build_debian(){
 		else
 			array_deps_required+=( openjdk-8-jre-headless )
 		fi
-	# Medal of Honor: Allied Assault 
+	# Medal of Honor: Allied Assault
 	elif [ "${shortname}" == "mohaa" ]; then
 		array_deps_required+=( libstdc++5:i386 )
 	# Project Zomboid
@@ -467,13 +464,11 @@ fn_deps_build_redhat(){
 	fi
 
 	# All servers except ts3 require tmux.
-	if [ "${shortname}" != "ts3" ]; then
-		if [ "$(command -v tmux 2>/dev/null)" ]; then
-			# Added for users compiling tmux from source to bypass check.
-			tmuxcheck=1
-		else
-			array_deps_required+=( tmux )
-		fi
+	if [ "$(command -v tmux 2>/dev/null)" ]; then
+		# Added for users compiling tmux from source to bypass check.
+		tmuxcheck=1
+	else
+		array_deps_required+=( tmux )
 	fi
 
 	# All servers except ts3, mumble, multi theft auto and minecraft servers require glibc.i686 and libstdc++.i686.

+ 1 - 1
lgsm/functions/check_logs.sh

@@ -15,7 +15,7 @@ fn_check_logs(){
 }
 
 # Create directories for the script and console logs.
-if [ ! -d "${lgsmlogdir}" ]||[ ! -d "${consolelogdir}" ]&&[ "${shortname}" != "ts3" ]; then
+if [ ! -d "${lgsmlogdir}" ]||[ ! -d "${consolelogdir}" ]; then
 	fn_check_logs
 fi
 

+ 1 - 14
lgsm/functions/check_status.sh

@@ -8,17 +8,4 @@
 local commandname="CHECK"
 local function_selfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
-if [ "${shortname}" == "ts3" ]; then
-	# 1: Server is running
-	# 0: Server seems to have died
-	# 0: No server running (ts3server.pid is missing)
-	status=$("${executabledir}/ts3server_startscript.sh" status servercfgfullpathfile="${servercfgfullpath}")
-	if [ "${status}" == "Server is running" ]; then
-		status=1
-	else
-		ts3error="${status}"
-		status=0
-	fi
-else
-	status=$(tmux list-sessions -F "#{session_name}" 2>/dev/null | grep -Ecx "^${servicename}")
-fi
+status=$(tmux list-sessions -F "#{session_name}" 2>/dev/null | grep -Ecx "^${servicename}")

+ 1 - 1
lgsm/functions/command_console.sh

@@ -19,7 +19,7 @@ fn_print_warning_nl "Do NOT press CTRL+c to exit."
 echo -e "	* https://docs.linuxgsm.com/commands/console"
 echo -e ""
 if ! fn_prompt_yn "Continue?" Y; then
-	echo Exiting; return
+	return
 fi
 fn_print_dots "Accessing console"
 check_status.sh

+ 1 - 1
lgsm/functions/command_debug.sh

@@ -86,7 +86,7 @@ echo -e "Press CTRL+c to drop out of debug mode."
 fn_print_warning_nl "If ${servicename} is already running it will be stopped."
 echo -e ""
 if ! fn_prompt_yn "Continue?" Y; then
-	echo Exiting; return
+	return
 fi
 
 fn_print_info_nl "Stopping any running servers"

+ 1 - 1
lgsm/functions/command_mods_install.sh

@@ -87,7 +87,7 @@ if [ -f "${modsinstalledlistfullpath}" ]; then
 		fn_script_log_warn "${modprettyname} is already installed"
 		echo -e " * Any configs may be overwritten."
 		if ! fn_prompt_yn "Continue?" Y; then
-			echo Exiting; core_exit.sh
+			core_exit.sh
 		fi
 		fn_script_log_info "User selected to continue"
 	fi

+ 1 - 1
lgsm/functions/command_mods_remove.sh

@@ -46,7 +46,7 @@ done
 fn_print_warning_nl "You are about to remove ${cyan}${usermodselect}${default}."
 echo -e " * Any custom files/configuration will be removed."
 if ! fn_prompt_yn "Continue?" Y; then
-	echo Exiting; exit
+	core_exit.sh
 fi
 
 currentmod="${usermodselect}"

+ 1 - 1
lgsm/functions/command_postdetails.sh

@@ -67,7 +67,7 @@ else
 		fn_info_message_script
 		fn_info_message_backup
 		# Some game servers do not have parms.
-		if [ "${shortname}" != "ts3" ]&&[ "${shortname}" != "jc2" ]&&[ "${shortname}" != "jc3" ]&&[ "${shortname}" != "dst" ]&&[ "${shortname}" != "pz" ]&&[ "${engine}" != "renderware" ]; then
+		if [ "${shortname}" != "jc2" ]&&[ "${shortname}" != "jc3" ]&&[ "${shortname}" != "dst" ]&&[ "${shortname}" != "pz" ]&&[ "${engine}" != "renderware" ]; then
 			fn_parms
 			fn_info_message_commandlineparms
 		fi

+ 1 - 24
lgsm/functions/command_start.sh

@@ -24,34 +24,11 @@ fn_start_teamspeak3(){
 		sleep 5
 		touch "${servercfgfullpath}"
 	fi
-	fn_sleep_time
-	if [ -f "${lgsmlog}" ]; then
-		mv "${lgsmlog}" "${lgsmlogdate}"
-	fi
-
-	# Create lockfile.
-	date '+%s' > "${rootdir}/${lockselfname}"
 	# Accept license.
 	if [ ! -f "${executabledir}/.ts3server_license_accepted" ]; then
 		install_eula.sh
 	fi
-	cd "${executabledir}" || exit
-	if [ "${ts3serverpass}" == "1" ]; then
-		./ts3server_startscript.sh start serveradmin_password="${newpassword}" inifile="${servercfgfullpath}" > /dev/null 2>&1
-	else
-		./ts3server_startscript.sh start inifile="${servercfgfullpath}" > /dev/null 2>&1
-	fi
-	fn_sleep_time
-	check_status.sh
-	if [ "${status}" == "0" ]; then
-		fn_print_fail_nl "Unable to start ${servername}"
-		fn_script_log_fatal "Unable to start ${servername}"
-		echo -e "	Check log files: ${logdir}"
-		core_exit.sh
-	else
-		fn_print_ok_nl "${servername}"
-		fn_script_log_pass "Started ${servername}"
-	fi
+	fn_start_tmux
 }
 
 fn_start_tmux(){

+ 0 - 18
lgsm/functions/command_stop.sh

@@ -200,22 +200,6 @@ fn_stop_graceful_select(){
 		fn_stop_graceful_sdtd
 	elif [ "${stopmode}" == "9" ]; then
 		fn_stop_graceful_goldsource
-	elif [ "${stopmode}" == "10" ]; then
-		fn_stop_teamspeak3
-	fi
-}
-
-fn_stop_teamspeak3(){
-	fn_print_dots "${servername}"
-	"${serverfiles}"/ts3server_startscript.sh stop > /dev/null 2>&1
-	check_status.sh
-	if [ "${status}" == "0" ]; then
-		rm -f "${rootdir}/${lockselfname}"
-		fn_print_ok_nl "${servername}"
-		fn_script_log_pass "Stopped ${servername}"
-	else
-		fn_print_fail_nl "Unable to stop ${servername}"
-		fn_script_log_error "Unable to stop ${servername}"
 	fi
 }
 
@@ -240,8 +224,6 @@ fn_stop_pre_check(){
 	if [ "${status}" == "0" ]; then
 		fn_print_info_nl "${servername} is already stopped"
 		fn_script_log_error "${servername} is already stopped"
-	elif [ "${shortname}" == "ts3" ]; then
-		fn_stop_teamspeak3
 	else
 		# Select graceful shutdown.
 		fn_stop_graceful_select

+ 7 - 10
lgsm/functions/command_ts3_server_pass.sh

@@ -5,13 +5,12 @@
 # Website: https://linuxgsm.com
 # Description: Changes TS3 serveradmin password.
 
-local commandname="TS3-CHANGE-PASS"
-local commandaction="ServerAdmin Password Change"
+local commandname="PASSWORD-CHANGE"
+local commandaction="Password Change"
 local function_selfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
 fn_serveradmin_password_prompt(){
 	fn_print_header
-	echo -e "Press \"CTRL+b d\" to exit console."
 	fn_print_information_nl "You are about to change the ${gamename} ServerAdmin password."
 	fn_print_warning_nl "${gamename} will restart during this process."
 	echo -e ""
@@ -19,32 +18,30 @@ fn_serveradmin_password_prompt(){
 		echo Exiting; exit
 	fi
 	fn_script_log_info "Initiating ${gamename} ServerAdmin password change"
-	read -rp "Enter new password : " newpassword
+	read -rp "Enter new password: " newpassword
+	fn_print_info_nl "Changing password"
+	fn_script_log_info "Changing password"
 }
 
 fn_serveradmin_password_set(){
-	fn_print_info_nl "Starting server with new password..."
-	fn_script_log_info "Starting server with new password"
 	# Start server in "new password mode".
 	ts3serverpass="1"
 	exitbypass="1"
 	command_start.sh
-	fn_print_ok_nl "Password applied"
+	fn_print_ok_nl "New password applied"
 	fn_script_log_pass "New ServerAdmin password applied"
 }
 
 # Running functions.
 check.sh
 fn_serveradmin_password_prompt
-check_status.sh
 if [ "${status}" != "0" ]; then
 	# Stop any running server.
 	exitbypass="1"
 	command_stop.sh
 	fn_serveradmin_password_set
+	parms="serveradmin_password=\"${newpassword}\" inifile=\"${servercfgfullpath}\" > /dev/null 2>&1"
 	ts3serverpass="0"
-	fn_print_info_nl "Restarting server normally"
-	fn_script_log_info "Restarting server normally"
 	command_restart.sh
 else
 	fn_serveradmin_password_set

+ 1 - 1
lgsm/functions/command_wipe.sh

@@ -185,7 +185,7 @@ if [ "${shortname}" == "rust" ]; then
 	if [ -d "${serveridentitydir}/storage" ]||[ -d "${serveridentitydir}/user" ]||[ -n "$(find "${serveridentitydir}" -type f -name "proceduralmap*.sav")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "barren*.sav")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "Log.*.txt")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "player.deaths.*.db")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "player.blueprints.*.db")" ]||[ -n "$(find "${serveridentitydir}" -type f -name "sv.files.*.db")" ]; then
 		fn_print_warning_nl "Any user, storage, log and map data from ${serveridentitydir} will be erased."
 		if ! fn_prompt_yn "Continue?" Y; then
-				echo Exiting; core_exit.sh
+				core_exit.sh
 		fi
 		fn_script_log_info "User selects to erase any user, storage, log and map data from ${serveridentitydir}"
 		fn_sleep_time

+ 1 - 1
lgsm/functions/compress_unreal2_maps.sh

@@ -18,7 +18,7 @@ echo -e ""
 echo -e "${compressedmapsdir}"
 echo -e ""
 if ! fn_prompt_yn "Start compression?" Y; then
-	echo Exiting; return
+	return
 fi
 mkdir -pv "${compressedmapsdir}" > /dev/null 2>&1
 rm -rfv "${serverfiles}/Maps/"*.ut2.uz2

+ 1 - 1
lgsm/functions/compress_ut99_maps.sh

@@ -18,7 +18,7 @@ echo -e ""
 echo -e "${compressedmapsdir}"
 echo -e ""
 if ! fn_prompt_yn "Start compression?" Y; then
-	echo Exiting; return
+	return
 fi
 mkdir -pv "${compressedmapsdir}" > /dev/null 2>&1
 rm -rfv "${serverfiles}/Maps/"*.unr.uz

+ 3 - 5
lgsm/functions/core_getopt.sh

@@ -74,13 +74,11 @@ if [ -n "${appid}" ]; then
 	currentopt+=( "${cmd_validate[@]}" )
 fi
 
-#Backup.
+# Backup.
 currentopt+=( "${cmd_backup[@]}" )
 
-# Exclude games without a console.
-if [ "${shortname}" != "ts3" ]; then
-	currentopt+=( "${cmd_console[@]}" "${cmd_debug[@]}" )
-fi
+# Console & Debug
+currentopt+=( "${cmd_console[@]}" "${cmd_debug[@]}" )
 
 ## Game server exclusive commands.
 

+ 3 - 5
lgsm/functions/info_distro.sh

@@ -9,9 +9,7 @@ local function_selfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
 ### Game Server pid
 if [ "${status}" == "1" ]; then
-	if [ "${shortname}" != "ts3" ]; then
-		gameserverpid=$(tmux list-sessions -F "#{session_name} #{pane_pid}"| grep "^${servicename}"|awk '{print $2}')
-	fi
+	gameserverpid=$(tmux list-sessions -F "#{session_name} #{pane_pid}"| grep "^${servicename}"|awk '{print $2}')
 fi
 ### Distro information
 
@@ -100,7 +98,7 @@ cpumodel=$(awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo | sed
 cpucores=$(awk -F: '/model name/ {core++} END {print core}' /proc/cpuinfo)
 cpufreqency=$(awk -F: ' /cpu MHz/ {freq=$2} END {print freq " MHz"}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//')
 # CPU usage of the game server pid
-if [ "${status}" == "1" ]; then
+if [ "${gameserverpid}" ]; then
 	cpuused=$(ps --forest -o pcpu -g "${gameserverpid}"|awk '{s+=$1} END {print s}')
 fi
 
@@ -138,7 +136,7 @@ if [ -n "$(command -v numfmt 2>/dev/null)" ]; then
 	swapused=$(numfmt --to=iec --from=iec --suffix=B "$(($(grep ^SwapTotal /proc/meminfo | awk '{print $2}')-$(grep ^SwapFree /proc/meminfo | awk '{print $2}')))K")
 	# RAM usage of the game server pid
 	# MB
-	if [ "${status}" == "1" ]; then
+	if [ "${gameserverpid}" ]; then
 		memused=$(ps --forest -o rss -g "${gameserverpid}" | awk '{s+=$1} END {print s}'| awk '{$1/=1024;printf "%.0fMB\t",$1}{print $2}')
 	# %
 		pmemused=$(ps --forest -o %mem -g "${gameserverpid}" | awk '{s+=$1} END {print s}')

+ 2 - 2
lgsm/functions/install_retry.sh

@@ -9,7 +9,7 @@ local commandaction="Install"
 local function_selfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
 if fn_prompt_yn "Retry install?" Y; then
-	command_install.sh; exit
+	command_install.sh; core_exit.sh
 else
-	echo Exiting; exit
+	core_exit.sh
 fi

+ 4 - 2
lgsm/functions/install_ts3db.sh

@@ -70,7 +70,9 @@ echo -e "${lightyellow}Getting privilege key${default}"
 echo -e "================================="
 fn_sleep_time
 fn_print_information_nl "Save these details for later."
+fn_print_information_nl "Key also saved in:"
+echo -e "${serverfiles}/privilege_key.txt"
 cd "${executabledir}" || exit
-${executable} start inifile=ts3-server.ini
+./ts3server_startscript.sh start inifile=ts3-server.ini 2>&1 | tee "${serverfiles}/privilege_key.txt"
 sleep 5
-${executable} stop
+./ts3server_startscript.sh stop