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 + + + + + +