[QUESTION] Can't autostart Screen session with Minecraft server

Hi everyone!

Just having bought a Raspberry Pi to use as a small Minecraft Forge Server, I am delighted to say DietPi has so far worked really well. I use it in its “headless” configuration, i.e. without a screen and keyboard. Using these instructions to get the Minecraft server up and running, I’ve so far managed to get everything working - mostly. As Linux newbie one thing has alluded me altogether; I can’t get the server script to autostart when rebooting the server. If anyone can point me in the right direction, I’d be most grateful.

Here are the details:

  1. Trying to keep things as simple as possible, I’m using the dietpi-config tool to setup the autostart using the menu item “9. Autostart Option → 17. Custom script (foreground, with autologin”).
  2. When editing the autostart-script (stored as the default file name, i.e. “/var/lib/dietpi/dietpi-autostart/custom.sh”), I’m asking dietpi-config to run it as root.
  3. Here are the contents of the custom.sh script:
cd /opt/minecraft/
screen -dmS Minecraft ./run.sh

Unfortunately, when starting the server the script doesn’t launch. A “screen -ls” check reveals no deattched screen has been started, and running “ps -all” or “htop” shows no Java process (i.e. the Minecraft server) is running.

When launching the script “manually” using sudo in a ssh window (i.e. by changing directory to “/var/lib/dietpi/dietpi-autostart/”, and then typing “sudo ./custom.sh”), the script doesn’t seem to be executed at all; sudo never asks me for my password, and the bash prompt immediately re-appears. No error message is given, like the following output shows:

@foobar:~$ cd /var/lib/dietpi/dietpi-autostart/
8bitkid@foobar:/var/lib/dietpi/dietpi-autostart$ sudo ./custom.sh
8bitkid@foobar:/var/lib/dietpi/dietpi-autostart$

For anyone interested, here are the permissions for custom.sh and /opt/minecraft/run.sh:

-rwxr-xr-x 1 root root 159  1 jan 20.54 /var/lib/dietpi/dietpi-autostart/custom.sh
-rwxr-xr-x 1 root root 365  1 jan 16.00 /opt/minecraft/run.sh

Finally, this is what the Minecraft Forge server script (“run.sh”) looks like:

#!/usr/bin/env sh
# Forge requires a configured set of both JVM and program arguments.
# Add custom JVM arguments to the user_jvm_args.txt
# Add custom program arguments {such as nogui} to this file in the next line before the "$@" or
#  pass them to this script directly
java @user_jvm_args.txt @libraries/net/minecraftforge/forge/1.18.1-39.0.9/unix_args.txt "$@"

If someone here would be kind enough to review this post and tell me in what way I’ve managed to screw up, I’d very much appreciate it :slight_smile:. Thank you very much in advance!

Hi,

you could have used dietpi-software to install a Minecraft. We are offering different types.

root@DietPi4:~# dietpi-software list | grep Minec
ID 52 | =0 | Cuberite: Minecraft server with web interface (C++) | | https://dietpi.com/docs/software/gaming/#cuberite
ID 53 | =0 | MineOS: Minecraft servers with web interface (Java/Node.js) | +Java JRE +Node.js +Build-Essential +Git | https://dietpi.com/docs/software/gaming/#mineos
ID 164 | =0 | Nukkit: A nuclear-powered server for Minecraft Pocket Edition | +Java JRE | https://dietpi.com/docs/software/gaming/#nukkit
ID 181 | =0 | PaperMC: Highly optimised Minecraft server with plugins, written in Java | +Java JRE | https://dietpi.com/docs/software/gaming/#papermc
root@DietPi4:~#

https://dietpi.com/docs/software/#gaming-emulation

Hello, and thank you very much for your answer. You’re right, and I did actually browse for different Minecraft solutions. Unfortunately though, Forge - perhaps the most popular server - wasn’t on the list, which is why I opted to follow LinuxNorth.org’s Forge installation tutorial - and that’s where I’m currently stuck (on step 5, for anyone interested).

Kurtzgesagt, I can’t get Dietpi to start a server/daemon process in a Screen on system startup. Again, any help or directions is most appreciated. Thank you! :slight_smile:

Since it’s a systemd service that runs naturally in background, try it with 14 : Custom script (background, no autologin) autostart option. Ah and give your script a shebang:

#!/bin/dash
cd /opt/minecraft
exec screen -dmS Minecraft ./run.sh

I added exec to replace the originating (after cd obsolete) shell process.

And screen is actually installed?

apt install screen

Not sure whether screen is required at all when running as a service? So as an alternative to try:

#!/bin/dash
cd /opt/minecraft
exec ./run.sh

In case of the dietpi user it is not asked for a sudo password as of /etc/sudoers.d/dietpi.

Sweet Christmas! :open_mouth: That did the trick! I modified the script and changed the startup to “14: Custom script (background, no autologin” and rebooted the server, and all of the sudden the Minecraft Forge server started just as intended! Thank you very, very much!

For the record, “screen” was installed to begin with so it seems like that “exec” command did the trick - possibly also in combination with the “14: Custom script” option. And yes, I’m delighted to say that sudo screen -r Minecraft pulls up the Minecraft Forge server console on the double!

Thank you, that’s really useful to know. Being a DietPi newbie, I wish there was a physical, ring-bound manual to have on the desk for situations like these :slight_smile:.

Again, thank you very much for helping me out! I’ll mark your post as “answered”, and for anyone else looking to set up a Minecraft Forge server I’m confident this thread will be of use in the future, too!