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
%i
is explained in the manual page forsystemd.unit
and explains what the instances are.