Running Cuberite at startup on a Raspberry Pi
#1
This guide shows you how to run Cuberite on startup in such a way that grants you access to the Cuberite console even in headless setups. It's little more than a guide about starting up Cuberite within a "tmux" terminal via /etc/rc.local. If you're familiar with tmux or GNU Screen, you probably don't need this guide.

The guide was made with Raspberry Pi in mind, but the only thing Pi-specific about it is the assumptions regarding "su/sudo" and the system users. Any other Linux system should work, assuming you know your way around your system's sudo/su/users and you tweak the guide accordingly.

tmux explained briefly
Consider this scenario:
You open a bash terminal, (Either SSH or locally), you run Cuberite, and you execute a few console commands, then you close your terminal (or close your ssh session). Without tmux, your server will stop working. With tmux, the Cuberite console will "detach" and keep running in the background. You'll be able to see it again whenever you want.

tmux allows you to run a virtual terminal that you can "attach" or "detach" from without interrupting the process running inside, this is very useful for running persistent tasks.

Installing tmux
Code:
sudo apt-get install tmux

Creating a Cuberite Linux user
For security, it's always best to run servers as non-root. Your "pi" account is effectively a "root account", so we want to run minecraft on a different user. fire up your terminal and type:
Code:
sudo adduser minecraft
Now choose a password for your newly created Linux user.
Done!

Download Cuberite
You should now login to the user "minecraft" and download Cuberite to "minecraft"'s home directory (/home/minecraft).
You can access your newly created user by executing "sudo su minecraft", or by directly logging in to "minecraft@your address" via ssh.

Starting Cuberite inside tmux
/etc/rc.local is a system script that is executed whenever your system boots.
Add this to /etc/rc.local just before the "exit 0" line:
Code:
su - minecraft -c 'tmux new -d "cd PATH && ./Cuberite" '
Replace PATH with the path to your Cuberite executable.
If you picked a different name for your user, modify the command accordingly.
Done!
Now, Cuberite will run inside tmux whenever you boot your raspberry pi.

Attaching to the console
This is the step that would have not been possible without tmux.
Your Cuberite is now running in the background, yet you can check out the console whenever you want. First, login to "minecraft" as explained above. Next, execute this:
Code:
tmux attach

Detaching from the console
Want to leave the console while keeping the server running? No problem, hit CTRL + B at the same time, then release them and quickly hit D.

That's it.
Note that this also works with Gnu Screen. But you'll need to tweak some commands accordingly.
Reply
Thanks given by: marcvangend , Francisdaumb


Messages In This Thread
Running Cuberite at startup on a Raspberry Pi - by LogicParrot - 05-11-2015, 09:35 PM



Users browsing this thread: 1 Guest(s)