Systemd ignora RestartSec = 15s

4

Eu tenho este serviço:

[Unit]
Description=TimeAgent Recorder
Requires=timeagent.service

[Service]
User=deployer
Group=sudo
WorkingDirectory=/home/deployer/timeagent
Environment=HOME=/home/deployer
Environment=RAILS_ENV=production
Environment=EYE_CLIENT_TIMEOUT=120
Restart=always
RestartSec=15
Nice=1

Type=forking
PIDFile=/home/deployer/.eye/pid
ExecStart=/usr/local/bin/bundle exec eye load recorder.eye
ExecStop=/usr/local/bin/bundle exec eye quit --stop-all -t 600

[Install]
WantedBy=timeagent.service

Na reinicialização, às vezes, não é iniciado:

$ systemctl status timeagent-recorder
● timeagent-recorder.service - TimeAgent Recorder
   Loaded: loaded (/etc/systemd/system/timeagent-recorder.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Mon 2017-03-20 16:30:17 GMT; 42min ago
  Process: 10929 ExecStop=/usr/local/bin/bundle exec eye quit --stop-all -t 600 (code=exited, status=0/SUCCESS)
  Process: 11409 ExecStart=/usr/local/bin/bundle exec eye load recorder.eye (code=killed, signal=TERM)
 Main PID: 9236 (code=killed, signal=TERM)

Mar 20 16:30:16 Ti systemd[1]: Starting TimeAgent Recorder...
Mar 20 16:30:17 Ti systemd[1]: Stopped TimeAgent Recorder.
Mar 20 16:30:17 Ti systemd[1]: timeagent-recorder.service: Start request repeated too quickly.
Mar 20 16:30:17 Ti systemd[1]: Failed to start TimeAgent Recorder.
Mar 20 16:30:20 Ti systemd[1]: Stopped TimeAgent Recorder.
Mar 20 16:30:20 Ti systemd[1]: timeagent-recorder.service: Start request repeated too quickly.
Mar 20 16:30:20 Ti systemd[1]: Failed to start TimeAgent Recorder.
Mar 20 16:30:20 Ti systemd[1]: Stopped TimeAgent Recorder.
Mar 20 16:30:20 Ti systemd[1]: timeagent-recorder.service: Start request repeated too quickly.
Mar 20 16:30:20 Ti systemd[1]: Failed to start TimeAgent Recorder.

Aqui está também a saída relevante:

$ systemctl show timeagent-recorder | grep -i restart
Restart=always
RestartUSec=15s

Assegurei-me de ativar o serviço, assim como o daemon-reload, como você pode ver acima, ele está ativado e o systemd tenta iniciá-lo, mas ignora completamente o RestartSec.

Estou no Ubuntu 16.04.1 LTS com a versão systemd 229-4ubuntu10.

Alguma idéia porque o RestartSec = 15 não está sendo honrado? - Eu também tentei usar RestartSec = 15s, o que também não fez diferença.

EDITAR:

Eu mudei Requer Quer como sugerido e o problema ainda está acontecendo. Aqui está o log relavant que mostra um pouco mais o que está acontecendo:

# journalctl -f -u timeagent-recorder
Mar 26 20:18:21 Ti bundle[7030]: Config loaded!
Mar 26 20:18:21 Ti systemd[1]: Started TimeAgent Recorder.
Mar 26 22:17:06 Ti systemd[1]: Stopping TimeAgent Recorder...
Mar 26 22:17:08 Ti bundle[22989]: Eye quit ಠ╭╮ಠ (/home/deployer)
Mar 26 22:17:08 Ti systemd[1]: Stopped TimeAgent Recorder.
Mar 26 22:17:08 Ti systemd[1]: Starting TimeAgent Recorder...
Mar 26 22:17:09 Ti bundle[23272]: Eye started! ㋡ (/home/deployer)
Mar 26 22:17:09 Ti systemd[1]: Stopped TimeAgent Recorder.
Mar 26 22:17:09 Ti systemd[1]: Starting TimeAgent Recorder...
Mar 26 22:17:09 Ti systemd[1]: timeagent-recorder.service: Control process exited, code=exited status=1
Mar 26 22:17:09 Ti systemd[1]: Stopped TimeAgent Recorder.
Mar 26 22:17:09 Ti systemd[1]: timeagent-recorder.service: Unit entered failed state.
Mar 26 22:17:09 Ti systemd[1]: timeagent-recorder.service: Failed with result 'exit-code'.
Mar 26 22:17:09 Ti systemd[1]: Starting TimeAgent Recorder...
Mar 26 22:17:09 Ti systemd[1]: Stopped TimeAgent Recorder.
Mar 26 22:17:09 Ti systemd[1]: Starting TimeAgent Recorder...
Mar 26 22:17:10 Ti systemd[1]: Stopped TimeAgent Recorder.
Mar 26 22:17:10 Ti systemd[1]: Starting TimeAgent Recorder...
Mar 26 22:17:10 Ti systemd[1]: Stopped TimeAgent Recorder.
Mar 26 22:17:10 Ti systemd[1]: timeagent-recorder.service: Start request repeated too quickly.
Mar 26 22:17:10 Ti systemd[1]: Failed to start TimeAgent Recorder.
Mar 26 22:17:10 Ti systemd[1]: Stopped TimeAgent Recorder.
Mar 26 22:17:10 Ti systemd[1]: timeagent-recorder.service: Start request repeated too quickly.
Mar 26 22:17:10 Ti systemd[1]: Failed to start TimeAgent Recorder.
    
por Roman Gaufman 20.03.2017 / 18:18

1 resposta

2

Eu acredito que o comportamento que você está enfrentando é devido à sua Requires= de dependência. De acordo com a seção sobre Requires= de man systemd.unit :

If one of the other units gets deactivated or its activation fails, this unit will be deactivated.

Parece que é isso que acontece aqui. Mais adiante no parágrafo, há este conselho, que eu acho que se aplica neste caso:

Often, it is a better choice to use Wants= instead of Requires= in order to achieve a system that is more robust when dealing with failing services.

A documentação para Wants= diz:

A weaker version of Requires=. Units listed in this option will be started if the configuring unit is. However, if the listed units fail to start or cannot be added to the transaction, this has no impact on the validity of the transaction as a whole. This is the recommended way to hook start-up of one unit to the start-up of another unit.

Para responder de outra forma: não acho que a lógica "RequireSec=" esteja recebendo uma chance de entrar, porque o systemd está desativando o serviço porque a condição "Require=" não foi atendida.

Esse é o meu palpite.

    
por 21.03.2017 / 18:29