[systemd-devel] How to restart my socket activated service safely ?

Arian van Putten arian.vanputten at gmail.com
Wed Jul 28 08:14:03 UTC 2021


If your service gracefully exits and flushes buffers on SIGTERM then no
requests will be lost. (That means. Finish off processing any requests that
have been accept()'d before exiting).

Any requests you didn't accept() yet will simply queue up whilst the
service is down and you pick up where you left off after restart.

On Wed, 28 Jul 2021, 10:08 Francis Moreau, <francis.moro at gmail.com> wrote:

> On Tue, Jul 27, 2021 at 11:12 AM Mantas Mikulėnas <grawity at gmail.com>
> wrote:
> >
> > On Tue, Jul 27, 2021 at 10:10 AM Francis Moreau <francis.moro at gmail.com>
> wrote:
> > >
> > > Hello,
> > >
> > > During my application update, I want to restart my service which is
> > > activated by a socket but want to be sure that no request sent to my
> > > service will be missed. I also want to restart the socket too so
> > > systemd uses the latest version of the socket unit file.
> > >
> > > If I restart the socket when the service is still running then I get
> > > an error message: "rotor.socket: Socket service rotor.service already
> > > active, refusing."
> > >
> > > If I stop the service first and restart the socket then there's a
> > > short time frame where requests can be lost.
> >
> > The old socket has to be unbound before a new one can be put in its
> > place. Trying to keep the service alive (holding the old listener fd)
> > would just result in systemd not being able to bind a new socket with
> > the same address... (And even if that was possible, the old service
> > wouldn't be able to handle requests arriving on the new socket
> > anyway.)
> >
> > So whenever you restart a socket, there will *always* be a short time
> > frame where the old socket is closed but the new one is not yet
> > bound/listening. But as soon as the new one is listening, it'll start
> > queuing the requests even if the service isn't yet running (since it's
> > a socket-activated service after all) and the number of lost requests
> > should be minimal.
>
> Thank you for response.
>
> If the service only is restarted, will be there also requests that can be
> lost ?
>
> If the service is restarted then it's first stopped but in the
> meantime the socket unit should be listening for new requests...
>
> --
> Francis
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/systemd-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20210728/2bd38d38/attachment.htm>


More information about the systemd-devel mailing list