Gaming

Automate Game Server Restarts with systemd and cron

Keep your game server rock-solid: a systemd service that auto-restarts on crash and boot, plus a scheduled nightly restart with player warnings.

NXNxeonNxeon editorialJune 18, 2026 3 min readUpdated July 23, 2026
Quick answer

Keep your game server rock-solid: a systemd service that auto-restarts on crash and boot, plus a scheduled nightly restart with player warnings.

Topic
Gaming
Read time
3 min read
Covers
systemd, cron, game-servers
Last updated
July 23, 2026

Running a game server in a screen session is fine for testing, but for a server you actually rely on, you want it to restart itself — after a crash, after a reboot, and on a nightly schedule to clear memory leaks. That's what systemd is for. Here's how to set it up.

Why systemd beats screen

A screen session dies if the server crashes and doesn't come back after a reboot. A systemd service:

  • Restarts automatically if the server process crashes.
  • Starts on boot, so a VPS reboot brings your game back with no action from you.
  • Logs cleanly to the journal, so you can see what happened.
  • Starts, stops and restarts with simple commands.

Step 1: Create the service file

As root, create /etc/systemd/system/minecraft.service (adapt paths and command to your game):

[Unit]
Description=Minecraft Server
After=network.target

[Service]
User=minecraft
WorkingDirectory=/home/minecraft/server
ExecStart=/usr/bin/java -Xms4G -Xmx4G -jar server.jar nogui
Restart=on-failure
RestartSec=10
SuccessExitStatus=0 1

[Install]
WantedBy=multi-user.target

The key line is Restart=on-failure — if the process exits unexpectedly, systemd waits 10 seconds and starts it again.

Step 2: Enable and start it

sudo systemctl daemon-reload
sudo systemctl enable minecraft
sudo systemctl start minecraft

enable makes it start on boot; start launches it now. Check it's healthy:

sudo systemctl status minecraft
journalctl -u minecraft -f

That last command tails the live log — your window into the server.

Managing the server

From now on you control it with standard commands:

sudo systemctl stop minecraft
sudo systemctl restart minecraft

Sending commands to a systemd-managed server

One catch: with systemd you lose the interactive console. Two common solutions:

  • Run the game inside a tmux/screen session managed by systemd, so you can still attach to type commands.
  • Use the game's RCON to send commands remotely — the cleaner approach for Minecraft, Rust and others.

For Minecraft, enable RCON in server.properties (enable-rcon=true, set a port and password) and use a small RCON client to send save-all, say and other commands.

Step 3: Schedule a nightly restart

Long-running game servers gradually accumulate lag from memory fragmentation and entity buildup. A daily restart keeps performance fresh. Add a cron job as root:

0 5 * * * /usr/bin/systemctl restart minecraft

That restarts the server every day at 5 AM, when players are least likely to be online.

Step 4: Warn players before a restart

Restarting mid-session without warning is a good way to lose players. Script a warning sequence over RCON before the restart. For example, a script that announces at 5, 3 and 1 minutes, saves the world, then restarts:

rcon "say Server restarting in 5 minutes"
sleep 240
rcon "say Restarting in 60 seconds"
sleep 50
rcon "save-all"
sleep 10
systemctl restart minecraft

Point cron at this script instead of the bare restart command and players get a graceful heads-up.

Applying it to other games

The same pattern works for every game — swap the ExecStart line and working directory for Valheim, Rust, Palworld or any server binary. The self-healing benefit is universal: crash recovery, boot startup and scheduled restarts.

Watching for restart loops

One caveat with Restart=on-failure: if the server crashes instantly on startup — a bad config, a missing file, not enough memory — systemd will restart it over and over in a tight loop. Guard against this with StartLimitBurst and StartLimitIntervalSec in the [Unit] section, which stop the service after too many rapid failures so you can investigate rather than hammering a broken server. When a service goes into that state, journalctl -u minecraft shows you exactly why it's failing to boot.

Where hosting helps

systemd and cron need full root access — something locked-down managed game panels often don't give you. Nxeon's VPS provides root by default, so you can build proper self-healing services, schedule restarts and tail the journal exactly as shown here. Combined with reliable NVMe hardware, the result is a game server that quietly takes care of itself and is there whenever your players are.

Game server hosting

Deploy in seconds, not weekends

Explore Game server hosting ★★★★★ Instant deploy · full root · 24/7 support
#systemd#cron#game-servers#server-admin
NX

Nxeon · Nxeon editorial

★★★★★ Straight-talking guides from the team that runs the servers.

Game server hosting

Deploy in seconds, not weekends

Spin up a ready-to-play game server in minutes — one-click installs, DDoS protection and instant scaling.

Explore Game server hosting ★★★★★ Instant deploy · full root · 24/7 support