From 76f4f0580728070048507ff732012c7d0230ef8a Mon Sep 17 00:00:00 2001 From: Clarth Date: Fri, 1 Mar 2024 23:52:33 -0500 Subject: [PATCH] Add Rimworld-Together/restartserver.sh --- Rimworld-Together/restartserver.sh | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Rimworld-Together/restartserver.sh diff --git a/Rimworld-Together/restartserver.sh b/Rimworld-Together/restartserver.sh new file mode 100644 index 0000000..9b305f7 --- /dev/null +++ b/Rimworld-Together/restartserver.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +# Variables - Change these for each game server +game="rimworld" +GAME_DIR="/home/$game" +log_file="$GAME_DIR/script.log" + + + +# Functions +start_server() { + # Kill any previous screen sessions + screen -X -S "$game" quit > /dev/null 2>&1 + + # Start the screen and run the server + cd "$GAME_DIR" || exit 1 + screen -dmS "$game" ./serverupdate.sh && echo "Restarted at: $(date)" >> "$log_file" +} + + + +# Run the screen command to stop the server +output=$(screen -p 0 -S "$game" -X eval "stuff quit\015" 2>&1) + +# Check if the output contains the "No screen session found" message +if [[ $output == *"No screen session found."* ]]; then + echo "Starting Server" + start_server + exit +else + echo "Saving World, Please wait." + echo "This takes some time!" + sleep 30 + start_server +fi + +exit + + + + + +