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
● [email protected] - Test one
Loaded: loaded (/etc/systemd/system/[email protected]; 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 [email protected] failed because the control process exited with error code. See "systemctl status [email protected]" and "journalctl -xe" for details.
root@Paidia:~# systemctl status minecraft@survival
● [email protected] - Minecraft Server survival
Loaded: loaded (/etc/systemd/system/[email protected]; 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]: [email protected]: 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]: [email protected]: Unit entered failed state.
Nov 01 01:32:44 Paidia systemd[1]: [email protected]: 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]: [email protected]: 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]: [email protected]: Unit entered failed state.
Nov 01 01:32:44 Paidia systemd[1]: [email protected]: Failed with result 'exit-code'.
As you can see, it tries to execute "ExecStart" and "ExecStop" at the same time.
"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 meansscreen
exited when the command it was told to run exited. Use-dm
instead to keepscreen
alive, then reattach it to see what happened.I had a similar problem, and found that screen was masking the error code from Java. When I ran this by itself: /bin/java -Xmx2048M -jar minecraft_server.jar nogui I got an error that minecraft was compiled by a more recent version of Java Runtime than was installed on my system (60 vs 55)