systemd: add "requiredBy" option.

"require" is a stronger version of "want",
and just like wantedBy allows you to specify this relation in reverse,
requiredBy does the same.

It may seem pointless to be able to specify these stronger relations in
reverse, because if something is really required, you would expect the
other unit to specify this himself.

However, this is still useful for virtual/automatic units (like
devices) that are created by systemd on demand and hence have no unit
file you can alter.
This commit is contained in:
Mathijs Kwik 2013-04-19 22:28:00 +02:00
parent 8c702b7c28
commit 8de00c328a
2 changed files with 22 additions and 5 deletions

View file

@ -76,6 +76,12 @@ rec {
''; '';
}; };
requiredBy = mkOption {
default = [];
types = types.listOf types.string;
description = "Units that require (i.e. depend on and need to go down with) this unit.";
};
wantedBy = mkOption { wantedBy = mkOption {
default = []; default = [];
types = types.listOf types.string; types = types.listOf types.string;

View file

@ -211,7 +211,7 @@ let
as)); as));
targetToUnit = name: def: targetToUnit = name: def:
{ inherit (def) wantedBy enable; { inherit (def) wantedBy requiredBy enable;
text = text =
'' ''
[Unit] [Unit]
@ -220,7 +220,7 @@ let
}; };
serviceToUnit = name: def: serviceToUnit = name: def:
{ inherit (def) wantedBy enable; { inherit (def) wantedBy requiredBy enable;
text = text =
'' ''
[Unit] [Unit]
@ -267,7 +267,7 @@ let
}; };
socketToUnit = name: def: socketToUnit = name: def:
{ inherit (def) wantedBy enable; { inherit (def) wantedBy requiredBy enable;
text = text =
'' ''
[Unit] [Unit]
@ -279,7 +279,7 @@ let
}; };
timerToUnit = name: def: timerToUnit = name: def:
{ inherit (def) wantedBy enable; { inherit (def) wantedBy requiredBy enable;
text = text =
'' ''
[Unit] [Unit]
@ -291,7 +291,7 @@ let
}; };
mountToUnit = name: def: mountToUnit = name: def:
{ inherit (def) wantedBy enable; { inherit (def) wantedBy requiredBy enable;
text = text =
'' ''
[Unit] [Unit]
@ -343,6 +343,12 @@ let
ln -sfn ../${name} $out/${name2}.wants/ ln -sfn ../${name} $out/${name2}.wants/
'') unit.wantedBy) cfg.units)} '') unit.wantedBy) cfg.units)}
${concatStrings (mapAttrsToList (name: unit:
concatMapStrings (name2: ''
mkdir -p $out/${name2}.requires
ln -sfn ../${name} $out/${name2}.requires/
'') unit.requiredBy) cfg.units)}
ln -s ${cfg.defaultUnit} $out/default.target ln -s ${cfg.defaultUnit} $out/default.target
ln -s rescue.target $out/kbrequest.target ln -s rescue.target $out/kbrequest.target
@ -387,6 +393,11 @@ in
from being started. from being started.
''; '';
}; };
requiredBy = mkOption {
default = [];
types = types.listOf types.string;
description = "Units that require (i.e. depend on and need to go down with) this unit.";
};
wantedBy = mkOption { wantedBy = mkOption {
default = []; default = [];
types = types.listOf types.string; types = types.listOf types.string;