Discussion:
Create a target unit to start & stop a group of services
(too old to reply)
林自均
2018-02-26 09:24:01 UTC
Permalink
Raw Message
Hi folks,

I would like to create a target unit to start and stop a group of services.
For example, I want a "my-apps.target" to start and stop "docker.service",
"sshd.service" and "mongodb.service". Here are my units and drop-ins:

# /etc/systemd/system/my-apps.target
[Unit]
Wants=docker.service sshd.service mongodb.service # for starting

# /etc/systemd/system/docker.service.d/my-apps.conf
[Unit]
PartOf=my-apps.target # for stopping

And the drop-ins for "sshd.service" and "mongodb.service" are similar.

Then I can use "systemctl start my-apps.target" and "systemctl stop
my-apps.target" to start and stop the 3 services.

However, it is a little bit tedious to write drop-ins for each service
units. Is there a directive for "my-apps.target" to propagate "stop"
operation to the 3 services? I was expecting something like
"PropagateStopTo=docker.service sshd.service mongodb.service".

Thanks!

John Lin
Michal Sekletar
2018-02-26 10:08:50 UTC
Permalink
Raw Message
Post by 林自均
However, it is a little bit tedious to write drop-ins for each service
units. Is there a directive for "my-apps.target" to propagate "stop"
operation to the 3 services? I was expecting something like
"PropagateStopTo=docker.service sshd.service mongodb.service".
I agree that preparation steps are tedious for your scenario, but this
is because the original use-case behind PartOf was a bit different. We
needed a way to stop a group of services at the same time. Think about
foo.target and then imagine a lot of instances of ***@.service which
all have PartOf=foo.target (because of configuration in the template
unit file). Previously you couldn't really stop the instances with a
single command.

Unfortunately, we don't have a dependency (AFAIK) that only propagates
stop actions.

Michal
Michal Koutný
2018-02-26 11:28:45 UTC
Permalink
Raw Message
Post by Michal Sekletar
Unfortunately, we don't have a dependency (AFAIK) that only propagates
stop actions.
FTR (not helpful for the original problem), there exists ConsistsOf= as
an inverse of PartOf= dependency. However, it's read only currently (or
strictly speaking, writable through the PartOf= endpoint).

Michal
林自均
2018-02-27 01:49:09 UTC
Permalink
Raw Message
Hi both Michal,

Thank you for the quick responses! I think I will keep on using the tedious
PartOf= directive.

However, may I ask why ConsistsOf= is readonly? If I can use it in my
"my-apps.target", that would be great.

John Lin
Post by Michal Koutný
Post by Michal Sekletar
Unfortunately, we don't have a dependency (AFAIK) that only propagates
stop actions.
FTR (not helpful for the original problem), there exists ConsistsOf= as
an inverse of PartOf= dependency. However, it's read only currently (or
strictly speaking, writable through the PartOf= endpoint).
Michal
_______________________________________________
systemd-devel mailing list
https://lists.freedesktop.org/mailman/listinfo/systemd-devel
Jérémy Rosen
2018-02-27 08:34:18 UTC
Permalink
Raw Message
Post by 林自均
Hi both Michal,
Thank you for the quick responses! I think I will keep on using the tedious
PartOf= directive.
However, may I ask why ConsistsOf= is readonly? If I can use it in my
"my-apps.target", that would be great.
Because "ConsistsOf" doesn't exist in the way you think it does...

Every relation between units (Wants, Before, PartOf) needs to have an
internal, reverse relation for accounting purpose

That reverse relation is usually an internal detail, but it is handy to
expose
it in "systemctl show" & co.

So that's what you see, an internal property exposed for ease-of-use. not an
external, user configurable property
Post by 林自均
John Lin
Post by Michal Koutný
Post by Michal Sekletar
Unfortunately, we don't have a dependency (AFAIK) that only propagates
stop actions.
FTR (not helpful for the original problem), there exists ConsistsOf= as
an inverse of PartOf= dependency. However, it's read only currently (or
strictly speaking, writable through the PartOf= endpoint).
Michal
_______________________________________________
systemd-devel mailing list
https://lists.freedesktop.org/mailman/listinfo/systemd-devel
_______________________________________________
systemd-devel mailing list
https://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
SMILE <http://www.smile.eu/>

20 rue des Jardins
92600 AsniÚres-sur-Seine


*Jérémy ROSEN*
Architecte technique
Responsable de l'expertise Smile-ECS

email ***@smile.fr <mailto:***@smile.fr>
phone +33141402967
url http://www.smile.eu

Twitter <https://twitter.com/GroupeSmile> Facebook
<https://www.facebook.com/smileopensource> LinkedIn
<https://www.linkedin.com/company/smile> Github
<https://github.com/Smile-SA>


Découvrez l’univers Smile, rendez-vous sur smile.eu
<http://smile.eu/?utm_source=signature&utm_medium=email&utm_campaign=signature>

eco Pour la planÚte, n'imprimez ce mail que si c'est nécessaire
林自均
2018-02-27 10:20:37 UTC
Permalink
Raw Message
Hi Jérémy,

Thank you, but I read the section "Mapping of unit properties to their
inverses" in the man page
https://www.freedesktop.org/software/systemd/man/systemd.unit.html and then
found out the PropagatesReloadTo= and ReloadPropagatedFrom= are inverses to
each other and both can be configured in a unit file. I was wondering why
PartOf= and ConsistsOf= are not the case. Thank you.

John Lin
Post by 林自均
Hi both Michal,
Thank you for the quick responses! I think I will keep on using the tedious
PartOf= directive.
However, may I ask why ConsistsOf= is readonly? If I can use it in my
"my-apps.target", that would be great.
Because "ConsistsOf" doesn't exist in the way you think it does...
Every relation between units (Wants, Before, PartOf) needs to have an
internal, reverse relation for accounting purpose
That reverse relation is usually an internal detail, but it is handy to
expose
it in "systemctl show" & co.
So that's what you see, an internal property exposed for ease-of-use. not an
external, user configurable property
John Lin
Unfortunately, we don't have a dependency (AFAIK) that only propagates
stop actions.
FTR (not helpful for the original problem), there exists ConsistsOf= as
an inverse of PartOf= dependency. However, it's read only currently (or
strictly speaking, writable through the PartOf= endpoint).
Michal
_______________________________________________
_______________________________________________
--
[image: SMILE] <http://www.smile.eu/>
20 rue des Jardins
92600 AsniÚres-sur-Seine
*Jérémy ROSEN*
Architecte technique
Responsable de l'expertise Smile-ECS
[image: phone] +33141402967 <+33%201%2041%2040%2029%2067>
[image: url] http://www.smile.eu
[image: Twitter] <https://twitter.com/GroupeSmile> [image: Facebook]
<https://www.facebook.com/smileopensource> [image: LinkedIn]
<https://www.linkedin.com/company/smile> [image: Github]
<https://github.com/Smile-SA>
[image: Découvrez l’univers Smile, rendez-vous sur smile.eu]
<http://smile.eu/?utm_source=signature&utm_medium=email&utm_campaign=signature>
[image: eco] Pour la planÚte, n'imprimez ce mail que si c'est nécessaire
_______________________________________________
systemd-devel mailing list
https://lists.freedesktop.org/mailman/listinfo/systemd-devel
林自均
2018-03-06 03:07:30 UTC
Permalink
Raw Message
Anyone?

John Lin
Post by 林自均
Hi Jérémy,
Thank you, but I read the section "Mapping of unit properties to their
inverses" in the man page
https://www.freedesktop.org/software/systemd/man/systemd.unit.html and
then found out the PropagatesReloadTo= and ReloadPropagatedFrom= are
inverses to each other and both can be configured in a unit file. I was
wondering why PartOf= and ConsistsOf= are not the case. Thank you.
John Lin
Post by 林自均
Hi both Michal,
Thank you for the quick responses! I think I will keep on using the tedious
PartOf= directive.
However, may I ask why ConsistsOf= is readonly? If I can use it in my
"my-apps.target", that would be great.
Because "ConsistsOf" doesn't exist in the way you think it does...
Every relation between units (Wants, Before, PartOf) needs to have an
internal, reverse relation for accounting purpose
That reverse relation is usually an internal detail, but it is handy to
expose
it in "systemctl show" & co.
So that's what you see, an internal property exposed for ease-of-use. not an
external, user configurable property
John Lin
Unfortunately, we don't have a dependency (AFAIK) that only propagates
stop actions.
FTR (not helpful for the original problem), there exists ConsistsOf= as
an inverse of PartOf= dependency. However, it's read only currently (or
strictly speaking, writable through the PartOf= endpoint).
Michal
_______________________________________________
_______________________________________________
--
[image: SMILE] <http://www.smile.eu/>
20 rue des Jardins
92600 AsniÚres-sur-Seine
*Jérémy ROSEN*
Architecte technique
Responsable de l'expertise Smile-ECS
[image: phone] +33141402967 <+33%201%2041%2040%2029%2067>
[image: url] http://www.smile.eu
[image: Twitter] <https://twitter.com/GroupeSmile> [image: Facebook]
<https://www.facebook.com/smileopensource> [image: LinkedIn]
<https://www.linkedin.com/company/smile> [image: Github]
<https://github.com/Smile-SA>
[image: Découvrez l’univers Smile, rendez-vous sur smile.eu]
<http://smile.eu/?utm_source=signature&utm_medium=email&utm_campaign=signature>
[image: eco] Pour la planÚte, n'imprimez ce mail que si c'est nécessaire
_______________________________________________
systemd-devel mailing list
https://lists.freedesktop.org/mailman/listinfo/systemd-devel
Zbigniew Jędrzejewski-Szmek
2018-03-07 12:47:26 UTC
Permalink
Raw Message
Post by 林自均
Anyone?
John Lin
Hi Jérémy,
Thank you, but I read the section "Mapping of unit properties to their
inverses" in the man page
https://www.freedesktop.org/software/systemd/man/systemd.unit.html and
then found out the PropagatesReloadTo= and ReloadPropagatedFrom= are
inverses to each other and both can be configured in a unit file. I was
wondering why PartOf= and ConsistsOf= are not the case. Thank you.
No particular reason, just noobody got around to implementing the
parsing of that option. Shouldn't be too hard though.

Zbyszek
林自均
2018-03-08 10:40:00 UTC
Permalink
Raw Message
Hi Zbyszek,

Thank you for your explanation.

However, I found that Conflicts= will be a good choice for me:

# /etc/systemd/system/my-apps-start.target
[Unit]
Wants=docker.service sshd.service mongodb.service

# /etc/systemd/system/my-apps-stop.target
[Unit]
Conflicts=docker.service sshd.service mongodb.service
After=docker.service sshd.service mongodb.service

Then

systemctl start my-apps-start.target # starts all my apps
systemctl start my-apps-stop.target # stops all my apps

And both operations are sync, i.e. will wait for all apps to be
started/stopped before systemctl exits.

Thank you all for solving my problems.

John Lin
Post by Zbigniew Jędrzejewski-Szmek
Post by 林自均
Anyone?
John Lin
Post by 林自均
Hi Jérémy,
Thank you, but I read the section "Mapping of unit properties to their
inverses" in the man page
https://www.freedesktop.org/software/systemd/man/systemd.unit.html and
then found out the PropagatesReloadTo= and ReloadPropagatedFrom= are
inverses to each other and both can be configured in a unit file. I was
wondering why PartOf= and ConsistsOf= are not the case. Thank you.
No particular reason, just noobody got around to implementing the
parsing of that option. Shouldn't be too hard though.
Zbyszek
Loading...