0

Update:

Still having this issue. I notice that my systemd service is running both ExecStart and ExecStop commands sequentially when I run "systemctl start minecraft.service". I have verified this from the output from the tmux console and the systemd status as seen below. So it is properly calling the mc_server.sh script, but I can't get it to stop calling the "ExecStop" command. I've tried removing the Type= setting (making it simple by default), directly changing Type to simple, but none of these seem to fix the problem.

Original question:

I recently upgraded to 18.04.1 and am having trouble getting my Minecraft systemd service working again. I did a clean install of 18.04 from 16.04. This service was working properly on 16.04, but now it doesn't seem to work. When I run "systemctl start minecraft.service" it seems to run the ExecStart script and the ExecStop script together based on the status output below, but I do not see any output from the scripts in my tmux console that it should be running through. If I call the startup script manually, it works fine, so something is wrong in the systemd service.

The service is set to run as the minecraft user under minecraft group. Everything in /srv/minecraft is owned by minecraft user/group. The minecraft.service file is owned by root. All of this is the same as it was in 16.04 when it was working. Please let me know if you have any ideas to get it running again! Thanks!!

:/etc/systemd/system$ systemctl status minecraft.service
● minecraft.service - Minecraft Server
   Loaded: loaded (/etc/systemd/system/minecraft.service; enabled; vendor 
   preset
   Active: inactive (dead) since Wed 2018-11-14 16:33:25 PST; 3s ago
  Process: 4667 ExecStop=/srv/minecraft/mc_server.sh stop (code=exited, 
  status=0/SUCCESS)
  Process: 4651 ExecStart=/srv/minecraft/mc_server.sh start (code=exited, 
  status=0/SUCCESS)

Nov 14 16:33:11 systemd[1]: Starting Minecraft Server...
Nov 14 16:33:11 mc_server.sh[4651]: Session found.  Connecting.
Nov 14 16:33:11 mc_server.sh[4651]: Minecraft server successfully 
started
Nov 14 16:33:11 mc_server.sh[4667]: step 1 successs
Nov 14 16:33:19 mc_server.sh[4667]: step 2 success
Nov 14 16:33:21 mc_server.sh[4667]: server shutdown success
Nov 14 16:33:25 systemd[1]: Started Minecraft Server.

Here is the systemd script:

# Source: https://github.com/agowa338/MinecraftSystemdUnit/
# License: MIT
[Unit]
Description=Minecraft Server
After=network.target auditd.service

[Service]
WorkingDirectory=/srv/minecraft/
# PrivateUsers=true
User=minecraft
Group=minecraft
ProtectSystem=full
ProtectHome=true
# ProtectKernelTunables=true
# Implies MountFlags=slave
# ProtectKernelModules=true
# Implies NoNewPrivileges=yes
# ProtectControlGroups=true
# Implies MountAPIVFS=yes
Type=forking

ExecStart=/srv/minecraft/mc_server.sh start

ExecStop=/srv/minecraft/mc_server.sh stop

Restart=on-abnormal
RestartSec=60s

[Install]
WantedBy=multi-user.target

2 Answers 2

0

Ok, I figured it out. So here's what I did to get this service working again.

Add directive "RemainAfterExit=yes" seemed to solve the problem of the ExecStop command being run right after the startup command. This is a bit strange because in 16.04 with the same setup I didn't need the RemainAfterExit option when the Type was set to forking. But apparently now you need it?

In case anyone is having a similar issue, here is my current systemd Unit file:

# Source: https://github.com/agowa338/MinecraftSystemdUnit/
# License: MIT
[Unit]
Description=Minecraft Server
After=network.target

[Service]
User=minecraft
Group=minecraft

WorkingDirectory=~

Type=simple
RemainAfterExit=yes

PIDFile=/srv/minecraft/minecraft_process.pid

ExecStart=/srv/minecraft/mc_server.sh start

ExecStop=/srv/minecraft/mc_server.sh stop

[Install]
WantedBy=multi-user.target
0

This might not be your systemd but might be the script it is calling that is having trouble.

/srv/minecraft/mc_server.sh

Have you tried running this directly and does that work?

Normally this should work, as I did not get to see your script calling tmux, this is what it should look like.

tmux new -s my_session
run your command to start the server
tmux detach
2
  • Yes, that's what I meant by calling the startup script manually. Sorry if that was unclear. So I can run that script with the "start" option appended and it works as it should, which is to start the program in a tmux console. It's just not working when I try the systemd service. Also, I made another systemd service for a different program just to make sure I could do it (type=simple) and that one works properly. I'm thinking there may be a permission issue somewhere? Nov 19, 2018 at 20:25
  • I see your new edits. The way I do it is: 1. tmux new-session -d -s my_session 2. tmux send-keys ...etc... This works perfectly when calling the startup script directly. Nov 28, 2018 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.