From your username, I'm going to assume you're trying to run a dedicated server, and will post my answer as such. This system has been battle-tested and is currently being used by a network where I am the infrastructure admin (alongside other fancy features), as well as countless other entry-level servers and production networks.
If you want a persistent auto-restarting server, you might look at creating a
systemd service for your server. You will lose your GUI and headless interface, but you'll still be able to issue commands to your server through RCON or similar.
Effectively, you'd need to create a new user (let's call it
mcserver) that will handle your server tasks:
sudo adduser --system --disabled-login --group --home /opt/mcserver
Next, you'll want to switch to this user:
sudo -u mcserver
While you're here, copy all of your game server files and whatever over.
Next, create a new script to launch your server. Do not include any relaunch logic or similar. It should be very simple:
/usr/bin/java -Xms1024M -Xmx4G -jar -XX:+UseConcMarkSweepGC -jar minecraft.jar --nojline --noconsole
Mark the file as executable using
chmod +x mcserver.sh.
exit the session for
mcserver, you won't need it anymore.
Create a new file (
sudo nano /etc/systemd/system/mcserver.sh
In this file, add the following contents:
Description=Vanilla Minecraft Server
InaccessibleDirectories=/root /sys /srv -/opt /media -/lost+found
Once you're done, you'll need to activate the service:
sudo systemctl daemon-reload
sudo systemctl enable mcserver.service
sudo systemctl start mcserver.service
The server will now auto-start on system boot, and run normally.
Note that the server will auto-restart on a failure (non-zero exit code), so
/stop will stop the server without the chance for a respawn. While you may also stop the server with
systemctl stop mcserver.service, it'll be unsafe as the server will not get to gracefully die. You can, however, use
rcon to have the aforementioned command send a graceful stop. This, however, will be left as an exercise to the reader.
Backup scrips can still be run, though it would be advisable to use a user cron-entry that ZIPs the entire folder, and stores it somewhere safe.