[systemd-devel] dependency-only .service

Uoti Urpala uoti.urpala at pp1.inet.fi
Mon Oct 15 23:17:32 UTC 2018


On Mon, 2018-10-15 at 15:09 -0700, Johannes Ernst wrote:
> I have several programs A, B and C that, while they are running, require memcached.service to be running.
> When none of A, B, or C is running, I want memcached.service to not run either.
> A, B and C should share the same memcached instance.
> 
> How do I best express this?
> 
> I was thinking I would have a foo at .service, which would be started by A, B and C as foo at A, foo at B, and foo at C right when they come up, and stopped before they quit. This foo at .service would have a dependency on memcached.service, but otherwise not do anything.

Why this indirection through "foo" instead of direct dependencies? Are
A, B and C not systemd services, so you require "foo" as a placeholder
that reflects their dependencies?

> 1. There isn’t a Type=Noop, so having an ExecStart=/bin/true might be my best option?

I think a service with Type=oneshot and RemainAfterExit=true should
work with no ExecStart lines.


> 2. How do I get memcached.service to stop automatically? A Requires= seems to keep it running even after all foo at .service have gone away.

Add StopWhenUnneeded=true to the configuration of the memcached
service.




More information about the systemd-devel mailing list