Add Rimworld-Together/restartserver.sh

This commit is contained in:
Clarth 2024-03-01 23:52:33 -05:00
parent 7d0c8b3d53
commit 76f4f05807
1 changed files with 43 additions and 0 deletions

View File

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