Minecraft server on Ubuntu with systemd
From the minecraft-server-properly dept. (9207) (0) by Luis
In this previous article, I described how to setup Minecraft with Ubuntu versions previous to 15.04, which by default allowed you to run upstart in user mode to start services and respawn as necessary. Refer to wiki SystemdForUpstartUsers if you want to get a better understanding on how systemd differs from upstart and ArchLinux wiki if you would like to get information on how systemd --user works.
In this article, we'll create the service using the newer systemd, which is now the de-facto system service (/sbin/init with process ID 1) on many Linux distributions and for Ubuntu it starts in version 15.04 (to be released in 2015-04, i.e. April). Please be sure to review the first article as you will need to do some steps from that first.
To recap from the upstart article on how to setup Ubuntu, you needed to do:
- Ubuntu Gnome Desktop 15.04
- Minecraft Server 1.7.x or latest
- Oracle Java 1.7.x get the Java tarball for Linux
After you've downloaded the necessary items, follow these simple steps:
- You'll need to create a Debian package for Oracle's Java by doing the following from Gnome Terminal:
1 2 3 4 5 |
sudo apt-get install java-package # installs Java packager cd ~/Downloads # goes to the directory where you downloaded Java tarball make-jpkg jre-7u60-linux-x64.tar.gz # create .deb package sudo dpkg -i oracle-java7-jre_7u60_amd64.deb # installs Java java -version # verifies current version. Be sure this returns a string like java version "1.7.0_60" |
- Create a user account "familia" and set it to automatically login to its desktop (Gnome -> Users. Create user and select to auto-login). Or you may use
sudo adduser familia
from the Gnome Terminal and then switch to this user account to continue setup - Create a directory
~familia/Minecraft
and copy the minecraft server .jar into this directory:mkdir ~familia/Minecraft
- Create a file
~familia/.config/systemd/user/minecraft.service
with the following content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
cat > ~familia/.config/systemd/user/minecraft.service <<-EOF [Unit] Description="Minecraft server on port 25565" # author "Luis Mondesi <lemsx1@gmail.com>" After=network.target [Service] DefaultEnvironment=DISPLAY=:0 Restart=on-failure ExecStart=${XDG_CACHE_HOME:-$HOME}/Minecraft/minecraft_server [Install] WantedBy=default.target EOF |
- Then enable the service with:
systemctl --user enable minecraft.service
- You may optionally create the following text files:
touch ~familia/Minecraft/{ops.txt,white-list.txt}
- You will also need to agree to the end-user license by editing the eula.txt file with
eula=true
At this point your server installation is setup. All we need is the wrapper scripts to allow easy access to the service:
- Create a wrapper script for the minecraft_server.jar:
1 2 3 4 5 6 7 8 9 |
cd ~familia/Minecraft ln -sf minecraft_server.1.7.10.jar minecraft_server.jar cat > minecraft_server <<-EOF #!/bin/bash cd /home/familia/Minecraft && \ # append "nogui" if you want to run it from the terminal without a GUI java -Xmx1024M -Xms1024M -jar minecraft_server.jar 2>&1 |zenity --timeout=90 --text-info - cd - EOF |
- Make the script executable:
chmod a+rx minecraft_server
- Create a .desktop file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
cat > MinecraftServer.desktop <<-EOF # Minecraft [Desktop Entry] Version=1.0 Name=Minecraft Server Name[es]=Servidor de Minecraft Comment=Serve Minecraft Comment[es]=Sirve Minecraft GenericName=Minecraft Server Keywords=Internet;Game;Minecraft Exec=/home/familia/Minecraft/minecraft_server Terminal=false X-MultipleArgs=false Type=Application Icon=/home/familia/Minecraft/mc.png #Categories=GNOME;GTK;Network;WebBrowser; StartupNotify=false #Actions=NewWindow;NewPrivateWindow; EOF |
- Be sure to download a nifty icon for your .desktop file and call it mc.png. Example Minecraft icon
- Make the .desktop file executable:
chmod a+rx MinecraftServer.desktop
- Make a link to the desktop with:
ln -s ~familia/Minecraft/MinecraftServer.desktop ~/Desktop/
In order to start the service, you will need to execute
1 |
systemctl --user start minecraft.service |