How to create composite systemd unit
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
There I certain services, that I typically start together: say zookeeper+kafka+elassandra. Is there a way how to write composite unit: all starts together, all dies together? Meaning if I start this, it will delegate to start all that, and vice versa. What would be proper way of doing that?
systemd
add a comment |Â
up vote
1
down vote
favorite
There I certain services, that I typically start together: say zookeeper+kafka+elassandra. Is there a way how to write composite unit: all starts together, all dies together? Meaning if I start this, it will delegate to start all that, and vice versa. What would be proper way of doing that?
systemd
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
There I certain services, that I typically start together: say zookeeper+kafka+elassandra. Is there a way how to write composite unit: all starts together, all dies together? Meaning if I start this, it will delegate to start all that, and vice versa. What would be proper way of doing that?
systemd
There I certain services, that I typically start together: say zookeeper+kafka+elassandra. Is there a way how to write composite unit: all starts together, all dies together? Meaning if I start this, it will delegate to start all that, and vice versa. What would be proper way of doing that?
systemd
systemd
asked 1 hour ago
user1534084
163
163
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
One way is to have all three services depend on the remaining two using Requires=
.
- one.service:
Requires=two.service three.service
- two.service:
Requires=one.service three.service
- three.service: etc.
This won't create a loop â dependencies are independent from startup ordering.
(That said, you should declare some Before= or After=, e.g. if kafka needs to run after zookeeper.)
The other method is to create a .target unit, have it depend on your three services, and the services be PartOf=
the unit. (Unfortunately it is not yet possible to have ConsistsOf= in the .target itself.)
- all.target:
Requires=one.service two.service three.service
- one.service:
PartOf=all.target
- etc.
(Again, you should additionally declare dependencies and ordering between the services; don't rely only on the .target starting everything.)
add a comment |Â
up vote
1
down vote
Yes, there are a few ways to accomplish that.
The simplest one (which does some of what uou describe, but not all) is to create a target unit and add dependencies on your service units (for example, Requires=zookeeper.service kafka.service elassandra.service
and also set After=
to the same units.) A target unit is helpful in starting all these units together, but it doesn't really help you stop them all together (using systemctl stop
on the target unit won't stop its dependencies.) There are ways you can stop units, for example systemctl isolate multi-user.target
will stop all units that are not dependencies of that target, which means units started manually will be stopped, but this is much stronger than stopping a small set of units, so probably not a great fit...
A better approach is perhaps using the PartOf=
directive, which does exactly as you describe. You can either create a "dummy" service unit to manage all services together, or pick one of your services and make the others PartOf
that one service.
You need to configure PartOf=
in all the units you want to start and stop together, in your case, zookeeper.service, kafka.service and elassandra.service. But please note you don't necessarily need to modify the service unit files themselves (for example, if they're shipped with the software itself in deb or rpm packages.) You can use override files (which you can create using systemctl edit
) to add a small configuration snippet to an existing unit, which should make it easy for you to define PartOf=
relationships between units even if they're defined in files you would prefer not to modify.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
One way is to have all three services depend on the remaining two using Requires=
.
- one.service:
Requires=two.service three.service
- two.service:
Requires=one.service three.service
- three.service: etc.
This won't create a loop â dependencies are independent from startup ordering.
(That said, you should declare some Before= or After=, e.g. if kafka needs to run after zookeeper.)
The other method is to create a .target unit, have it depend on your three services, and the services be PartOf=
the unit. (Unfortunately it is not yet possible to have ConsistsOf= in the .target itself.)
- all.target:
Requires=one.service two.service three.service
- one.service:
PartOf=all.target
- etc.
(Again, you should additionally declare dependencies and ordering between the services; don't rely only on the .target starting everything.)
add a comment |Â
up vote
2
down vote
One way is to have all three services depend on the remaining two using Requires=
.
- one.service:
Requires=two.service three.service
- two.service:
Requires=one.service three.service
- three.service: etc.
This won't create a loop â dependencies are independent from startup ordering.
(That said, you should declare some Before= or After=, e.g. if kafka needs to run after zookeeper.)
The other method is to create a .target unit, have it depend on your three services, and the services be PartOf=
the unit. (Unfortunately it is not yet possible to have ConsistsOf= in the .target itself.)
- all.target:
Requires=one.service two.service three.service
- one.service:
PartOf=all.target
- etc.
(Again, you should additionally declare dependencies and ordering between the services; don't rely only on the .target starting everything.)
add a comment |Â
up vote
2
down vote
up vote
2
down vote
One way is to have all three services depend on the remaining two using Requires=
.
- one.service:
Requires=two.service three.service
- two.service:
Requires=one.service three.service
- three.service: etc.
This won't create a loop â dependencies are independent from startup ordering.
(That said, you should declare some Before= or After=, e.g. if kafka needs to run after zookeeper.)
The other method is to create a .target unit, have it depend on your three services, and the services be PartOf=
the unit. (Unfortunately it is not yet possible to have ConsistsOf= in the .target itself.)
- all.target:
Requires=one.service two.service three.service
- one.service:
PartOf=all.target
- etc.
(Again, you should additionally declare dependencies and ordering between the services; don't rely only on the .target starting everything.)
One way is to have all three services depend on the remaining two using Requires=
.
- one.service:
Requires=two.service three.service
- two.service:
Requires=one.service three.service
- three.service: etc.
This won't create a loop â dependencies are independent from startup ordering.
(That said, you should declare some Before= or After=, e.g. if kafka needs to run after zookeeper.)
The other method is to create a .target unit, have it depend on your three services, and the services be PartOf=
the unit. (Unfortunately it is not yet possible to have ConsistsOf= in the .target itself.)
- all.target:
Requires=one.service two.service three.service
- one.service:
PartOf=all.target
- etc.
(Again, you should additionally declare dependencies and ordering between the services; don't rely only on the .target starting everything.)
answered 41 mins ago
grawity
222k33455519
222k33455519
add a comment |Â
add a comment |Â
up vote
1
down vote
Yes, there are a few ways to accomplish that.
The simplest one (which does some of what uou describe, but not all) is to create a target unit and add dependencies on your service units (for example, Requires=zookeeper.service kafka.service elassandra.service
and also set After=
to the same units.) A target unit is helpful in starting all these units together, but it doesn't really help you stop them all together (using systemctl stop
on the target unit won't stop its dependencies.) There are ways you can stop units, for example systemctl isolate multi-user.target
will stop all units that are not dependencies of that target, which means units started manually will be stopped, but this is much stronger than stopping a small set of units, so probably not a great fit...
A better approach is perhaps using the PartOf=
directive, which does exactly as you describe. You can either create a "dummy" service unit to manage all services together, or pick one of your services and make the others PartOf
that one service.
You need to configure PartOf=
in all the units you want to start and stop together, in your case, zookeeper.service, kafka.service and elassandra.service. But please note you don't necessarily need to modify the service unit files themselves (for example, if they're shipped with the software itself in deb or rpm packages.) You can use override files (which you can create using systemctl edit
) to add a small configuration snippet to an existing unit, which should make it easy for you to define PartOf=
relationships between units even if they're defined in files you would prefer not to modify.
add a comment |Â
up vote
1
down vote
Yes, there are a few ways to accomplish that.
The simplest one (which does some of what uou describe, but not all) is to create a target unit and add dependencies on your service units (for example, Requires=zookeeper.service kafka.service elassandra.service
and also set After=
to the same units.) A target unit is helpful in starting all these units together, but it doesn't really help you stop them all together (using systemctl stop
on the target unit won't stop its dependencies.) There are ways you can stop units, for example systemctl isolate multi-user.target
will stop all units that are not dependencies of that target, which means units started manually will be stopped, but this is much stronger than stopping a small set of units, so probably not a great fit...
A better approach is perhaps using the PartOf=
directive, which does exactly as you describe. You can either create a "dummy" service unit to manage all services together, or pick one of your services and make the others PartOf
that one service.
You need to configure PartOf=
in all the units you want to start and stop together, in your case, zookeeper.service, kafka.service and elassandra.service. But please note you don't necessarily need to modify the service unit files themselves (for example, if they're shipped with the software itself in deb or rpm packages.) You can use override files (which you can create using systemctl edit
) to add a small configuration snippet to an existing unit, which should make it easy for you to define PartOf=
relationships between units even if they're defined in files you would prefer not to modify.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Yes, there are a few ways to accomplish that.
The simplest one (which does some of what uou describe, but not all) is to create a target unit and add dependencies on your service units (for example, Requires=zookeeper.service kafka.service elassandra.service
and also set After=
to the same units.) A target unit is helpful in starting all these units together, but it doesn't really help you stop them all together (using systemctl stop
on the target unit won't stop its dependencies.) There are ways you can stop units, for example systemctl isolate multi-user.target
will stop all units that are not dependencies of that target, which means units started manually will be stopped, but this is much stronger than stopping a small set of units, so probably not a great fit...
A better approach is perhaps using the PartOf=
directive, which does exactly as you describe. You can either create a "dummy" service unit to manage all services together, or pick one of your services and make the others PartOf
that one service.
You need to configure PartOf=
in all the units you want to start and stop together, in your case, zookeeper.service, kafka.service and elassandra.service. But please note you don't necessarily need to modify the service unit files themselves (for example, if they're shipped with the software itself in deb or rpm packages.) You can use override files (which you can create using systemctl edit
) to add a small configuration snippet to an existing unit, which should make it easy for you to define PartOf=
relationships between units even if they're defined in files you would prefer not to modify.
Yes, there are a few ways to accomplish that.
The simplest one (which does some of what uou describe, but not all) is to create a target unit and add dependencies on your service units (for example, Requires=zookeeper.service kafka.service elassandra.service
and also set After=
to the same units.) A target unit is helpful in starting all these units together, but it doesn't really help you stop them all together (using systemctl stop
on the target unit won't stop its dependencies.) There are ways you can stop units, for example systemctl isolate multi-user.target
will stop all units that are not dependencies of that target, which means units started manually will be stopped, but this is much stronger than stopping a small set of units, so probably not a great fit...
A better approach is perhaps using the PartOf=
directive, which does exactly as you describe. You can either create a "dummy" service unit to manage all services together, or pick one of your services and make the others PartOf
that one service.
You need to configure PartOf=
in all the units you want to start and stop together, in your case, zookeeper.service, kafka.service and elassandra.service. But please note you don't necessarily need to modify the service unit files themselves (for example, if they're shipped with the software itself in deb or rpm packages.) You can use override files (which you can create using systemctl edit
) to add a small configuration snippet to an existing unit, which should make it easy for you to define PartOf=
relationships between units even if they're defined in files you would prefer not to modify.
answered 37 mins ago
Filipe Brandenburger
2104
2104
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1369115%2fhow-to-create-composite-systemd-unit%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password