Start with downloading screen, which we will use later:
sudo apt-get update
sudo apt-get install screen
Now we download and install Oracle Java SDK
Copy(samba/ftp/scp) the file to osmc-user home folder, Go to console on your OSMC device(ssh), take note of the version number(folder name), it will come again later on.
sudo mkdir -p /usr/local/java
sudo cp ./jdk-8u111-linux-arm32-vfp-hflt.tar.gz /usr/local/java/
tar xvzf jdk-8u111-linux-arm32-vfp-hflt.tar.gz
sudo nano /etc/profile
On line 9, before export path, insert these lines, the version number is in the folder name:
Run these commands:
> sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.8.0_111/bin/java" 1 > sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.8.0_111/bin/javac" 1 > sudo update-alternatives --set java /usr/local/java/jdk1.8.0_111/bin/java > sudo update-alternatives --set javac /usr/local/java/jdk1.8.0_111/bin/javac > source /etc/profile
Now you got Oracle JDK in your system, now onto the server building.
Next up is to download the buildtools for the minecrafts server
mv BuildTools.jar ./minecraft/
Now comes the time consuming part, about 3 hours and 40 minutes on my pi3. In order to get enough memory to compile we need to lower gpu_mem to 16. Go into MyOSMC, chose Pi-config, GPU_mem and codec- tab lower gpu mem to 16 and reboot.
sudo systemctl stop mediacenter
java -Xms256M -Xmx640M -jar BuildTools.jar
sudo systemctl start mediacenter
After you ran BuildTools.jar you can restore gpu_mem to 256, and reboot.
So why does it take such time to install a minecraft server?
Well in our case we want a lightweight server that can load some plugins to lower server load even more and regulary free up memory, that’s why we are choseing Spigot plus a few plugins.
Spigot is a fork of Craftbukkit , wich is a fork of Bukkit, which is a spinnoff of Mojangs vanilla server. We could use the vanilla server, but it would lag terrible if we played 2-3 players and kodi playing something at the same time.
This BuildTool will download Bukkit, Craftbukkit and Spigot sources and Mojangs vanilla server. Then decompile Mojangs server, add the patches for each server. And compile them. Thats why it will take “forever”
Once the dust has settled we should move the server to a logical place:
sudo mkdir /opt/minecraft
sudo mv spigot*.jar /opt/minecraft/spigot.jar
sudo java -Xms256M -Xmx320M -jar spigot.jar nogui
Once it stared it will stop again, urging you to read the eula.txt, So edit it and change the false to true
sudo nano eula.txt
We can also at the same time edit the server properties file
sudo nano server.properties
Paste all this text under the two top lines:
spawn-protection=16 generator-settings= force-gamemode=false allow-nether=false gamemode=0 broadcast-console-to-ops=true enable-query=false player-idle-timeout=0 difficulty=1 spawn-monsters=true op-permission-level=4 announce-player-achievements=true pvp=true snooper-enabled=true level-type=DEFAULT hardcore=false enable-command-block=false max-players=8 network-compression-threshold=256 resource-pack-sha1= max-world-size=29999984 server-port=25565 debug=false texture-pack= server-ip= spawn-npcs=true allow-flight=false level-name=world view-distance=5 resource-pack= spawn-animals=true white-list=false generate-structures=true online-mode=true max-build-height=256 level-seed= enable-rcon=false motd=OSMC server, keep client renderview to 5
Now we can restart the server, and this time it will take a little bit of time since it’s creating the world. When it’s ”Done”, you should run this command:
op [your minecraft username]
(without the )
Stop the server again by writing stop in server console.
We don’t want to run the server as root user, so let’s change the file permissions on all files, recursively. I know this might be overkill but lets set it all to 777 (read, write and execute for everyone)
sudo chmod 777 * -R
Start the server again and enjoy.
java -Xms256M -Xmx320M -jar spigot.jar nogui
It’s hard to remember that long command line every time so we make a start script:
paste this into nano:
#!/bin/bash cd /opt cd minecraft java -Xms256M -Xmx320M -jar spigot.jar nogui
Save the file. And make it executable
chmod +x startMC.sh
Finally you got a server running, but as soon as you try to close your terminal the server will die, lets make it run in the background insted. To do this I use a program called screen, which we installed earlier via apt-get.
It’s time to start minecraft server running in the background. If you want to acces the server console we will do that soon. Notice this command will just give you a blank prompt, but there is magic happening in the background.
screen -dmS Minecraft /home/osmc/startMC.sh
And to enter your server console you use this command:
screen -r Minecraft
Voila, there you have your running server, before you close your ssh client you must detach your ”minecraftserver screen”. Press CTRL+a then d, this will return you to a normal promp and the minecraft server is still running in the background and you can close your ssh session.
Here is how you make minecraft server start when your pi starts. First we make a scripts dir where we put out scripts and then a script that starts minecraft in the background…
sudo mkdir /opt/scripts
sudo mv /home/osmc/startMC.sh /opt/scripts/
sudo nano /opt/scripts/minecraftstarter.sh
#!/bin/bash screen -dmS Minecraft /opt/scripts/startMC.sh exit
Then we make a script to stop the the server and close the background screen.
sudo nano /opt/scripts/minecraftstopper.sh
#!/bin/bash screen -S Minecraft -p 0 -X stuff "stop$(printf \\r)" exit
Lets make sure all scripts are executable:
sudo chmod +x /opt/scripts/minecraftstarter.sh
sudo chmod +x /opt/scripts/minecraftstopper.sh
sudo chmod +x /opt/scripts/startMC.sh
Create a service file that calls on our minecraftstarter.sh and minecraftstopper.sh.
sudo nano /etc/systemd/system/minecraft.service
[Unit] Description = Minecraftserver After = remote-fs.target network-online.target mediacenter.service [Service] Type=oneshot RemainAfterExit=yes User=osmc ExecStart = /opt/scripts/minecraftstarter.sh ExecStop = /opt/scripts/minecraftstopper.sh TimeoutStopSec=20 [Install] WantedBy = multi-user.target
That should be it, now we just enable and start the server
sudo systemctl enable minecraft
sudo systemctl start minecraft