0

I'm trying to get a local Minecraft server going, and while there's a million and 2 tutorials out there, I'm trying to take it a step further than the scope of said tutorials and learn at the same time.

I found one tutorial that places a systemd .service file to start it on boot. Cool. Then, I found another that uses screen, which will help me immensely as I now have console access to it. And that's where I'm having trouble.

I created the forge-server.service file in the parent directory of the Forge server (allows mods, in case you didn't know), then I used "ln" to drop a link into /etc/systemd/system. And, it fails to load.

I get code=exited status=1 and a fail to start. I don't know what is going on. Half way down, I get no screen session found. Then, it just fails.

[Unit]
Description=Forge Server %i

[Service]
WorkingDirectory=/home/<USER>/minecraft/forge-server/%i
User=<USER>
Group=<USER>
Restart=always

ExecStart=/usr/bin/screen -DmS mc-%i /usr/bin/java -Xmx1536M -jar forge*.jar nogui

ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "say SERVER SHUTTING DOWN. Saving map..."15'
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "save-all"15'
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "stop"15'
ExecStop=/bin/sleep 2

[Install]
WantedBy=multi-user.target

If I don't specify the working directory as such, I get CHDIR200.

If I execute the Forge*.jar in my SSH/screen session, it works just fine. Can you please advise me where I went wrong and how to possibly fix this script?

EDIT: I figured it out. This is my new .service file;

#!/bin/sh -

[Unit]
Description=Forge Server

[Service]
WorkingDirectory=/home/<USER>/minecraft/forge-server/
User=<USER>
Group=<USER>
Restart=on-failure

ExecStart=/usr/bin/screen -DmS forge /usr/bin/java -Xmx1536M -jar forge-1.10.2-12.18.2.2099-universal.jar nogui

ExecStop=/usr/bin/screen -p 0 -S forge -X eval 'stuff "say SERVER SHUTTING DOWN. Saving map..."15'
ExecStop=/usr/bin/screen -p 0 -S forge -X eval 'stuff "save-all"15'
ExecStop=/usr/bin/screen -p 0 -S forge -X eval 'stuff "stop"15'
ExecStop=/bin/sleep 2

[Install]
WantedBy=multi-user.target
6
  • I changed the %i to absolutes. I removed it from the Description, WorkingDirectory, and ExecStart fields. I now have status=203. Do I need to add +x via chmod to my forge*.jar? Let's find out. That didn't work.
    – afr33sl4ve
    Nov 23, 2016 at 18:00
  • Figured it out, will place new file in top level.
    – afr33sl4ve
    Nov 23, 2016 at 18:10
  • Do not edit the solution to the question. There is field for answer below. Explaining what was wrong is also good idea to help others with similar problems.
    – Jakuje
    Nov 23, 2016 at 18:38
  • Seeing as I don't know what the %i variable did (just copied and pasted from another script), I cannot explain what exactly broke the script. Also, thank you for the answer field. Did not know that existed.
    – afr33sl4ve
    Nov 23, 2016 at 19:02
  • %i is explained in the manual page for systemd.unit and explains what the instances are.
    – Jakuje
    Nov 23, 2016 at 19:04

1 Answer 1

1

I figured it out. This is my new .service file;

#!/bin/sh -

[Unit]
Description=Forge Server

[Service]
WorkingDirectory=/home/<USER>/minecraft/forge-server/
User=<USER>
Group=<USER>
Restart=on-failure

ExecStart=/usr/bin/screen -DmS forge /usr/bin/java -Xmx1536M -jar forge-1.10.2-12.18.2.2099-universal.jar nogui

ExecStop=/usr/bin/screen -p 0 -S forge -X eval 'stuff "say SERVER SHUTTING DOWN. Saving map..."15'
ExecStop=/usr/bin/screen -p 0 -S forge -X eval 'stuff "save-all"15'
ExecStop=/usr/bin/screen -p 0 -S forge -X eval 'stuff "stop"15'
ExecStop=/bin/sleep 2

[Install]
WantedBy=multi-user.target

I had set the forge jar file as executable (chmod +x) and removed all the variables (%i from the initial script I copied). It now works and launches in a screen instance at boot.

You must log in to answer this question.

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