chiark / gitweb /
systemd: added new dependency PartOf
authorMichal Sekletar <msekleta@redhat.com>
Fri, 20 Jul 2012 13:55:01 +0000 (15:55 +0200)
committerMichal Schmidt <mschmidt@redhat.com>
Thu, 26 Jul 2012 07:16:43 +0000 (09:16 +0200)
This should address TODO item "new dependency type to "group" services
in a target". Semantic of new dependency is as follows. Once configured
it creates dependency which will cause that all dependent units get
stopped if unit they all depend on is stopped or restarted.  Usual use
case would be configuring PartOf=some.target in template unit file
and WantedBy=some.target in [Install] section and enabling desired
number of instances. In this case starting one instance won't pull in
target but stopping or starting target(in case of WantedBy is properly
configured) will cause stop/start of all instances.

man/systemd.unit.xml
src/core/load-fragment-gperf.gperf.m4
src/core/transaction.c
src/core/unit.c
src/core/unit.h

index 286862006a9ab503027085e679a97f9eed3f668a..bdd8f7d7014cd67010969b9a9ce3de97ba399b55 100644 (file)
                                 systemd.</para></listitem>
                         </varlistentry>
 
+                        <varlistentry>
+                                <term><varname>PartOf=</varname></term>
+
+                                 <listitem><para>Configures dependency
+                                 on other unit. When systemd stops or
+                                 restarts unit listed here, stop or
+                                 restart is propagated to dependent
+                                 units. Note that this is one way
+                                 dependency and changes to dependent
+                                 units does not affect listed unit. If
+                                 something else is desired, please
+                                 use some other type of dependency.
+                                 </para></listitem>
+                        </varlistentry>
+
                         <varlistentry>
                                 <term><varname>Conflicts=</varname></term>
 
index d6a4711a32508883087c1d6d81935b6177ae995d..2b1cfa073ca5170028ef1e8377448330624f4073 100644 (file)
@@ -112,6 +112,7 @@ Unit.PropagatesReloadTo,         config_parse_unit_deps,             UNIT_PROPAG
 Unit.PropagateReloadTo,          config_parse_unit_deps,             UNIT_PROPAGATES_RELOAD_TO,     0
 Unit.ReloadPropagatedFrom,       config_parse_unit_deps,             UNIT_RELOAD_PROPAGATED_FROM,   0
 Unit.PropagateReloadFrom,        config_parse_unit_deps,             UNIT_RELOAD_PROPAGATED_FROM,   0
+Unit.PartOf,                     config_parse_unit_deps,             UNIT_PART_OF,                  0
 Unit.RequiresMountsFor,          config_parse_unit_requires_mounts_for, 0,                          offsetof(Unit, requires_mounts_for)
 Unit.StopWhenUnneeded,           config_parse_bool,                  0,                             offsetof(Unit, stop_when_unneeded)
 Unit.RefuseManualStart,          config_parse_bool,                  0,                             offsetof(Unit, refuse_manual_start)
index a1cf70693428d9ad535d77a883692422a40afca1..1f8d803aeb72b252628b3539225994191638f676 100644 (file)
@@ -994,6 +994,18 @@ int transaction_add_job_and_dependencies(
                                                 dbus_error_free(e);
                                 }
                         }
+
+                        SET_FOREACH(dep, ret->unit->dependencies[UNIT_CONSISTS_OF], i) {
+                                r = transaction_add_job_and_dependencies(tr, type, dep, ret, true, override, false, false, ignore_order, e);
+                                if (r < 0) {
+                                        if (r != -EBADR)
+                                                goto fail;
+
+                                        if (e)
+                                                dbus_error_free(e);
+                                }
+                        }
+
                 }
 
                 if (type == JOB_RELOAD) {
index 7b2f597589cfc5c76bea5421c6327ee77c4cdac3..be75cd792d5961a515ad647821cdce5ed11ad64f 100644 (file)
@@ -1610,7 +1610,8 @@ int unit_add_dependency(Unit *u, UnitDependency d, Unit *other, bool add_referen
                 [UNIT_TRIGGERS] = UNIT_TRIGGERED_BY,
                 [UNIT_TRIGGERED_BY] = UNIT_TRIGGERS,
                 [UNIT_PROPAGATES_RELOAD_TO] = UNIT_RELOAD_PROPAGATED_FROM,
-                [UNIT_RELOAD_PROPAGATED_FROM] = UNIT_PROPAGATES_RELOAD_TO
+                [UNIT_RELOAD_PROPAGATED_FROM] = UNIT_PROPAGATES_RELOAD_TO,
+                [UNIT_PART_OF] = UNIT_CONSISTS_OF
         };
         int r, q = 0, v = 0, w = 0;
 
index 2102b7a57001f94cc7e3c6376d58d36c2fd46d7c..89bd61c2d8fae939c03521de8b8e347d8b0c6d94 100644 (file)
@@ -75,12 +75,14 @@ enum UnitDependency {
         UNIT_REQUISITE_OVERRIDABLE,
         UNIT_WANTS,
         UNIT_BINDS_TO,
+        UNIT_PART_OF,
 
         /* Inverse of the above */
         UNIT_REQUIRED_BY,             /* inverse of 'requires' and 'requisite' is 'required_by' */
         UNIT_REQUIRED_BY_OVERRIDABLE, /* inverse of 'requires_overridable' and 'requisite_overridable' is 'soft_required_by' */
         UNIT_WANTED_BY,               /* inverse of 'wants' */
         UNIT_BOUND_BY,                /* inverse of 'binds_to' */
+        UNIT_CONSISTS_OF,             /* inverse of 'part_of' */
 
         /* Negative dependencies */
         UNIT_CONFLICTS,               /* inverse of 'conflicts' is 'conflicted_by' */