1

I'm trying to run a minecraft server using systemd, but it's not working. Here is a simple test file with just the "execstart" and "execstop" bits replaced for simplicity.

root@Paidia:~# systemctl start test@one
root@Paidia:~# systemctl status test@one
● test@one.service - Test one
   Loaded: loaded (/etc/systemd/system/test@.service; disabled; vendor preset: enabled)
   Active: inactive (dead)

Oct 31 23:03:21 Paidia echo[398]: I started
Oct 31 23:03:21 Paidia echo[399]: I stopped
Oct 31 23:03:21 Paidia systemd[1]: Started Test one.
root@Paidia:~# cat /etc/systemd/system/test\@.service 
[Unit]
Description=Test %i

[Service]
Type=forking
ExecStart=/bin/echo "I started"
ExecStop=/bin/echo "I stopped"

[Install]
WantedBy=multi-user.target

Edit with actual code

root@Paidia:~# cat /etc/systemd/system/minecraft\@.service 
[Unit]
Description=Minecraft Server %i

[Service]
WorkingDirectory=/opt/minecraft-%i
User=minecraft
Type=forking

ExecStart=/usr/bin/screen -DmS mc-%i /bin/java -Xmx2048M -jar minecraft_server.jar nogui 

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

[Install]
WantedBy=multi-user.target
root@Paidia:~# systemctl start minecraft@survival
Job for minecraft@survival.service failed because the control process exited with error code. See "systemctl status minecraft@survival.service" and "journalctl -xe" for details.
root@Paidia:~# systemctl status minecraft@survival
● minecraft@survival.service - Minecraft Server survival
   Loaded: loaded (/etc/systemd/system/minecraft@.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2017-11-01 01:32:44 UTC; 8s ago
  Process: 422 ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval stuff "say SERVER SHUTTING DOWN. Saving map..."\015 (code=exited, status=1/FAILURE)
  Process: 420 ExecStart=/usr/bin/screen -DmS mc-%i /bin/java -Xmx2048M -jar minecraft_server.jar nogui (code=exited, status=0/SUCCESS)

Nov 01 01:32:43 Paidia systemd[1]: Starting Minecraft Server survival...
Nov 01 01:32:44 Paidia systemd[1]: minecraft@survival.service: Control process exited, code=exited status=1
Nov 01 01:32:44 Paidia systemd[1]: Failed to start Minecraft Server survival.
Nov 01 01:32:44 Paidia systemd[1]: minecraft@survival.service: Unit entered failed state.
Nov 01 01:32:44 Paidia systemd[1]: minecraft@survival.service: Failed with result 'exit-code'.
root@Paidia:~# journalctl -u minecraft@survival
-- Logs begin at Wed 2017-11-01 01:32:10 UTC, end at Wed 2017-11-01 01:32:44 UTC. --
Nov 01 01:32:43 Paidia systemd[1]: Starting Minecraft Server survival...
Nov 01 01:32:44 Paidia systemd[1]: minecraft@survival.service: Control process exited, code=exited status=1
Nov 01 01:32:44 Paidia systemd[1]: Failed to start Minecraft Server survival.
Nov 01 01:32:44 Paidia systemd[1]: minecraft@survival.service: Unit entered failed state.
Nov 01 01:32:44 Paidia systemd[1]: minecraft@survival.service: Failed with result 'exit-code'.

As you can see, it tries to execute "ExecStart" and "ExecStop" at the same time.

  • From man systemd.service: "Set Type=forking in the service's unit file to support this mode of operation. systemd will consider the service to be in the process of initialization while the original program is still running. Once it exits successfully and at least a process remains (and RemainAfterExit=no), the service is considered started." You don't have a process that remains alive after the original program (/bin/echo) exits. Your made up example doesn't satisfy Type=forking, so provide an actual example, please. – muru Nov 1 '17 at 0:57
  • I updated the post with the information you requested. However, I have tried both with type=forking and type=simple with the same result. – Eric Wolf Nov 1 '17 at 1:36
  • "Control process exited, code=exited status=1" seems to me your java process exited, causing screen to exit (since you use -D -m). Try with -d -m instead and enter the screen session to see if the java code threw any errors. – muru Nov 1 '17 at 1:46
  • Good catch! I found that my java was at /usr/bin/java and not /bin/java. Thank you. – Eric Wolf Nov 1 '17 at 1:51
0

"Control process exited, code=exited status=1" indicates that the main process started by the service exited with status 1, without any surviving forked processes. Since you used screen -Dm, that means screen exited when the command it was told to run exited. Use -dm instead to keep screen alive, then reattach it to see what happened.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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