Minecraft Server on Linux using Screen

Recently I wrote a guide on how to install a Minecraft Server on Linux, check it out if you havn’t got your own Minecraft Server yet!

This post will teach you how to, in a very simple way, make your Minecraft Server run as a daemon in the background instead of consuming a terminal and making it hard to remotely control the server.

1. What you’ll need.
First off you need to set up a Minecraft Server, SSH, FTP and java environment. After that you’ll need to download and install GNU Screen. For me Screen was somehow already installed on Ubuntu, so I didn’t have to do that, but if you need to install it I think the code is “sudo apt-get install screen”. To check if you got screen installed, type “screen -v” (displays the version, if any).

2. What is Screen?
GNU Screen is a utility that lets you run “multiple terminal windows” (excuse my very bad tech jargon here) inside a single terminal. You can see it as being able to switch through multiple full-screen applications on your desktop.

“screen” will start the software and create a virtual terminal. CTRL+A C will create a new window, CTRL+A K will kill a window and CTRL+A D will detatch the window (essentially leaving screen). To enter screen you type “screen -r”. In case you got more than one screen session you’ll get a list with the ID and name of the session, and “screen -r ID” or “screen -r NAME” will enter that session.

3. How to use Minecraft and Screen.
The easiest way to run a Minecraft Server within Screen would be to run Screen and then start the server as usual, but we can do all of this using one line of code: “screen -dmS minecraft java -Xms1024M -Xmx1024M -jar minecraft_server.jar nogui”. This will start screen in the background and name the session minecraft and then run the command. If you need superuser you can put “sudo” just before “java”.

4. Creating a script to launch the server.
Everyone who use Linux is (or should be) lazy. You see, in Windows you have to do things yourself, but in Linux you have the ability to easily automate tasks. Open up nano and type the command you use to start your server (“screen -dmS minecraft java -Xms1024M -Xmx1024M -jar minecraft_server.jar nogui”), and save the file as “minecraft.sh”. When you want to start the minecraft server you only have to type “sh minecraft.sh”. Of cource you could spend more time and make it start on boot as well, but we’ll leave it here for now.

Join the Conversation

15 Comments

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  1. I have a pocket mine server
    it launches using /pocketmine/start.sh

    Any tips on:
    1. CentOS server boots
    2. Load a screen session ( screen -S Pocketmine_Server)
    3. Then start the pocketmine server in that screen session

    Any suggestions?

  2. Thanks so much, this was very helpful.

    By the way, I had to add this to the beginning of the .sh script to get it to work:

    #!/bin/sh
    BINDIR=$(dirname “$(readlink -fn “$0″)”)
    cd “$BINDIR”

  3. Any way to detach a screen (like “ctrl+a d”) with just commands? For example, you might want to have a script running that enters the Minecraft screen, tells the server to stop the autosaving temporarily (so that you can make a full backup or something), detach the screen, do the backup, enter the screen again and turn on auto-saving.

  4. Thanks, it works great. I have the server running as a service. Occasionally, I need to see the console, issue commands, etc., so I do a screen -r. This brings the process to the foreground. Once I am done though, if I kill the terminal window, it kills the server. How do I put that session back in the background when I am finished?

  5. Thanks for answering. had allready two times to get to my server physically to get networking up again (started setting the whole server up since saturday night: 4 days). moving my only tft around back and forth; configurin dhclient and netplugd to just have it react on cable plug in and out. Somtimes i just want to push the d**n power button for inducing halt and have my minecraft go gracefully down whithout currupting the saves. I’ll beat this configuration marathon. And i will let you know when i manage to write a “daemonized” shutdown script done which may send a stop to that specific screen session and waits for the termination of that screen… yeah lets deamonize the minecraft *MWahaha* …
    at least it sounds somewhat evil ;)

  6. Hard question, Nonsensius.
    AFAIK screen doesn’t give you much “security” against system halts. It might be possible to send a signal to the app when screen detects a impending halt.. but that’s just me guessing.
    Right now Minecraft has auto-save, and if you force a full save every now and then (“screen -x SCREENNAME save-all”.. i think) you won’t lose any data.
    I’d suggest you to try it out and see what happens =). And share the result!

  7. How would one secure minecraft in the screen session from system halt?
    So it would gracefully stop if system gets accidently halted(through “pebcak”).
    Or does minecraft act allready that nicely during java session kill?
    I know backups are usefull, but i’d like to prevent some unecesary user discouragements. And ty for the nice instructions.