0

Is/should "Restart=always" be honoured when "systemctl stop docker.service" is excuted?

My understanding (which is limited) is that systemctl stop should stop with an Exit Code of 0. I then expect the docker.service to retstart as "Restart=always" is configured i.e should restart it no matter what the exit code is, but this does not seem to happen.

Is systemctl stop a special case and if so how do I test "Restart=always" is working by getting dockerd to exit with a status code of 0?

0

2 Answers 2

1

Thank you for your comments greatly appreciated. Fiddling around with the above (best description of it based on my lack of knowledge) this is what I believe the behaviour is:

  • The Eval/gdp script above seems to work on docker.service. It causes the dockerd process to exit and it is restarted. There is no message written to /var/log/messages to say the the processes exited with status Zero. If I change the scirpt to use exit status 1 this is written to messages log file as status=1 and the service is also restarted
  • SIGTERM also causes docker.service to stop, no exit code status to be written to /var/log/messages and the process to be restarted
  • systemctl stop docker.service causes the process to stop and it is not restarted
  • systemctl stop systemd-udevd causes the process to stop and it is not restarted i.e. its like a SIGSTOP

The last point would seem to suggest that the STOP command does not honour restart=always by design.

0

No. Yes. And I'm not sure.

For a program which is linked against libc, like udev:

eval $(systemctl show -p MainPID systemd-udevd)
gdb -p $MainPID
p (void)_exit(0)
quit

However Docker is written in go, which is unusually unfriendly to calling C functions (and maybe uses it's own syscall implementations?). So I do not know if this would work on dockerd.

If you just want to double-check that Restart=always works how you think it does, systemd-udevd.service already uses Restart=always. So you can demonstrate Restart=always using the above. It worked for me :-).

4
  • 1
    The usual way of checking automatic restarts, at least from long practice in the daemontools world, is to send the service a TERM signal with svc -t or similar.
    – JdeBP
    Mar 16, 2019 at 0:40
  • @JdeBP ah, that's a really good point that I did not address. I think I was imagining the process would not exit with 0 in that case. I suppose it can depend whether the process has any need to handle SIGTERM explicitly. If not, it might not register any signal handler, and then you would see an abnormal exit (WIFSIGNALED).
    – sourcejedi
    Mar 16, 2019 at 0:48
  • … which does not affect always restarts.
    – JdeBP
    Mar 16, 2019 at 9:31
  • @JdeBP 'how do I test "Restart=always" is working by getting dockerd to exit with a status code of 0'.
    – sourcejedi
    Mar 16, 2019 at 11:02

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.