Hi guys I am trying to get my Minecraft server to startup with my server. I will use cron once I figure out what the proper commands are. I want Minecraft to start in a new screen titled "Minecraft" and I want to have a command sent to this session that starts the server. Every morning at 3AM I want to send the command "stop" to stop the Minecraft server and then send the command to start the server (Minecraft gets buggy if it isn't restarted every once in a while). I was playing around with the screen options and I got Minecraft to start for a few seconds and screen killed it. From what I am reading online this command should work.

screen -dmS Minecraft java -Xmx12G -Xms12G -jar /home/alan/minecraft/forge-1.16.5-36.2.30.jar --nogui

I want to reattach to this session to type commands or restart the Minecraft server because I made a change. All of the commands I ran didn't work I type "screen -ls" and my "Minecraft" session isn't there. I know how to use cron, but I clearly don't understand screen. We have frequent power outages in my area, so I have a UPS shutdown my server and a Raspberry PI turns it back on when power is restored. It would be nice to include Minecraft to my startup. After that, all of my services will start and stop automatically without my intervention.


1 Answer 1


Since you named your screen Minecraft,

# Tell Minecraft to gracefully stop.
# Ending Minecraft will terminate Java
# systemd will kill Screen after the 10-second delay. No explicit kill for Screen needed
screen -p 0 -S Minecraft -X eval 'stuff "say SERVER SHUTTING DOWN. Saving map..."\\015'
screen -p 0 -S Minecraft -X eval 'stuff "save-all"\\015'
screen -p 0 -S Minecraft -X eval 'stuff "stop"\\015'
sleep 10

It's easy to wrap your commands into a systemd service, which also gives you automatic start at boot, status monitoring, and easy start/stop/restart control using systemctl.

You generally don't need to bother leaving screen open, since all output is logged, and all server commands can be entered through the admin console.

I wrote a whole blog post about the whole process a couple years ago: It's the first section of http://cheesehead-techblog.blogspot.com/2019/08/toggling-minecraft-server-using-systemd.html

  • I clearly have a basic understanding of screen. Looks like I need to do some research. Thanks for the help! Aug 12, 2022 at 21:36
  • I tried it and it works! I just have one problem. Screen doesn't create a session titled "Minecraft". I typed "screen -ls" and there is a session labeled the same as my hostname. I can't use "screen -r hostname" I have to use the ID. How can I force it to label the session? apparently Minecraft looks for the Eula in my current directory, so that's why screen closed on me. Here's my current script. cd /home/alan/minecraft/ screen -s mc -d -m java -Xmx12G -Xms12G -jar forge-1.16.5-36.2.30.jar --nogui Aug 12, 2022 at 23:27
  • Ask yourself: screen -s mc creates a screen with what name?
    – user535733
    Aug 12, 2022 at 23:49
  • 1
    I didn't use a capital S. Ha ha I should know better! Thanks. Aug 13, 2022 at 1:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .