<commit_before>#!/bin/bash
# LGSM command_monitor.sh function
# Author: <NAME>
# Website: https://gameservermanagers.com
lgsm_version="060516"

# Description: Monitors server by checking for running proccesses
# then passes to monitor_gsquery.sh.

local modulename="Monitor"
function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"

fn_monitor_check_lockfile(){
	# Monitor does not run it lockfile is not found
	if [ ! -f "${rootdir}/${lockselfname}" ]; then
		fn_print_info_nl "Disabled: No lock file found"
		fn_scriptlog "Disabled: No lock file found"
		echo "	* To enable monitor run ./${selfname} start"
		exit 1
	fi
}

fn_monitor_check_update(){
	# Monitor will not check if update is running.
	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
		exit
	fi
}

fn_monitor_msg_checking(){
	fn_print_dots "Checking session: "
	fn_print_checking_eol
	fn_scriptlog "Checking session: CHECKING"
	sleep 1	
}

fn_monitor_email_notification(){
	# Email will be sent if enabled
	if [ "${emailnotification}" = "on" ]; then
		subject="${servicename} Monitor - Starting ${servername}"
		failurereason="${servicename} process not running"
		actiontaken="${servicename} has been restarted"
		email.sh
	fi	
}

fn_monitor_teamspeak3(){
	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: ${ts3error}: "
		fn_print_fail_eol_nl
		fn_scriptlog "Checking session: ${ts3error}: FAIL"
		failurereason="${ts3error}"
		fn_monitor_email_notification
	fi
	fn_scriptlog "Monitor is starting ${servername}"
	sleep 1
	fn_restart
}

fn_monitor_tmux(){
	# checks that tmux session is running
	if [ "${status}" != "0" ]; then
		fn_print_ok "Checking session: OK"
		fn_print_ok_eol_nl
		fn_scriptlog "Checking session: OK"
		# runs gsquery check on game with specific engines.
		local allowed_engines_array=( avalanche goldsource realvirtuality source spark unity3d unreal unreal2 )
		for allowed_engine in "${allowed_engines_array[@]}"
		do
			if [ "${allowed_engine}" == "${function_selfname}" ]; then
				monitor_gsquery.sh
			fi
		done<commit_msg>fixed error and OK display<commit_after>#!/bin/bash
# LGSM command_monitor.sh function
# Author: <NAME>
# Website: https://gameservermanagers.com
lgsm_version="060516"

# Description: Monitors server by checking for running proccesses
# then passes to monitor_gsquery.sh.

local modulename="Monitor"
function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"

fn_monitor_check_lockfile(){
	# Monitor does not run it lockfile is not found
	if [ ! -f "${rootdir}/${lockselfname}" ]; then
		fn_print_info_nl "Disabled: No lock file found"
		fn_scriptlog "Disabled: No lock file found"
		echo "	* To enable monitor run ./${selfname} start"
		exit 1
	fi
}

fn_monitor_check_update(){
	# Monitor will not check if update is running.
	if [ "$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)" != "0" ]; then
		fn_print_info_nl "SteamCMD is currently checking for updates"
		fn_scriptlog "SteamCMD is currently checking for updates"
		sleep 1
		exit
	fi
}

fn_monitor_msg_checking(){
	fn_print_dots "Checking session: "
	fn_print_checking_eol
	fn_scriptlog "Checking session: CHECKING"
	sleep 1	
}

fn_monitor_email_notification(){
	# Email will be sent if enabled
	if [ "${emailnotification}" = "on" ]; then
		subject="${servicename} Monitor - Starting ${servername}"
		failurereason="${servicename} process not running"
		actiontaken="${servicename} has been restarted"
		email.sh
	fi	
}

fn_monitor_teamspeak3(){
	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: ${ts3error}: "
		fn_print_fail_eol_nl
		fn_scriptlog "Checking session: ${ts3error}: FAIL"
		failurereason="${ts3error}"
		fn_monitor_email_notification
	fi
	fn_scriptlog "Monitor is starting ${servername}"
	sleep 1
	fn_restart
}

fn_monitor_tmux(){
	# checks that tmux session is running
	if [ "${status}" != "0" ]; then
		fn_print_ok "Checking session: "
		fn_print_ok_eol_nl
		fn_scriptlog "Checking session: OK"
		# runs gsquery check on game with specific engines.
		local allowed_engines_array=( avalanche goldsource realvirtuality source spark unity3d unreal unreal2 )
		for allowed_engine in "${allowed_engines_array[@]}"
		do
			if [ "${allowed_engine}" == "${function_selfname}" ]; then
				monitor_gsquery.sh
			fi
		done
{'fraction_non_alphanumeric': 0.11199655395218609, 'fraction_numerical': 0.008615119534783545, 'mean_word_length': 5.054758800521513, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6698471', 'n_tokens_mistral': 1690, 'n_tokens_neox': 1561, 'n_words': 446}