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
#2
Thank you for sharing. Let me share my approach, just in case it helps anyone.

I have a Raspberry Pi 2B running Arch Linux ARM. Since the Pi 2 has an ARMv7 processor, I had to compile the Cuberite server myself (which turned out to be pretty easy). Once Cuberite had been compiled, I moved the compiled Server directory to /srv/cuberite because it seemed (kind of) appropriate.

Just like the OP I created a 'mincraft' Linux user and made it the owner of all Cuberite files:

Code:
$ sudo chown -R minecraft:minecraft /srv/cuberite

Arch Linux uses Systemd as init sytem, so I wanted to use that to automatically start Cuberite. That's why we need a systemd unit file like this:

Code:
[Unit]
Description=Cuberite Server
After=local-fs.target network.target

[Service]
Type=forking
User=cuberite
WorkingDirectory=/srv/cuberite
ExecStart=/srv/cuberite/Cuberite --service

[Install]
WantedBy=multi-user.target

Save this as the file /etc/systemd/system/cuberite.service. It took a while before I had figured out the correct settings, but as you can see there is no magic going on here.

Finally, test if it works my starting the service:

$ sudo systemctl start cuberite.service

You should now be able to reach the server. If it works, enable the service to make sure it is started automatically:

$ sudo systemctl enable cuberite.service

By the way, this method does not provide a way to attach to the console, or at least I haven't found it yet Cool
Enjoy!
Reply
Thanks given by: LogicParrot , sphinxc0re
#3
This is what I am seeing when I connect and use tmux.

This%25252525252520guide%25252525252520shows%25252525252520you%25252525252520how%25252525252520to%25252525252520run%25252525252520Cuberite%25252525252520on%25252525252520startup%25252525252520in%25252525252520such%25252525252520a%25252525252520way%25252525252520that%25252525252520grants%25252525252520you%25252525252520access%25252525252520to%25252525252520the%25252525252520Cuberite%25252525252520console%25252525252520even%25252525252520in%25252525252520headless%25252525252520setups.%25252525252520It%25252525252527s%25252525252520little%25252525252520more%25252525252520than%25252525252520a%25252525252520guide%25252525252520about%25252525252520starting%25252525252520up%25252525252520Cuberite%25252525252520within%25252525252520a%25252525252520%25252525252522tmux%25252525252522%25252525252520terminal%25252525252520via%25252525252520%2525252525252Fetc%2525252525252Frc.local.%25252525252520If%25252525252520you%25252525252527re%25252525252520familiar%25252525252520with%25252525252520tmux%25252525252520or%25252525252520GNU%25252525252520Screen%2525252525252C%25252525252520you%25252525252520probably%25252525252520don%25252525252527t%25252525252520need%25252525252520this%25252525252520guide.%2525252525250A%2525252525250AThe%25252525252520guide%25252525252520was%25252525252520made%25252525252520with%25252525252520Raspberry%25252525252520Pi%25252525252520in%25252525252520mind%2525252525252C%25252525252520but%25252525252520the%25252525252520only%25252525252520thing%25252525252520Pi-specific%25252525252520about%25252525252520it%25252525252520is%25252525252520the%25252525252520assumptions%25252525252520regarding%25252525252520%25252525252522su%2525252525252Fsudo%25252525252522%25252525252520and%25252525252520the%25252525252520system%25252525252520users.%25252525252520Any%25252525252520other%25252525252520Linux%25252525252520system%25252525252520should%25252525252520work%2525252525252C%25252525252520assuming%25252525252520you%25252525252520know%25252525252520your%25252525252520way%25252525252520around%25252525252520your%25252525252520system%25252525252527s%25252525252520sudo%2525252525252Fsu%2525252525252Fusers%25252525252520and%25252525252520you%25252525252520tweak%25252525252520the%25252525252520guide%25252525252520accordingly.%2525252525250A%2525252525250Atmux%25252525252520explained%25252525252520briefly%2525252525250AConsider%25252525252520this%25252525252520scenario%2525252525253A%2525252525250AYou%25252525252520open%25252525252520a%25252525252520bash%25252525252520terminal%2525252525252C%25252525252520(Either%25252525252520SSH%25252525252520or%25252525252520locally)%2525252525252C%25252525252520you%25252525252520run%25252525252520Cuberite%2525252525252C%25252525252520and%25252525252520you%25252525252520execute%25252525252520a%25252525252520few%25252525252520console%25252525252520commands%2525252525252C%25252525252520then%25252525252520you%25252525252520close%25252525252520your%25252525252520terminal%25252525252520(or%25252525252520close%25252525252520your%25252525252520ssh%25252525252520session).%25252525252520Without%25252525252520tmux%2525252525252C%25252525252520your%25252525252520server%25252525252520will%25252525252520stop%25252525252520working.%25252525252520With%25252525252520tmux%2525252525252C%25252525252520the%25252525252520Cuberite%25252525252520console%25252525252520will%25252525252520%25252525252522detach%25252525252522%25252525252520and%25252525252520keep%25252525252520running%25252525252520in%25252525252520the%25252525252520background.%25252525252520You%25252525252527ll%25252525252520be%25252525252520able%25252525252520to%25252525252520see%25252525252520it%25252525252520again%25252525252520whenever%25252525252520you%25252525252520want.%2525252525250A%2525252525250Atmux%25252525252520allows%25252525252520you%25252525252520to%25252525252520run%25252525252520a%25252525252520virtual%25252525252520terminal%25252525252520that%25252525252520you%25252525252520can%25252525252520%25252525252522attach%25252525252522%25252525252520or%25252525252520%25252525252522detach%25252525252522%25252525252520from%25252525252520without%25252525252520interrupting%25252525252520the%25252525252520process%25252525252520running%25252525252520inside%2525252525252C%25252525252520this%25252525252520is%25252525252520very%25252525252520useful%25252525252520for%25252525252520running%25252525252520persistent%25252525252520tasks.%2525252525250A%2525252525250AInstalling%25252525252520tmux%2525252525250ACode%2525252525253A%2525252525250Asudo%25252525252520apt-get%25252525252520install%25252525252520tmux%2525252525250A%2525252525250ACreating%25252525252520a%25252525252520Cuberite%25252525252520Linux%25252525252520user%2525252525250AFor%25252525252520security%2525252525252C%25252525252520it%25252525252527s%25252525252520always%25252525252520best%25252525252520to%25252525252520run%25252525252520servers%25252525252520as%25252525252520non-root.%25252525252520Your%25252525252520%25252525252522pi%25252525252522%25252525252520account%25252525252520is%25252525252520effectively%25252525252520a%25252525252520%25252525252522root%25252525252520account%25252525252522%2525252525252C%25252525252520so%25252525252520we%25252525252520want%25252525252520to%25252525252520run%25252525252520minecraft%25252525252520on%25252525252520a%25252525252520different%25252525252520user.%25252525252520fire%25252525252520up%25252525252520your%25252525252520terminal%25252525252520and%25252525252520type%2525252525253A%2525252525250ACode%2525252525253A%2525252525250Asudo%25252525252520adduser%25252525252520minecraft%2525252525250ANow%25252525252520choose%25252525252520a%25252525252520password%25252525252520for%25252525252520your%25252525252520newly%25252525252520created%25252525252520Linux%25252525252520user.%2525252525250ADone!%2525252525250A%2525252525250ADownload%25252525252520Cuberite%2525252525250AYou%25252525252520should%25252525252520now%25252525252520login%25252525252520to%25252525252520the%25252525252520user%25252525252520%25252525252522minecraft%25252525252522%25252525252520and%25252525252520download%25252525252520Cuberite%25252525252520to%25252525252520%25252525252522minecraft%25252525252522%25252525252527s%25252525252520home%25252525252520directory%25252525252520(%2525252525252Fhome%2525252525252Fminecraft).%2525252525250AYou%25252525252520can%25252525252520access%25252525252520your%25252525252520newly%25252525252520created%25252525252520user%25252525252520by%25252525252520executing%25252525252520%25252525252522sudo%25252525252520su%25252525252520minecraft%25252525252522%2525252525252C%25252525252520or%25252525252520by%25252525252520directly%25252525252520logging%25252525252520in%25252525252520to%25252525252520%25252525252522minecraft%25252525252540your%25252525252520address%25252525252522%25252525252520via%25252525252520ssh.%2525252525250A%2525252525250AStarting%25252525252520Cuberite%25252525252520inside%25252525252520tmux%2525252525250A%2525252525252Fetc%2525252525252Frc.local%25252525252520is%25252525252520a%25252525252520system%25252525252520script%25252525252520that%25252525252520is%25252525252520executed%25252525252520whenever%25252525252520your%25252525252520system%25252525252520boots.%2525252525250AAdd%25252525252520this%25252525252520to%25252525252520%2525252525252Fetc%2525252525252Frc.local%25252525252520just%25252525252520before%25252525252520the%25252525252520%25252525252522exit%252525252525200%25252525252522%25252525252520line%2525252525253A%2525252525250ACode%2525252525253A%2525252525250Asu%25252525252520-%25252525252520minecraft%25252525252520-c%25252525252520%25252525252527tmux%25252525252520new%25252525252520-d%25252525252520%25252525252522cd%25252525252520PATH%25252525252520%25252525252526%25252525252526%25252525252520.%2525252525252FCuberite%25252525252522%25252525252520%25252525252527%2525252525250AReplace%25252525252520PATH%25252525252520with%25252525252520the%25252525252520path%25252525252520to%25252525252520your%25252525252520Cuberite%25252525252520executable.%2525252525250AIf%25252525252520you%25252525252520picked%25252525252520a%25252525252520different%25252525252520name%25252525252520for%25252525252520your%25252525252520user%2525252525252C%25252525252520modify%25252525252520the%25252525252520command%25252525252520accordingly.%2525252525250ADone!%2525252525250ANow%2525252525252C%25252525252520Cuberite%25252525252520will%25252525252520run%25252525252520inside%25252525252520tmux%25252525252520whenever%25252525252520you%25252525252520boot%25252525252520your%25252525252520raspberry%25252525252520pi.%2525252525250A%2525252525250AAttaching%25252525252520to%25252525252520the%25252525252520console%2525252525250AThis%25252525252520is%25252525252520the%25252525252520step%25252525252520that%25252525252520would%25252525252520have%25252525252520not%25252525252520been%25252525252520possible%25252525252520without%25252525252520tmux.%2525252525250AYour%25252525252520Cuberite%25252525252520is%25252525252520now%25252525252520running%25252525252520in%25252525252520the%25252525252520background%2525252525252C%25252525252520yet%25252525252520you%25252525252520can%25252525252520check%25252525252520out%25252525252520the%25252525252520console%25252525252520whenever%25252525252520you%25252525252520want.%25252525252520First%2525252525252C%25252525252520login%25252525252520to%25252525252520%25252525252522minecraft%25252525252522%25252525252520as%25252525252520explained%25252525252520above.%25252525252520Next%2525252525252C%25252525252520execute%25252525252520this%2525252525253A%2525252525250ACode%2525252525253A%2525252525250Atmux%25252525252520attach%2525252525250A%2525252525250ADetaching%25252525252520from%25252525252520the%25252525252520console%2525252525250AWant%25252525252520to%25252525252520leave%25252525252520the%25252525252520console%25252525252520while%25252525252520keeping%25252525252520the%25252525252520server%25252525252520running%2525252525253F%25252525252520No%25252525252520problem%2525252525252C%25252525252520hit%25252525252520CTRL%25252525252520%2525252525252B%25252525252520B%25252525252520at%25252525252520the%25252525252520same%25252525252520time%2525252525252C%25252525252520then%25252525252520release%25252525252520them%25252525252520and%25252525252520quickly%25252525252520hit%25252525252520D.%2525252525250A%2525252525250AThat%25252525252527s%25252525252520it.%2525252525250ANote%25252525252520that%25252525252520this%25252525252520also%25252525252520works%25252525252520with%25252525252520Gnu%25252525252520Screen.%25252525252520But%25252525252520you%25252525252527ll%25252525252520need%25252525252520to%25252525252520tweak%25252525252520some%25252525252520commands%25252525252520accordingly.%25252525252520
Reply
Thanks given by:
#4
(04-20-2016, 01:53 AM)dodiaraculus17 Wrote: This is what I am seeing when I connect and use tmux.

This%25252525252520guide%25252525252520shows%25252525252520you%25252525252520how%25252525252520to%25252525252520run%25252525252520Cuberite%25252525252520on%25252525252520startup%25252525252520in%25252525252520such%25252525252520a%25252525252520way%25252525252520that%25252525252520grants%25252525252520you%25252525252520access%25252525252520to%25252525252520the%25252525252520Cuberite%25252525252520console%25252525252520even%25252525252520in%25252525252520headless%25252525252520setups.

...

"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."

...just with a lot of 25252525s than LogicParrot's post.
Reply
Thanks given by:
#5
When I urldecode this is what I get:
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:
#6
Please remove that spam!

EDIT By NiLSPACE:
Done
Reply
Thanks given by:
#7
If you use DietPi instead of the Raspbian image you will start out with an extremely minimal system.
http://dietpi.com/

Then go through the graphical menus and select Cuberite.
Click OK and you are done!
Cuberite is installed as a service and starts on boot!


I have my Pi Zero running headless on wifi so I had a couple of extra steps.
After flashing the initial image (and before the steps above) I opened the dietpi.txt and set wifi enabled and put in the wifi details and a static ip
Code:
Wifi_Enabled=1

#Enter your Wifi details below, if applicable (Case Sensitive).
Wifi_SSID=MyWifiName
Wifi_KEY=MyPassword

#Enter your Static Network details below, if applicable.
Use_Static=1
Static_IP=192.168.1.110
Static_Mask=255.255.255.0
Static_Gateway=192.168.1.2

That meant on first boot it auto-configured itself to connect to wifi and I was able to connect over ssh and do the install steps above.

Code:
ssh root@192.168.1.110 (password dietpi)
Reply
Thanks given by:




Users browsing this thread: 2 Guest(s)