How to Set Up a FiveM Server: Step-by-Step Guide
Complete FiveM server setup guide on REXE VDS: installation, txAdmin configuration, port settings, and performance optimization tips for GTA V roleplay servers.
Auto-start your game server with systemd, watchdog scripts, restart policies, and tmux/screen usage guide.
Game servers are services that need to run 24/7. Automatic restart in case of server crashes, system reboots, or unexpected errors is critical. This guide covers systemd service configuration, watchdog scripts, tmux/screen usage, and restart policy settings in detail.
sudo nano /etc/systemd/system/gameserver.service
[Unit]
Description=Game Dedicated Server
After=network.target
Wants=network-online.target
[Service]
Type=simple
User=steam
Group=steam
WorkingDirectory=/home/steam/gameserver
ExecStartPre=/home/steam/steamcmd/steamcmd.sh +force_install_dir /home/steam/gameserver +login anonymous +app_update APP_ID +quit
ExecStart=/home/steam/gameserver/start.sh
ExecStop=/bin/kill -SIGINT $MAINPID
Restart=on-failure
RestartSec=30
StartLimitIntervalSec=300
StartLimitBurst=5
TimeoutStartSec=180
TimeoutStopSec=60
StandardOutput=journal
StandardError=journal
SyslogIdentifier=gameserver
LimitNOFILE=100000
[Install]
WantedBy=multi-user.target
# Enable service (auto-start on boot)
sudo systemctl daemon-reload
sudo systemctl enable gameserver
# Service management
sudo systemctl start gameserver
sudo systemctl stop gameserver
sudo systemctl restart gameserver
sudo systemctl status gameserver
# View logs
sudo journalctl -u gameserver -f
sudo journalctl -u gameserver --since "1 hour ago"
| Option | Description |
|---|---|
| no | No restart |
| on-success | Only on successful exit |
| on-failure | On error (exit code != 0) |
| on-abnormal | On signal or timeout |
| on-watchdog | On watchdog timeout |
| always | Always restart |
[Service]
Restart=always
RestartSec=15
StartLimitIntervalSec=600
StartLimitBurst=10
This configuration:
sudo systemctl reset-failed gameserver
sudo systemctl start gameserver
nano ~/watchdog.sh
#!/bin/bash
SERVICE="gameserver"
LOG="/home/steam/watchdog.log"
while true; do
if ! systemctl is-active --quiet $SERVICE; then
echo "$(date): $SERVICE not running, restarting..." >> $LOG
sudo systemctl restart $SERVICE
sleep 30
fi
sleep 60
done
chmod +x ~/watchdog.sh
nano ~/watchdog_advanced.sh
#!/bin/bash
SERVICE="gameserver"
PORT=27015
LOG="/home/steam/watchdog.log"
MAX_RETRIES=3
RETRY_COUNT=0
check_port() {
ss -tuln | grep -q ":$PORT "
return $?
}
check_process() {
systemctl is-active --quiet $SERVICE
return $?
}
while true; do
if ! check_process; then
echo "$(date): Process not running, restarting..." >> $LOG
sudo systemctl restart $SERVICE
RETRY_COUNT=$((RETRY_COUNT + 1))
sleep 60
elif ! check_port; then
echo "$(date): Port $PORT not responding, checking..." >> $LOG
RETRY_COUNT=$((RETRY_COUNT + 1))
if [ $RETRY_COUNT -ge $MAX_RETRIES ]; then
echo "$(date): $MAX_RETRIES attempts failed, restarting server..." >> $LOG
sudo systemctl restart $SERVICE
RETRY_COUNT=0
fi
sleep 30
else
RETRY_COUNT=0
fi
sleep 60
done
chmod +x ~/watchdog_advanced.sh
sudo nano /etc/systemd/system/gameserver-watchdog.service
[Unit]
Description=Game Server Watchdog
After=gameserver.service
Requires=gameserver.service
[Service]
Type=simple
User=steam
ExecStart=/home/steam/watchdog_advanced.sh
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable gameserver-watchdog
sudo systemctl start gameserver-watchdog
sudo apt install tmux -y
nano ~/start_tmux.sh
#!/bin/bash
SESSION="gameserver"
tmux kill-session -t $SESSION 2>/dev/null
tmux new-session -d -s $SESSION
tmux send-keys -t $SESSION "cd ~/gameserver && ./start.sh" C-m
echo "Server started in tmux session '$SESSION'."
echo "To attach: tmux attach -t $SESSION"
chmod +x ~/start_tmux.sh
tmux attach -t gameserver # Attach to session
# Ctrl+B, then D # Detach from session
tmux list-sessions # List sessions
tmux kill-session -t gameserver # Kill session
sudo apt install screen -y
nano ~/start_screen.sh
#!/bin/bash
SCREEN_NAME="gameserver"
screen -S $SCREEN_NAME -X quit 2>/dev/null
screen -dmS $SCREEN_NAME bash -c "cd ~/gameserver && ./start.sh"
echo "Server started in screen '$SCREEN_NAME'."
echo "To attach: screen -r $SCREEN_NAME"
chmod +x ~/start_screen.sh
screen -r gameserver # Attach to screen
# Ctrl+A, then D # Detach from screen
screen -ls # List screens
screen -S gameserver -X quit # Kill screen
nano ~/auto_update_restart.sh
#!/bin/bash
SERVICE="gameserver"
LOG="/home/steam/update.log"
echo "$(date): Starting update..." >> $LOG
sudo systemctl stop $SERVICE
sleep 10
~/steamcmd/steamcmd.sh +force_install_dir ~/gameserver +login anonymous +app_update APP_ID +quit >> $LOG 2>&1
sudo systemctl start $SERVICE
echo "$(date): Update complete." >> $LOG
chmod +x ~/auto_update_restart.sh
crontab -e
0 4 * * * /home/steam/auto_update_restart.sh
With systemd service configuration, watchdog scripts, and tmux/screen usage, you can ensure your game server runs 24/7 without interruption. Proper restart policies and automatic update mechanisms automate server management. REXE VDS reliable infrastructure ensures your server is always accessible.
systemd service ensures your server starts automatically on system boot and restarts on crashes.
Both are terminal multiplexers. tmux is more modern and feature-rich, while screen is older and more widespread. Functionally they are similar.
A watchdog script regularly checks if the server is running. If the server is down or the port is not responding, it automatically restarts.
Configure Restart, RestartSec, StartLimitIntervalSec, and StartLimitBurst parameters in the systemd service file.
Use journalctl -u gameserver -f for live logs and journalctl -u gameserver --since '1 hour ago' for the last hour's logs.
Complete FiveM server setup guide on REXE VDS: installation, txAdmin configuration, port settings, and performance optimization tips for GTA V roleplay servers.
Complete Minecraft server setup guide on REXE VDS: Paper/Spigot installation, Java configuration, plugin management, and performance optimization for stable gameplay.
Complete CS2 dedicated server setup guide on REXE VDS: SteamCMD installation, GSLT token, server configuration, game modes, and DDoS protection with Path Panel.