GameServerManagers / LinuxGSM

The command-line tool for quick, simple deployment and management of Linux dedicated game servers.
https://linuxgsm.com
MIT License
4.23k stars 807 forks source link

I add Ark Server rcon broadcast and Discord Alert to restart,stop,update in 15min 5min 1min #2922

Open Fr1tzl1 opened 4 years ago

Fr1tzl1 commented 4 years ago

Hello I hope you add this code or something like that

The code is only tested on an ARK server with active cluster with Discord Alert, no other alerts were active during the test

restart-broadcast  ar   | Restart the ARK Server with Broadcast on Server 15m 5m 1m.
stop-broadcast     as   | Stop the ARK Server with Broadcast on Server 15m 5m 1m.
update-broadcast   au   | Update the ARK Server with Broadcast on Server 15m 5m 1m.
arkserver@gameserver:/ark$ ./arkserver
Usage: ./arkserver [option]

LinuxGSM - ARK: Survival Evolved - Version v20.3.3
https://linuxgsm.com/arkserver

Commands
start              st   | Start the server.
stop               sp   | Stop the server.
restart            r    | Restart the server.
monitor            m    | Check server status and restart if crashed.
test-alert         ta   | Send a test alert.
details            dt   | Display server information.
postdetails        pd   | Post details to termbin.com (removing passwords).
update-lgsm        ul   | Check and apply any LinuxGSM updates.
update             u    | Check and apply any server updates.
force-update       fu   | Apply server updates bypassing check.
validate           v    | Validate server files with SteamCMD.
backup             b    | Create backup archives of the server.
console            c    | Access server console.
debug              d    | Start server directly in your terminal.
restart-broadcast  ar   | Restart the ARK Server with Broadcast on Server 15m 5m 1m.
stop-broadcast     as   | Stop the ARK Server with Broadcast on Server 15m 5m 1m.
update-broadcast   au   | Update the ARK Server with Broadcast on Server 15m 5m 1m.
install            i    | Install the server.
auto-install       ai   | Install the server without prompts.
developer          dev  | Enable developer Mode.
donate             do   | Donation options.

how to

install on Server mcrcon SEE https://github.com/Tiiffi/mcrcon/tree/v0.7.1

Add in /ARK-LGSM-FOLDER/lgsm/config-lgsm/arkserver/arkserver.cfg and for every other cluster server config

port="PORT"
queryport="QUERYPORT"
rconport="RCONPORT"
ip="SERVERPUBLICIP"
rconpassword="SERVERRCONPASSWORD"
hostname_for_discord="CLUSERSERVERNAME"

fn_parms(){
parms="\"TheIsland?SessionName=${hostname_for_discord}?AltSaveDirectoryName=${defaultmap}?listen?MultiHome=${ip}?MaxPlayers=${maxplayers}?QueryPort=${queryport}?RCONPort=${rconport}?Port=${port} -automanagedmods -NoTransferFromFiltering -clusterid=cluster1\""
}

Add in /ARK-LGSM-FOLDER/lgsm/functions/core_getopt.sh

after

cmd_fastdl=( "fd;fastdl" "command_fastdl.sh" "Build a FastDL directory." )

follow

cmd_ark_restart=( "ar;restart-broadcast" "command_ark_restart.sh" "Restart the ARK Server with Broadcast on Server 15m 5m 1m." )
cmd_ark_stop=( "as;stop-broadcast" "command_ark_stop.sh" "Stop the ARK Server with Broadcast on Server 15m 5m 1m." )
cmd_ark_update=( "au;update-broadcast" "command_ark_update.sh" "Update the ARK Server with Broadcast on Server 15m 5m 1m." )

after

## Game server exclusive commands.

follow

# ARK exclusive
if [ "${shortname}" == "ark" ]; then
        currentopt+=( "${cmd_ark_restart[@]}" )
        currentopt+=( "${cmd_ark_stop[@]}" )
        currentopt+=( "${cmd_ark_update[@]}" )
fi

Add in /ARK-LGSM-FOLDER/lgsm/functions/core_functions.sh

after

command_wipe.sh(){
functionfile="${FUNCNAME[0]}"
fn_fetch_function
}

follow

command_ark_restart.sh(){
functionfile="${FUNCNAME[0]}"
        fn_fetch_function
}

command_ark_update.sh(){
functionfile="${FUNCNAME[0]}"
fn_fetch_function
}

command_ark_stop.sh(){
functionfile="${FUNCNAME[0]}"
fn_fetch_function
}

after

update_steamcmd.sh(){
functionfile="${FUNCNAME[0]}"
fn_fetch_function
}

follow

update_ark_steamcmd.sh(){
functionfile="${FUNCNAME[0]}"
fn_fetch_function
}

create the file /ARK-LGSM-FOLDER/lgsm/functions/command_ark_stop.sh with the following content

#!/bin/bash
# LinuxGSM command_stop.sh function
# Author: Daniel Gibbs
# Contributors: UltimateByte
# Website: https://linuxgsm.com
# Description: Stops the server.

commandname="STOP"
commandaction="Stopping"
functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"

# Attempts graceful shutdown by sending 'CTRL+c'.
fn_stop_graceful_ctrlc(){
        fn_print_dots "Graceful: CTRL+c"
        fn_script_log_info "Graceful: CTRL+c"
        # Sends quit.
        tmux send-keys -t "${sessionname}" C-c  > /dev/null 2>&1
        # Waits up to 30 seconds giving the server time to shutdown gracefuly.
        for seconds in {1..30}; do
                check_status.sh
                if [ "${status}" == "0" ]; then
                        fn_print_ok "Graceful: CTRL+c: ${seconds}: "
                        fn_print_ok_eol_nl
                        fn_script_log_pass "Graceful: CTRL+c: OK: ${seconds} seconds"
                        break
                fi
                sleep 1
                fn_print_dots "Graceful: CTRL+c: ${seconds}"
        done
        check_status.sh
        if [ "${status}" != "0" ]; then
                fn_print_error "Graceful: CTRL+c: "
                fn_print_fail_eol_nl
                fn_script_log_error "Graceful: CTRL+c: FAIL"
        fi
}

# Attempts graceful shutdown by sending a specified command.
# Usage: fn_stop_graceful_cmd "console_command" "timeout_in_seconds"
# e.g.: fn_stop_graceful_cmd "quit" "30"
fn_stop_graceful_cmd(){
        fn_print_dots "Graceful: sending \"${1}\""
        fn_script_log_info "Graceful: sending \"${1}\""
        # Sends specific stop command.
        tmux send -t "${sessionname}" "${1}" ENTER > /dev/null 2>&1
        # Waits up to ${seconds} seconds giving the server time to shutdown gracefully.
        for ((seconds=1; seconds<=${2}; seconds++)); do
                check_status.sh
                if [ "${status}" == "0" ]; then
                        fn_print_ok "Graceful: sending \"${1}\": ${seconds}: "
                        fn_print_ok_eol_nl
                        fn_script_log_pass "Graceful: sending \"${1}\": OK: ${seconds} seconds"
                        break
                fi
                sleep 1
                fn_print_dots "Graceful: sending \"${1}\": ${seconds}"
        done
        check_status.sh
        if [ "${status}" != "0" ]; then
                fn_print_error "Graceful: sending \"${1}\": "
                fn_print_fail_eol_nl
                fn_script_log_error "Graceful: sending \"${1}\": FAIL"
        fi
}

# Attempts graceful shutdown of goldsrc using rcon 'quit' command.
# There is only a 3 second delay before a forced a tmux shutdown
# as GoldSrc servers 'quit' command does a restart rather than shutdown.
fn_stop_graceful_goldsrc(){
        fn_print_dots "Graceful: sending \"quit\""
        fn_script_log_info "Graceful: sending \"quit\""
        # sends quit
        tmux send -t "${sessionname}" quit ENTER > /dev/null 2>&1
        # Waits 3 seconds as goldsrc servers restart with the quit command.
        for seconds in {1..3}; do
                sleep 1
                fn_print_dots "Graceful: sending \"quit\": ${seconds}"
        done
        fn_print_ok "Graceful: sending \"quit\": ${seconds}: "
        fn_print_ok_eol_nl
        fn_script_log_pass "Graceful: sending \"quit\": OK: ${seconds} seconds"
}

# telnet command for sdtd graceful shutdown.
fn_stop_graceful_sdtd_telnet(){
        if [ -z "${telnetpass}" ]||[ "${telnetpass}" == "NOT SET" ]; then
                sdtd_telnet_shutdown=$( expect -c '
                proc abort {} {
                        puts "Timeout or EOF\n"
                        exit 1
                }
                spawn telnet '"${telnetip}"' '"${telnetport}"'
                expect {
                        "session."  { send "shutdown\r" }
                        default         abort
                }
                expect { eof }
                puts "Completed.\n"
                ')
        else
                sdtd_telnet_shutdown=$( expect -c '
                proc abort {} {
                        puts "Timeout or EOF\n"
                        exit 1
                }
                spawn telnet '"${telnetip}"' '"${telnetport}"'
                expect {
                        "password:"     { send "'"${telnetpass}"'\r" }
                        default         abort
                }
                expect {
                        "session."  { send "shutdown\r" }
                        default         abort
                }
                expect { eof }
                puts "Completed.\n"
                ')
        fi
}

# Attempts graceful shutdown of 7 Days To Die using telnet.
fn_stop_graceful_sdtd(){
        fn_print_dots "Graceful: telnet"
        fn_script_log_info "Graceful: telnet"
        if [ "${telnetenabled}" == "false" ]; then
                fn_print_info_nl "Graceful: telnet: DISABLED: Enable in ${servercfg}"
        elif [ "$(command -v expect 2>/dev/null)" ]; then
                # Tries to shutdown with both localhost and server IP.
                for telnetip in 127.0.0.1 ${ip}; do
                        fn_print_dots "Graceful: telnet: ${telnetip}:${telnetport}"
                        fn_script_log_info "Graceful: telnet: ${telnetip}:${telnetport}"
                        fn_stop_graceful_sdtd_telnet
                        completed=$(echo -en "\n ${sdtd_telnet_shutdown}" | grep "Completed.")
                        refused=$(echo -en "\n ${sdtd_telnet_shutdown}" | grep "Timeout or EOF")
                        if [ "${refused}" ]; then
                                fn_print_error "Graceful: telnet: ${telnetip}:${telnetport} : "
                                fn_print_fail_eol_nl
                                fn_script_log_error "Graceful: telnet:  ${telnetip}:${telnetport} : FAIL"
                        elif [ "${completed}" ]; then
                                break
                        fi
                done

                # If telnet shutdown was successful will use telnet again to check
                # the connection has closed, confirming that the tmux session can now be killed.
                if [ "${completed}" ]; then
                        for seconds in {1..30}; do
                                fn_stop_graceful_sdtd_telnet
                                refused=$(echo -en "\n ${sdtd_telnet_shutdown}" | grep "Timeout or EOF")
                                if [ "${refused}" ]; then
                                        fn_print_ok "Graceful: telnet: ${telnetip}:${telnetport} : "
                                        fn_print_ok_eol_nl
                                        fn_script_log_pass "Graceful: telnet: ${telnetip}:${telnetport} : ${seconds} seconds"
                                        break
                                fi
                                sleep 1
                                fn_print_dots "Graceful: telnet: ${seconds}"
                        done
                # If telnet shutdown fails tmux shutdown will be used, this risks loss of world save.
                else
                        if [ "${refused}" ]; then
                                fn_print_error "Graceful: telnet: "
                                fn_print_fail_eol_nl
                                fn_script_log_error "Graceful: telnet: ${telnetip}:${telnetport} : FAIL"
                        else
                                fn_print_error_nl "Graceful: telnet: Unknown error"
                                fn_script_log_error "Graceful: telnet: Unknown error"
                        fi
                        echo -en "\n" | tee -a "${lgsmlog}"
                        echo -en "Telnet output:" | tee -a "${lgsmlog}"
                        echo -en "\n ${sdtd_telnet_shutdown}" | tee -a "${lgsmlog}"
                        echo -en "\n\n" | tee -a "${lgsmlog}"
                fi
        else
                fn_print_warn "Graceful: telnet: expect not installed: "
                fn_print_fail_eol_nl
                fn_script_log_warn "Graceful: telnet: expect not installed: FAIL"
        fi
}

# Attempts graceful shutdown by sending /save /stop.
fn_stop_graceful_avorion(){
        fn_print_dots "Graceful: /save /stop"
        fn_script_log_info "Graceful: /save /stop"
        # Sends /save.
        tmux send-keys -t "${sessionname}" /save ENTER > /dev/null 2>&1
        sleep 5
        # Sends /quit.
        tmux send-keys -t "${sessionname}" /stop ENTER > /dev/null 2>&1
        # Waits up to 30 seconds giving the server time to shutdown gracefuly.
        for seconds in {1..30}; do
                check_status.sh
                if [ "${status}" == "0" ]; then
                        fn_print_ok "Graceful: /save /stop: ${seconds}: "
                        fn_print_ok_eol_nl
                        fn_script_log_pass "Graceful: /save /stop: OK: ${seconds} seconds"
                        break
                fi
                sleep 1
                fn_print_dots "Graceful: /save /stop: ${seconds}"
        done
        check_status.sh
        if [ "${status}" != "0" ]; then
                fn_print_error "Graceful: /save /stop: "
                fn_print_fail_eol_nl
                fn_script_log_error "Graceful: /save /stop: FAIL"
        fi
}

fn_stop_graceful_select(){
        if [ "${stopmode}" == "1" ]; then
                fn_stop_tmux
        elif [ "${stopmode}" == "2" ]; then
                fn_stop_graceful_ctrlc
        elif [ "${stopmode}" == "3" ]; then
                fn_stop_graceful_cmd "quit" 30
        elif [ "${stopmode}" == "4" ]; then
                fn_stop_graceful_cmd "quit" 120
        elif [ "${stopmode}" == "5" ]; then
                fn_stop_graceful_cmd "stop" 30
        elif [ "${stopmode}" == "6" ]; then
                fn_stop_graceful_cmd "q" 30
        elif [ "${stopmode}" == "7" ]; then
                fn_stop_graceful_cmd "exit" 30
        elif [ "${stopmode}" == "8" ]; then
                fn_stop_graceful_sdtd
        elif [ "${stopmode}" == "9" ]; then
                fn_stop_graceful_goldsrc
        elif [ "${stopmode}" == "10" ]; then
                fn_stop_graceful_avorion
        fi
}

fn_stop_tmux(){
        fn_print_dots "${servername}"
        fn_script_log_info "tmux kill-session: ${sessionname}: ${servername}"
        # Kill tmux session.
        tmux kill-session -t "${sessionname}" > /dev/null 2>&1
        sleep 0.5
        check_status.sh
        if [ "${status}" == "0" ]; then
                fn_print_ok_nl "${servername}"
                fn_script_log_pass "Stopped ${servername}"
        else
                fn_print_fail_nl "Unable to stop ${servername}"
                fn_script_log_fatal "Unable to stop ${servername}"
        fi
}

# Checks if the server is already stopped.
fn_stop_pre_check(){
        if [ "${status}" == "0" ]; then
                fn_print_info_nl "${servername} is already stopped"
                fn_script_log_error "${servername} is already stopped"
        else
                # Select graceful shutdown.
                echo -en "Broadcasting to server before shutdown...\n"
                fn_script_log_info "Broadcasting to server before shutdown"
                sleep 1
                echo
                time_left="15"
                echo
                echo "Run ARK Server shutdown with Broadcast on Server in 15min...5min...1min"
                /usr/local/bin/mcrcon -s -H ${ip} -P ${rconport} -p ${rconpassword} "broadcast AUTOMATIC MESSAGE: Server shutdown in ${time_left}min."
                echo
                echo "Server shudown in ${time_left} minutes."
                echo
                alert="stop-broadcast"
                alert.sh
                echo
                echo "Wait 10min for 5min Broadcast...."
                echo
                sleep 10m
                time_left="5"
                /usr/local/bin/mcrcon -s -H ${ip} -P ${rconport} -p ${rconpassword} "broadcast AUTOMATIC MESSAGE: Server shutdown in ${time_left}min."
                echo
                echo "Server restart in ${time_left}min."
                echo
                alert="stop-broadcast"
                alert.sh
                echo
                echo "Wait 4min for 5min Broadcast...."
                echo
                sleep 4m
                time_left="1"
                /usr/local/bin/mcrcon -s -H ${ip} -P ${rconport} -p ${rconpassword} "broadcast AUTOMATIC MESSAGE: Server shutdown in ${time_left}min."
                echo
                echo "Server shutdown in ${time_left} minutes."
                echo
                alert="stop-broadcast"
                alert.sh
                echo
                echo "Wait 1 minutes then shutdown...."
                echo
                sleep 1m
                echo
                echo "shutdown now"
                echo

                fn_stop_graceful_select
        fi
        # Check status again, a kill tmux session if graceful shutdown failed.
        check_status.sh
        if [ "${status}" != "0" ]; then
                fn_stop_tmux
        fi
}

check.sh
fn_print_dots "${servername}"

info_config.sh
fn_stop_pre_check
# Remove lockfile.
if [ -f "${lockdir}/${selfname}.lock" ]; then
        rm -f "${lockdir:?}/${selfname}.lock"
fi

if [ -z "${exitbypass}" ]; then
        core_exit.sh
fi

create the file /ARK-LGSM-FOLDER/lgsm/functions/command_ark_restart.sh with the following content

#!/bin/bash
# LinuxGSM command_restart.sh function
# Author: Daniel Gibbs
# Website: https://linuxgsm.com
# Description: Restarts the server.

commandname="MODS-INSTALL"
commandaction="Restarting"
functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"

info_config.sh
exitbypass=1

echo -en "Broadcasting to server before restart...\n"
fn_script_log_info "Broadcasting to server before restart"
sleep 1

time_left="15"
echo
echo "Run ARK Server restart with Broadcast on Server in 15m...5m...1m"
/usr/local/bin/mcrcon -s -H ${ip} -P ${rconport} -p ${rconpassword} "broadcast AUTOMATIC MESSAGE: Server restart in ${time_left} minutes."
echo
echo "Server restart in $time_left} minutes."
echo
alert="restart-broadcast"
alert.sh
echo
echo "Wait 10 minutes for 5m Broadcast...."
echo

sleep 10m
time_left="5"
/usr/local/bin/mcrcon -s -H ${ip} -P ${rconport} -p ${rconpassword} "broadcast AUTOMATIC MESSAGE: Server restart in ${time_left} minutes."
echo
echo "Server restart in ${time_left} minutes."
echo
alert="restart-broadcast"
alert.sh
echo
echo "Wait 4 minutes for 5m Broadcast...."
echo
sleep 4m
time_left="1"
/usr/local/bin/mcrcon -s -H ${ip} -P ${rconport} -p ${rconpassword} "broadcast AUTOMATIC MESSAGE: Server restart in ${time_left} minutes."
echo
echo "Server restart in ${time_left} minutes."
echo
alert="restart-broadcast"
alert.sh
echo
echo "Wait 1 minutes then restart...."
echo
sleep 1m
echo
echo "restart now"
echo

command_stop.sh
command_start.sh

echo
echo "Done"
echo

core_exit.sh

create the file /ARK-LGSM-FOLDER/lgsm/functions/command_ark_update.sh with the following content

#!/bin/bash
# LinuxGSM command_update.sh function
# Author: Daniel Gibbs
# Website: https://linuxgsm.com
# Description: Handles updating of servers.

commandname="UPDATE"
commandaction="Updating"
functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"

fn_print_dots ""
check.sh
core_logs.sh
check_last_update.sh

if [ "${shortname}" == "ts3" ]; then
        update_ts3.sh
elif [ "${shortname}" == "mc" ]; then
        update_minecraft.sh
elif [ "${shortname}" == "mcb" ]; then
        update_minecraft_bedrock.sh
elif [ "${shortname}" == "mumble" ]; then
        update_mumble.sh
elif [ "${shortname}" == "fctr" ]; then
        update_factorio.sh
elif [ "${shortname}" == "mta" ]; then
        update_mta.sh
elif [ "${shortname}" == "ark" ]; then
        update_ark_steamcmd.sh
else
        update_steamcmd.sh
fi

core_exit.sh

create the file /ARK-LGSM-FOLDER/lgsm/functions/update_ark_steamcmd.sh with the following content

#!/bin/bash
# LinuxGSM update_steamcmd.sh function
# Author: Daniel Gibbs
# Website: https://linuxgsm.com
# Description: Handles updating using SteamCMD.

functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"

fn_update_steamcmd_dl(){
        info_config.sh
        # Detects if unbuffer command is available for 32 bit distributions only.
        info_distro.sh
        if [ "$(command -v stdbuf)" ]&&[ "${arch}" != "x86_64" ]; then
                unbuffer="stdbuf -i0 -o0 -e0"
        fi
        if [ -d "${steamcmddir}" ]; then
                cd "${steamcmddir}" || exit
        fi

        # If GoldSrc (appid 90) servers. GoldSrc (appid 90) require extra commands.
        if [ "${appid}" == "90" ]; then
                # If using a specific branch.
                if [ -n "${branch}" ]; then
                        ${unbuffer} ${steamcmdcommand} +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_set_config 90 mod "${appidmod}" +app_update "${appid}" -beta "${branch}" +quit | tee -a "${lgsmlog}"
                else
                        ${unbuffer} ${steamcmdcommand} +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_set_config 90 mod "${appidmod}" +app_update "${appid}" +quit | tee -a "${lgsmlog}"
                fi
        elif [ "${shortname}" == "ac" ]; then
                ${unbuffer} ${steamcmdcommand} +@sSteamCmdForcePlatformType windows +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_update "${appid}" +quit
        # All other servers.
        else
                if [ -n "${branch}" ]; then
                        ${unbuffer} ${steamcmdcommand} +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_update "${appid}" -beta "${branch}" +quit | tee -a "${lgsmlog}"
                else
                        ${unbuffer} ${steamcmdcommand} +login "${steamuser}" "${steampass}" +force_install_dir "${serverfiles}" +app_update "${appid}" +quit | tee -a "${lgsmlog}"
                fi
        fi
        fix.sh
}

fn_update_steamcmd_localbuild(){
        # Gets local build info.
        fn_print_dots "Checking local build: ${remotelocation}"
        fn_appmanifest_check
        # Uses appmanifest to find local build.
        localbuild=$(grep buildid "${appmanifestfile}" | tr '[:blank:]"' ' ' | tr -s ' ' | cut -d\  -f3)

        # Set branch for updateinfo.
        IFS=' ' read -ra branchsplits <<< "${branch}"
        if [ "${#branchsplits[@]}" -gt 1 ]; then
                branchname="${branchsplits[1]}"
        else
                branchname="public"
        fi

        # Checks if localbuild variable has been set.
        if [ -z "${localbuild}" ]||[ "${localbuild}" == "null" ]; then
                fn_print_fail "Checking local build: ${remotelocation}"
                fn_script_log_fatal "Checking local build"
                core_exit.sh
        else
                fn_print_ok "Checking local build: ${remotelocation}"
                fn_script_log_pass "Checking local build"
        fi
}

fn_update_steamcmd_remotebuild(){
        # Gets remote build info.
        if [ -d "${steamcmddir}" ]; then
                cd "${steamcmddir}" || exit
        fi

        # Removes appinfo.vdf as a fix for not always getting up to date version info from SteamCMD.
        if [ "$(find "${HOME}" -type f -name "appinfo.vdf" | wc -l)" -ne "0" ]; then
                find "${HOME}" -type f -name "appinfo.vdf" -exec rm -f {} \;
        fi

        remotebuild=$(${steamcmdcommand} +login "${steamuser}" "${steampass}" +app_info_update 1 +app_info_print "${appid}" +quit | sed '1,/branches/d' | sed "1,/${branchname}/d" | grep -m 1 buildid | tr -cd '[:digit:]')
        if [ "${installer}" != "1" ]; then
                fn_print_dots "Checking remote build: ${remotelocation}"
                # Checks if remotebuild variable has been set.
                if [ -z "${remotebuild}" ]||[ "${remotebuild}" == "null" ]; then
                        fn_print_fail "Checking remote build: ${remotelocation}"
                        fn_script_log_fatal "Checking remote build"
                        core_exit.sh
                else
                        fn_print_ok "Checking remote build: ${remotelocation}"
                        fn_script_log_pass "Checking remote build"
                fi
        else
                # Checks if remotebuild variable has been set.
                if [ -z "${remotebuild}" ]||[ "${remotebuild}" == "null" ]; then
                        fn_print_failure "Unable to get remote build"
                        fn_script_log_fatal "Unable to get remote build"
                        core_exit.sh
                fi
        fi
}

fn_update_steamcmd_compare(){
        fn_print_dots "Checking for update: ${remotelocation}"
        if [ "${localbuild}" != "${remotebuild}" ]; then
                fn_print_ok_nl "Checking for update: ${remotelocation}"
                echo -en "\n"
                echo -e "Update available"
                echo -e "* Local build: ${red}${localbuild}${default}"
                echo -e "* Remote build: ${green}${remotebuild}${default}"
                if [ -v "${branch}" ]; then
                        echo -e "* Branch: ${branch}"
                fi
                echo -e "https://steamdb.info/app/${appid}/"
                echo -en "\n"
                fn_script_log_info "Update available"
                fn_script_log_info "Local build: ${localbuild}"
                fn_script_log_info "Remote build: ${remotebuild}"
                if [ -v "${branch}" ]; then
                        fn_script_log_info "Branch: ${branch}"
                fi
                fn_script_log_info "${localbuild} > ${remotebuild}"

                unset updateonstart
                check_status.sh
                # If server stopped.
                if [ "${status}" == "0" ]; then
                        fn_update_steamcmd_dl
                # If server started.
                else
                        echo -en "Broadcasting to server before restart...\n"
                        fn_script_log_info "Broadcasting to server before restart"
                        sleep 1
                        time_left="15"
                        echo
                        echo "Run ARK Server stop with Broadcast on Server in 15m...5m...1m"
                        /usr/local/bin/mcrcon -s -H ${ip} -P ${rconport} -p ${rconpassword} "broadcast AUTOMATIC MESSAGE: Server update and restart in ${time_left} minutes ."
                        echo
                        echo "Server update and restart in ${time_left} minutes."
                        echo
                        alert="update-broadcast"
                        alert.sh
                        echo
                        echo "Wait 10 minutes for 5m Broadcast...."
                        echo

                        sleep 10m
                        time_left="5"
                        /usr/local/bin/mcrcon -s -H ${ip} -P ${rconport} -p ${rconpassword} "broadcast AUTOMATIC MESSAGE: Server update and restart in ${time_left} minutes."
                        echo
                        echo "Server update and restart in ${time_left} minutes."
                        echo
                        alert="update-broadcast"
                        alert.sh
                        echo
                        echo "Wait 4 minutes for 5m Broadcast...."
                        echo
                        sleep 4m
                        time_left="1"
                        /usr/local/bin/mcrcon -s -H ${ip} -P ${rconport} -p ${rconpassword} "broadcast AUTOMATIC MESSAGE: Server update and restart in ${time_left} minutes."
                        echo
                        echo "Server updatea and restart in ${time_left} minutes."
                        echo
                        alert="update-broadcast"
                        alert.sh
                        echo
                        echo "Wait 1 minutes then update and restart...."
                        echo
                        sleep 1m
                        echo
                        echo "restart now"
                        echo

                        fn_stop_warning
                        exitbypass=1
                        command_stop.sh
                        exitbypass=1
                        fn_update_steamcmd_dl
                        exitbypass=1
                        command_start.sh
                fi
                date +%s > "${lockdir}/lastupdate.lock"
                alert="update"
                alert.sh
        else
                fn_print_ok_nl "Checking for update: ${remotelocation}"
                echo -en "\n"
                echo -e "No update available"
                echo -e "* Local build: ${green}${localbuild}${default}"
                echo -e "* Remote build: ${green}${remotebuild}${default}"
                if [ -v "${branch}" ]; then
                        echo -e "* Branch: ${branch}"
                fi
                echo -e "https://steamdb.info/app/${appid}/"
                echo -en "\n"
                fn_script_log_info "No update available"
                fn_script_log_info "Local build: ${localbuild}"
                fn_script_log_info "Remote build: ${remotebuild}"
                if [ -v "${branch}" ]; then
                        fn_script_log_info "Branch: ${branch}"
                fi
        fi
}

fn_appmanifest_info(){
        appmanifestfile=$(find "${serverfiles}" -type f -name "appmanifest_${appid}.acf")
        appmanifestfilewc=$(find "${serverfiles}" -type f -name "appmanifest_${appid}.acf" | wc -l)
}

fn_appmanifest_check(){
        fn_appmanifest_info
        # Multiple or no matching appmanifest files may sometimes be present.
        # This error is corrected if required.
        if [ "${appmanifestfilewc}" -ge "2" ]; then
                fn_print_error "Multiple appmanifest_${appid}.acf files found"
                fn_script_log_error "Multiple appmanifest_${appid}.acf files found"
                fn_print_dots "Removing x${appmanifestfilewc} appmanifest_${appid}.acf files"
                for appfile in ${appmanifestfile}; do
                        rm -f "${appfile:?}"
                done
                appmanifestfilewc1="${appmanifestfilewc}"
                fn_appmanifest_info
                # if error can not be resolved.
                if [ "${appmanifestfilewc}" -ge "2" ]; then
                        fn_print_fail "Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
                        fn_script_log_fatal "Unable to remove x${appmanifestfilewc} appmanifest_${appid}.acf files"
                        echo -e "* Check user permissions"
                        for appfile in ${appmanifestfile}; do
                                echo -e "       ${appfile}"
                        done
                        core_exit.sh
                else
                        fn_print_ok "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
                        fn_script_log_pass "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files"
                        fn_print_info_nl "Forcing update to correct issue"
                        fn_script_log_info "Forcing update to correct issue"
                        fn_update_steamcmd_dl
                fi
        elif [ "${appmanifestfilewc}" -eq "0" ]; then
                fn_print_error_nl "No appmanifest_${appid}.acf found"
                fn_script_log_error "No appmanifest_${appid}.acf found"
                fn_print_info_nl "Forcing update to correct issue"
                fn_script_log_info "Forcing update to correct issue"
                fn_update_steamcmd_dl
                fn_appmanifest_info
                if [ "${appmanifestfilewc}" -eq "0" ]; then
                        fn_print_fail_nl "Still no appmanifest_${appid}.acf found"
                        fn_script_log_fatal "Still no appmanifest_${appid}.acf found"
                        core_exit.sh
                fi
        fi
}

fn_stop_warning(){
        fn_print_warn "Updating server: SteamCMD: ${selfname} will be stopped during update"
        fn_script_log_warn "Updating server: SteamCMD: ${selfname} will be stopped during update"
        totalseconds=3
        for seconds in {3..1}; do
                fn_print_warn "Updating server: SteamCMD: ${selfname} will be stopped during update: ${totalseconds}"
                totalseconds=$((totalseconds - 1))
                sleep 1
                if [ "${seconds}" == "0" ]; then
                        break
                fi
        done
        fn_print_warn_nl "Updating server: SteamCMD: ${selfname} will be stopped during update"
}

# The location where the builds are checked and downloaded.
remotelocation="SteamCMD"
check_steamcmd.sh

if [ "${forceupdate}" == "1" ]; then
        # forceupdate bypasses update checks.
        check_status.sh
        if [ "${status}" != "0" ]; then
                fn_stop_warning
                exitbypass=1
                command_stop.sh
                fn_update_steamcmd_dl
                date +%s > "${lockdir}/lastupdate.lock"
                exitbypass=1
                command_start.sh
        else
                fn_update_steamcmd_dl
                date +%s > "${lockdir}/lastupdate.lock"
        fi
else
        fn_print_dots "Checking for update"
        fn_print_dots "Checking for update: ${remotelocation}"
        fn_update_steamcmd_localbuild
        fn_update_steamcmd_remotebuild
        fn_update_steamcmd_compare
fi

Add in /ARK-LGSM-FOLDER/lgsm/functions/alert.sh

after

fn_alert_restart(){
        fn_script_log_info "Sending alert: Restarted: ${executable} not running"
        alertsubject="Alert - ${selfname} - Restarted"
        alertemoji="🚨"
        alertsound="2"
        alerturl="not enabled"
        alertbody="${selfname} ${executable} not running"
}

follow

fn_alert_ark_restart(){
        fn_script_log_info "Sending alert: : ${selfname} restart in ${time_left}min"
        alertsubject="Alert - ${selfname} - ${hostname_for_discord} - Restart"
        alertemoji="➰"
        alertsound="1"
        alerturl="not enabled"
        alertbody="${hostname_for_discord} restart in ${time_left}min"
}

fn_alert_ark_update(){
        fn_script_log_info "Sending alert: : ${selfname} update and restart in ${time_left}min"
        alertsubject="Alert - ${selfname} - ${hostname_for_discord} - Update"
        alertemoji="🎮"
        alertsound="1"
        alerturl="not enabled"
        alertbody="${hostname_for_discord} update and restart in ${time_left}min"
}
fn_alert_ark_stop(){
        fn_script_log_info "Sending alert: : ${selfname} shutdown in ${time_left}min"
        alertsubject="Alert - ${selfname} - ${hostname_for_discord} - Shutdown"
        alertemoji="🎮"
        alertsound="1"
        alerturl="not enabled"
        alertbody="${hostname_for_discord} shutdown in ${time_left}min"
                                                }

fn_alert_restart_query(){
        fn_script_log_info "Sending alert: Restarted: ${selfname}"
        alertsubject="Alert - ${selfname} - Restarted"
        alertemoji="🚨"
        alertsound="2"
        alerturl="not enabled"
        alertbody="Unable to query: ${selfname}"
}

after

elif [ "${alert}" == "config" ]; then
        fn_alert_config

follow

elif [ "${alert}" == "restart-broadcast" ]; then
        fn_alert_ark_restart
elif [ "${alert}" == "update-broadcast" ]; then
        fn_alert_ark_update
elif [ "${alert}" == "stop-broadcast" ]; then
        fn_alert_ark_stop

Add in /ARK-LGSM-FOLDER/lgsm/functions/alert_discord.sh

after

escaped_alertbody=$(echo -n "${alertbody}" | jq -sRr "@json")

follow

escaped_hostname_for_discord=$(echo -n "${hostname_for_discord}" | jq -sRr "@json")

change

"name": "Server Name",
"value": ${escaped_servername},
"inline": true

to

"name": "Server Name",
"value": ${escaped_hostname_for_discord},
"inline": true
issue-label-bot[bot] commented 4 years ago

Issue-Label Bot is automatically applying the label type: feature request to this issue, with a confidence of 0.55. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

dgibbs64 commented 4 years ago

This will be very useful in the future as there are plans to do this at some point

chewbaccafr commented 3 years ago

Hello, your script don't work... Help me please ... Screenshots : image

image

dgibbs64 commented 3 years ago

There is no such command as ark-stop this looks like a fork and not official Linuxgsm

Edit: This is an unofficial script for ark

Fr1tzl1 commented 3 years ago

Hello, your script don't work... Help me please ... Screenshots :

it may be that the code no longer works with the current Linuxgsm version. I don't play ARK anymore and I don't have a server online either.

This was actually just a sample for @dgibbs64

Ultchad commented 3 years ago

@chewbaccafr

Hello, your script don't work... Help me please ...

I don't test the code but your log error show '\r'. It's when your file use \r\n for new line special caracter (sorry for my english) you may use \n (standard linux)

if i have time i will test the code, @Fr1tzl1 You have create a fork with your code for test ? a Pull Request ? (I haved the same idea for discord and the Altert system , thanks to you)

ToeiRei commented 3 years ago

Any progress on the implementation? I'd love to see such things as a core feature

DrewWeird commented 2 years ago

I have just set this up and can confirm that it works with the latest LGSM and Ark Version.

I have to make a minor change in the very last config section under alert_discord.sh

i left out this completely

escaped_hostname_for_discord=$(echo -n "${hostname_for_discord}" | jq -sRr "@json")

And i changed from this

"name": "Server Name",
"value": ${escaped_hostname_for_discord},
"inline": true

to this

"name": "Server Name",
"value": ${hostname_for_discord},
"inline": true