|
|
f27ed14 |
From bbb015bed0b09ddd9e86583f15d8a9366a892c6d Mon Sep 17 00:00:00 2001
|
|
|
f27ed14 |
From: Michal Sekletar <msekleta@redhat.com>
|
|
|
f27ed14 |
Date: Fri, 20 Jul 2012 15:55:01 +0200
|
|
|
f27ed14 |
Subject: [PATCH] systemd: added new dependency PartOf
|
|
|
f27ed14 |
|
|
|
f27ed14 |
This should address TODO item "new dependency type to "group" services
|
|
|
f27ed14 |
in a target". Semantic of new dependency is as follows. Once configured
|
|
|
f27ed14 |
it creates dependency which will cause that all dependent units get
|
|
|
f27ed14 |
stopped if unit they all depend on is stopped or restarted. Usual use
|
|
|
f27ed14 |
case would be configuring PartOf=some.target in template unit file
|
|
|
f27ed14 |
and WantedBy=some.target in [Install] section and enabling desired
|
|
|
f27ed14 |
number of instances. In this case starting one instance won't pull in
|
|
|
f27ed14 |
target but stopping or starting target(in case of WantedBy is properly
|
|
|
f27ed14 |
configured) will cause stop/start of all instances.
|
|
|
f27ed14 |
(cherry picked from commit 85e9a1010d16064ce435b84f02dc585bc645aade)
|
|
|
f27ed14 |
---
|
|
|
f27ed14 |
man/systemd.unit.xml | 15 +++++++++++++++
|
|
|
f27ed14 |
src/core/load-fragment-gperf.gperf.m4 | 1 +
|
|
|
f27ed14 |
src/core/transaction.c | 12 ++++++++++++
|
|
|
f27ed14 |
src/core/unit.c | 3 ++-
|
|
|
f27ed14 |
src/core/unit.h | 2 ++
|
|
|
f27ed14 |
5 files changed, 32 insertions(+), 1 deletion(-)
|
|
|
f27ed14 |
|
|
|
f27ed14 |
diff --git a/man/systemd.unit.xml b/man/systemd.unit.xml
|
|
|
f27ed14 |
index 698cbe3..5b708b3 100644
|
|
|
f27ed14 |
--- a/man/systemd.unit.xml
|
|
|
f27ed14 |
+++ b/man/systemd.unit.xml
|
|
|
f27ed14 |
@@ -427,6 +427,21 @@
|
|
|
f27ed14 |
</varlistentry>
|
|
|
f27ed14 |
|
|
|
f27ed14 |
<varlistentry>
|
|
|
f27ed14 |
+ <term><varname>PartOf=</varname></term>
|
|
|
f27ed14 |
+
|
|
|
f27ed14 |
+ <listitem><para>Configures dependency
|
|
|
f27ed14 |
+ on other unit. When systemd stops or
|
|
|
f27ed14 |
+ restarts unit listed here, stop or
|
|
|
f27ed14 |
+ restart is propagated to dependent
|
|
|
f27ed14 |
+ units. Note that this is one way
|
|
|
f27ed14 |
+ dependency and changes to dependent
|
|
|
f27ed14 |
+ units does not affect listed unit. If
|
|
|
f27ed14 |
+ something else is desired, please
|
|
|
f27ed14 |
+ use some other type of dependency.
|
|
|
f27ed14 |
+ </para></listitem>
|
|
|
f27ed14 |
+ </varlistentry>
|
|
|
f27ed14 |
+
|
|
|
f27ed14 |
+ <varlistentry>
|
|
|
f27ed14 |
<term><varname>Conflicts=</varname></term>
|
|
|
f27ed14 |
|
|
|
f27ed14 |
<listitem><para>Configures negative
|
|
|
f27ed14 |
diff --git a/src/core/load-fragment-gperf.gperf.m4 b/src/core/load-fragment-gperf.gperf.m4
|
|
|
f27ed14 |
index e6d0db3..1489342 100644
|
|
|
f27ed14 |
--- a/src/core/load-fragment-gperf.gperf.m4
|
|
|
f27ed14 |
+++ b/src/core/load-fragment-gperf.gperf.m4
|
|
|
f27ed14 |
@@ -108,6 +108,7 @@ Unit.PropagatesReloadTo, config_parse_unit_deps, UNIT_PROPAG
|
|
|
f27ed14 |
Unit.PropagateReloadTo, config_parse_unit_deps, UNIT_PROPAGATES_RELOAD_TO, 0
|
|
|
f27ed14 |
Unit.ReloadPropagatedFrom, config_parse_unit_deps, UNIT_RELOAD_PROPAGATED_FROM, 0
|
|
|
f27ed14 |
Unit.PropagateReloadFrom, config_parse_unit_deps, UNIT_RELOAD_PROPAGATED_FROM, 0
|
|
|
f27ed14 |
+Unit.PartOf, config_parse_unit_deps, UNIT_PART_OF, 0
|
|
|
f27ed14 |
Unit.RequiresMountsFor, config_parse_unit_requires_mounts_for, 0, offsetof(Unit, requires_mounts_for)
|
|
|
f27ed14 |
Unit.StopWhenUnneeded, config_parse_bool, 0, offsetof(Unit, stop_when_unneeded)
|
|
|
f27ed14 |
Unit.RefuseManualStart, config_parse_bool, 0, offsetof(Unit, refuse_manual_start)
|
|
|
f27ed14 |
diff --git a/src/core/transaction.c b/src/core/transaction.c
|
|
|
f27ed14 |
index a1cf706..1f8d803 100644
|
|
|
f27ed14 |
--- a/src/core/transaction.c
|
|
|
f27ed14 |
+++ b/src/core/transaction.c
|
|
|
f27ed14 |
@@ -994,6 +994,18 @@ int transaction_add_job_and_dependencies(
|
|
|
f27ed14 |
dbus_error_free(e);
|
|
|
f27ed14 |
}
|
|
|
f27ed14 |
}
|
|
|
f27ed14 |
+
|
|
|
f27ed14 |
+ SET_FOREACH(dep, ret->unit->dependencies[UNIT_CONSISTS_OF], i) {
|
|
|
f27ed14 |
+ r = transaction_add_job_and_dependencies(tr, type, dep, ret, true, override, false, false, ignore_order, e);
|
|
|
f27ed14 |
+ if (r < 0) {
|
|
|
f27ed14 |
+ if (r != -EBADR)
|
|
|
f27ed14 |
+ goto fail;
|
|
|
f27ed14 |
+
|
|
|
f27ed14 |
+ if (e)
|
|
|
f27ed14 |
+ dbus_error_free(e);
|
|
|
f27ed14 |
+ }
|
|
|
f27ed14 |
+ }
|
|
|
f27ed14 |
+
|
|
|
f27ed14 |
}
|
|
|
f27ed14 |
|
|
|
f27ed14 |
if (type == JOB_RELOAD) {
|
|
|
f27ed14 |
diff --git a/src/core/unit.c b/src/core/unit.c
|
|
|
f27ed14 |
index ca3892c..f0880a3 100644
|
|
|
f27ed14 |
--- a/src/core/unit.c
|
|
|
f27ed14 |
+++ b/src/core/unit.c
|
|
|
f27ed14 |
@@ -1606,7 +1606,8 @@ int unit_add_dependency(Unit *u, UnitDependency d, Unit *other, bool add_referen
|
|
|
f27ed14 |
[UNIT_TRIGGERS] = UNIT_TRIGGERED_BY,
|
|
|
f27ed14 |
[UNIT_TRIGGERED_BY] = UNIT_TRIGGERS,
|
|
|
f27ed14 |
[UNIT_PROPAGATES_RELOAD_TO] = UNIT_RELOAD_PROPAGATED_FROM,
|
|
|
f27ed14 |
- [UNIT_RELOAD_PROPAGATED_FROM] = UNIT_PROPAGATES_RELOAD_TO
|
|
|
f27ed14 |
+ [UNIT_RELOAD_PROPAGATED_FROM] = UNIT_PROPAGATES_RELOAD_TO,
|
|
|
f27ed14 |
+ [UNIT_PART_OF] = UNIT_CONSISTS_OF
|
|
|
f27ed14 |
};
|
|
|
f27ed14 |
int r, q = 0, v = 0, w = 0;
|
|
|
f27ed14 |
|
|
|
f27ed14 |
diff --git a/src/core/unit.h b/src/core/unit.h
|
|
|
f27ed14 |
index ed31c62..992afa2 100644
|
|
|
f27ed14 |
--- a/src/core/unit.h
|
|
|
f27ed14 |
+++ b/src/core/unit.h
|
|
|
f27ed14 |
@@ -77,12 +77,14 @@ enum UnitDependency {
|
|
|
f27ed14 |
UNIT_REQUISITE_OVERRIDABLE,
|
|
|
f27ed14 |
UNIT_WANTS,
|
|
|
f27ed14 |
UNIT_BINDS_TO,
|
|
|
f27ed14 |
+ UNIT_PART_OF,
|
|
|
f27ed14 |
|
|
|
f27ed14 |
/* Inverse of the above */
|
|
|
f27ed14 |
UNIT_REQUIRED_BY, /* inverse of 'requires' and 'requisite' is 'required_by' */
|
|
|
f27ed14 |
UNIT_REQUIRED_BY_OVERRIDABLE, /* inverse of 'requires_overridable' and 'requisite_overridable' is 'soft_required_by' */
|
|
|
f27ed14 |
UNIT_WANTED_BY, /* inverse of 'wants' */
|
|
|
f27ed14 |
UNIT_BOUND_BY, /* inverse of 'binds_to' */
|
|
|
f27ed14 |
+ UNIT_CONSISTS_OF, /* inverse of 'part_of' */
|
|
|
f27ed14 |
|
|
|
f27ed14 |
/* Negative dependencies */
|
|
|
f27ed14 |
UNIT_CONFLICTS, /* inverse of 'conflicts' is 'conflicted_by' */
|