I have an HTTP service (let's call it Foo) with systemd socket activation. I would like to support this setup:

  1. monitoring service tells Foo to stop (e.g. POST /stop)
  2. Foo finishes it's (potentially long) work then exits.
  3. monitoring service polls an HTTP endpoint on Foo (e.g. GET /are-you-up) waiting for it to exit.

At step 3 when the monitoring service hits /are-you-up, systemd's socket activation restarts the HTTP service!

I'd still like systemd to manage the socket (so that my service doesn't have to run/start as root). I'd also still like systemd to restart my service if it crashes (non-0 exit code).

Are either of these possible?

  • systemd manages the socket but doesn't do socket activation?
  • OR Foo service on shutdown tells systemd to close the socket / stop responding to it. I tried having the service run 'systemctl stop foo.socket' but it runs as an unprivileged user.

The big picture is that the service is being replaced. After it shuts down the (cloud) server will be deleted.

  • Why must your service start as root if you don't use socket activation? Why doesn't your monitoring service ask systemd when the service has stopped? – Michael Hampton Feb 1 at 3:33
  • root (or capabilities) because it listens on port 443. How would the remote monitoring system talk to systemd? – Graham King Feb 1 at 17:17
  • This is not a good use case for socket activation. You should instead configure your web server to drop privileges, like every other web server does. You could also run it on an unprivileged port with a standard web server in front of it, which is possibly a better idea. – Michael Hampton Feb 1 at 17:56

Your Answer

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

Browse other questions tagged or ask your own question.