summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/systemd/systemd-systemctl/systemctl
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-core/systemd/systemd-systemctl/systemctl')
-rwxr-xr-xmeta/recipes-core/systemd/systemd-systemctl/systemctl22
1 files changed, 16 insertions, 6 deletions
diff --git a/meta/recipes-core/systemd/systemd-systemctl/systemctl b/meta/recipes-core/systemd/systemd-systemctl/systemctl
index 990de1ab39..e003c860e3 100755
--- a/meta/recipes-core/systemd/systemd-systemctl/systemctl
+++ b/meta/recipes-core/systemd/systemd-systemctl/systemctl
@@ -11,6 +11,7 @@ import re
11import sys 11import sys
12 12
13from collections import namedtuple 13from collections import namedtuple
14from itertools import chain
14from pathlib import Path 15from pathlib import Path
15 16
16version = 1.0 17version = 1.0
@@ -25,12 +26,16 @@ locations = list()
25 26
26class SystemdFile(): 27class SystemdFile():
27 """Class representing a single systemd configuration file""" 28 """Class representing a single systemd configuration file"""
28 def __init__(self, root, path): 29 def __init__(self, root, path, instance_unit_name):
29 self.sections = dict() 30 self.sections = dict()
30 self._parse(root, path) 31 self._parse(root, path)
31 dirname = os.path.basename(path.name) + ".d" 32 dirname = os.path.basename(path.name) + ".d"
32 for location in locations: 33 for location in locations:
33 for path2 in sorted((root / location / "system" / dirname).glob("*.conf")): 34 files = (root / location / "system" / dirname).glob("*.conf")
35 if instance_unit_name:
36 inst_dirname = instance_unit_name + ".d"
37 files = chain(files, (root / location / "system" / inst_dirname).glob("*.conf"))
38 for path2 in sorted(files):
34 self._parse(root, path2) 39 self._parse(root, path2)
35 40
36 def _parse(self, root, path): 41 def _parse(self, root, path):
@@ -177,12 +182,14 @@ class SystemdUnit():
177 182
178 raise SystemdUnitNotFoundError(self.root, unit) 183 raise SystemdUnitNotFoundError(self.root, unit)
179 184
180 def _process_deps(self, config, service, location, prop, dirstem): 185 def _process_deps(self, config, service, location, prop, dirstem, instance):
181 systemdir = self.root / SYSCONFDIR / "systemd" / "system" 186 systemdir = self.root / SYSCONFDIR / "systemd" / "system"
182 187
183 target = ROOT / location.relative_to(self.root) 188 target = ROOT / location.relative_to(self.root)
184 try: 189 try:
185 for dependent in config.get('Install', prop): 190 for dependent in config.get('Install', prop):
191 # expand any %i to instance (ignoring escape sequence %%)
192 dependent = re.sub("([^%](%%)*)%i", "\\g<1>{}".format(instance), dependent)
186 wants = systemdir / "{}.{}".format(dependent, dirstem) / service 193 wants = systemdir / "{}.{}".format(dependent, dirstem) / service
187 add_link(wants, target) 194 add_link(wants, target)
188 195
@@ -193,8 +200,11 @@ class SystemdUnit():
193 # if we're enabling an instance, first extract the actual instance 200 # if we're enabling an instance, first extract the actual instance
194 # then figure out what the template unit is 201 # then figure out what the template unit is
195 template = re.match(r"[^@]+@(?P<instance>[^\.]*)\.", self.unit) 202 template = re.match(r"[^@]+@(?P<instance>[^\.]*)\.", self.unit)
203 instance_unit_name = None
196 if template: 204 if template:
197 instance = template.group('instance') 205 instance = template.group('instance')
206 if instance != "":
207 instance_unit_name = self.unit
198 unit = re.sub(r"@[^\.]*\.", "@.", self.unit, 1) 208 unit = re.sub(r"@[^\.]*\.", "@.", self.unit, 1)
199 else: 209 else:
200 instance = None 210 instance = None
@@ -206,7 +216,7 @@ class SystemdUnit():
206 # ignore aliases 216 # ignore aliases
207 return 217 return
208 218
209 config = SystemdFile(self.root, path) 219 config = SystemdFile(self.root, path, instance_unit_name)
210 if instance == "": 220 if instance == "":
211 try: 221 try:
212 default_instance = config.get('Install', 'DefaultInstance')[0] 222 default_instance = config.get('Install', 'DefaultInstance')[0]
@@ -219,8 +229,8 @@ class SystemdUnit():
219 else: 229 else:
220 service = self.unit 230 service = self.unit
221 231
222 self._process_deps(config, service, path, 'WantedBy', 'wants') 232 self._process_deps(config, service, path, 'WantedBy', 'wants', instance)
223 self._process_deps(config, service, path, 'RequiredBy', 'requires') 233 self._process_deps(config, service, path, 'RequiredBy', 'requires', instance)
224 234
225 try: 235 try:
226 for also in config.get('Install', 'Also'): 236 for also in config.get('Install', 'Also'):