Getting older, not necessarily wiser!
In the last post we had the Minecraft Server up and running. However there is one issue that needs to be resolved, and one feature that needs to be added.
Basically if you log out of the server, Minecraft stops. We will fix that by using the screen program we installed earlier. While we could do it by hand, we will write a bash script to simplify this process
And we want to start Minecraft when the server boots up. We will add that feature with a cron job.
We are going to use the terminal multiplexer we installed earlier to run minecraft server in a detached window that is not reliant on you being logged into the server.
This two line script file will create a detached screen session and launch the minecraft server in it. So fire up your favorite text editor. I saved it as startmc.sh in the mindcraft home directory.
M -Xms1024M -jar
The second line starts a new screen session in detached mode, with the command from last post running in the screen instance.
One more thing to do here, make the file executable. I used the chmod program to do this.
chmod ug+x startmc.sh
Now we can run the script to see if the server starts.
Ideally the results should be nothing as we started the server in a detached screen. Assuming this is the only instance of screen running, to attach it we use the command below and make sure server is running. Alternately try to connect.
You should be looking at a display similar to what we saw in the last post. Please remember to detach the screen before logging out. To do this use control and a then d key presses.
There is some variation between different distributions and versions of Linux on how to start a program at boot. We are going to get around theses variations by setting up a CRON Job. To start the process enter the command below.
You may be asked to chose your text editor. After that, enter the below line at the bottom of the file. Note that your script path may vary from what I used, depending on your setup.
Test the CRON job
Now perform a restart and validate the minecraft server program is running by logging into the minecraft world. You can also log back into the server and check if the it is running in a detached screen (see above).
That is it, we are done. Enjoy your Minecraft Server.
If this server will be exposed to unknown users, there are a few security things that you should attend to, like setting up a firewall. But that is beyond the scope of these posts.
Simple Debian 11 Minecraft Server – Part 3