Discussion:
dependency-only .service
(too old to reply)
Johannes Ernst
2018-10-15 22:09:40 UTC
Permalink
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 ***@.service, which would be started by A, B and C as ***@A, ***@B, and ***@C right when they come up, and stopped before they quit. This ***@.service would have a dependency on memcached.service, but otherwise not do anything.

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

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

Is there a better way of doing this?

Thanks,



Johannes.
Reindl Harald
2018-10-15 22:47:06 UTC
Permalink
Post by Johannes Ernst
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?
https://www.freedesktop.org/software/systemd/man/systemd.target.html
Uoti Urpala
2018-10-15 23:23:38 UTC
Permalink
Post by Reindl Harald
Post by Johannes Ernst
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?
https://www.freedesktop.org/software/systemd/man/systemd.target.html
I don't think there is any obvious way to solve this just by defining a
target.
Uoti Urpala
2018-10-15 23:17:32 UTC
Permalink
Post by Johannes Ernst
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?
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?
Post by Johannes Ernst
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.
Add StopWhenUnneeded=true to the configuration of the memcached
service.
Johannes Ernst
2018-10-15 23:49:22 UTC
Permalink
Post by Uoti Urpala
Post by Johannes Ernst
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?
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?
Yes, they are something else than a systemd service, in my example simply long-running batch programs.
Post by Uoti Urpala
Post by Johannes Ernst
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.
"Service lacks both ExecStart= and ExecStop= setting. Refusing.”

That presumably could be a .target but having a dummy exec is fine.
Post by Uoti Urpala
Add StopWhenUnneeded=true to the configuration of the memcached
service.
Ah. There’s always one more keyword somewhere :-)

Thank you,


Johannes.

Continue reading on narkive:
Loading...