Systemd executando ExecStart e ExecStop ao mesmo tempo

1

Estou tentando executar um servidor de minecraft usando o systemd, mas não está funcionando. Aqui está um arquivo de teste simples com apenas os bits "execstart" e "execstop" substituídos para simplificar.

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

Edite com código real

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..."5 (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'.

Como você pode ver, ele tenta executar "ExecStart" e "ExecStop" ao mesmo tempo.

    
por Eric Wolf 01.11.2017 / 00:05

1 resposta

0

"O processo de controle foi encerrado, o código = status de saída = 1" indica que o processo principal iniciado pelo serviço foi encerrado com o status 1, sem nenhum processo bifurcado sobrevivente. Como você usou screen -Dm , isso significa que screen foi encerrado quando o comando foi instruído a ser executado. Use -dm para manter screen vivo e, em seguida, anexe-o para ver o que aconteceu.

    
por muru 01.11.2017 / 03:21