Gamer-Server-Utility-Scripts/Rimworld-Together/restartserver.sh

44 lines
799 B
Bash
Raw Permalink Normal View History

2024-03-01 23:52:33 -05:00
#!/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