Minecraft server on ubuntu

Update OS & package

sudo apt update && sudo apt -y full-upgrade

Install JAVA & other package

sudo apt -y install software-properties-common tmux htop iotop nano wget curl
sudo add-apt-repository -y ppa:webupd8team/java
sudo apt update && sudo apt -y full-upgrade
sudo apt -y install oracle-java8-installer oracle-java8-set-default

Add minecraft user & login with minecraft

sudo adduser minecraft
su minecraft

Download minecraft server from https://yivesmirror.com/downloads/spigot

mkdir server
cd server
curl -L https://yivesmirror.com/files/spigot/spigot-latest.jar > minecraft_server.jar
echo "eula=true" > eula.txt

Exit to main user

exit

Add minecraft server to systemd service

sudo nano /etc/systemd/system/minecraft-server.service

With this unit

[Unit]
Description=start and stop the minecraft-server

[Service]
WorkingDirectory=/home/minecraft/server
User=minecraft
Group=minecraft
Restart=on-failure
RestartSec=20 5
Type=forking

ExecStart=/usr/bin/tmux new -s minecraft-server -d '/usr/bin/java -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSIncrementalPacing -XX:ParallelGCThreads=2 -XX:+AggressiveOpts -jar minecraft_server.jar nogui'

ExecStop=/usr/bin/tmux send-keys -t minecraft-server:0.0 'say SERVER SHUTTING DOWN. Saving map...' C-m 'save-all' C-m 'stop' C-m
ExecStop=/bin/sleep 2

[Install]
WantedBy=multi-user.target
Alias=minecraft.service

Reload daemon and allow autostart

sudo systemctl daemon-reload
sudo systemctl enable minecraft-server

Start minecraft server

systemctl start minecraft-server

Stop minecraft server

systemctl stop minecraft-server

Get minecraft server status

systemctl status minecraft-server