[systemd-devel] Socket based activation/deactivation
zbyszek at in.waw.pl
Wed Aug 27 04:51:12 PDT 2014
On Wed, Aug 27, 2014 at 11:18:11AM +0200, Umut Tezduyar Lindskog wrote:
> On Wed, Aug 27, 2014 at 3:24 AM, Zbigniew Jędrzejewski-Szmek
> <zbyszek at in.waw.pl> wrote:
> > On Tue, Aug 26, 2014 at 08:49:29PM -0400, Gary Mort wrote:
> >> Socket based activation for systemd is a really cool feature for my
> >> dev system.
> >> Prior to using socket based activation, on my dev system I would
> >> have 2 choices:
> >> 1) Automatically start mysql, apache, php fastcgi, memcached,
> >> mongodb and a dozen other services just in case I happen to be
> >> working with them on this particular bootup.
> >> 2) Manually start them when needed....usually /after/ trying to test
> >> something and discovering the service isn't running.
> >> With socket based activation, I can start up dozens of servers on
> >> different sockets and they won't bog my system down - they only
> >> truely activate if they are actually used.
> >> However, there is still a missing item to this feature[or it's not
> >> missing and I am simply unaware of it] - there is no way to do the
> >> reverse. IE if apache is running on my server there is no way to
> >> configure things so if there are no active socket connections for 30
> >> minutes, have it automatically shutdown and pass the socket control
> >> back.
> > This has to be implemented in the service itself. After the service
> > has been started systemd does not monitor the socket and simply
> > does not know when the service can be safely stopped. In addition
> > to the socket passed by systemd the service might have opened
> > additional channels of communication itself, or might be doing
> > some processing that systemd knows nothing about..., so only the
> > service knows when it has idle and how long it has been idle.
> > The service can close the socket and shut down. This is race free,
> > because if a connection comes on the socket in the meantime, it will
> > be queued by the kernel, and then when the service has shut down,
> > systemd will start it again.
> > Various systemd services like systemd-hostnamed do this kind of thing
> > already.
> I really think this can be achieved with notify socket and the
> advantage would be having a system wide stop on idle value.
You mean that the daemons would notify systemd about activity and it
would keep track when to stop them? I guess possible, but I think
it would be still racy, unless the notification protol was synchronous
or it was possible for the service to "deny" the stop request sent
by systemd. All in all, I don't think the complexity is worth it,
since it is very simple for an event-loop based the service to do
on its own.
> Note: I always mixup StopWhenUnneeded=. The name makes me believe that....
More information about the systemd-devel