mirror of
https://git.yoctoproject.org/poky
synced 2026-06-01 00:59:48 +00:00
systemd: systemd-systemctl: Support instance conf files during enable
Add ability to parse instance-specific conf files when enabling an instance of a templated unit during postinstall. (From OE-Core rev: baa0ecf3271008cf60cd830c54a71f191aebb81c) Signed-off-by: Nick Potenski <nick.potenski@garmin.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
858f7e9d36
commit
01aaeb444f
@@ -11,6 +11,7 @@ import re
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
from itertools import chain
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
version = 1.0
|
version = 1.0
|
||||||
@@ -25,12 +26,16 @@ locations = list()
|
|||||||
|
|
||||||
class SystemdFile():
|
class SystemdFile():
|
||||||
"""Class representing a single systemd configuration file"""
|
"""Class representing a single systemd configuration file"""
|
||||||
def __init__(self, root, path):
|
def __init__(self, root, path, instance_unit_name):
|
||||||
self.sections = dict()
|
self.sections = dict()
|
||||||
self._parse(root, path)
|
self._parse(root, path)
|
||||||
dirname = os.path.basename(path.name) + ".d"
|
dirname = os.path.basename(path.name) + ".d"
|
||||||
for location in locations:
|
for location in locations:
|
||||||
for path2 in sorted((root / location / "system" / dirname).glob("*.conf")):
|
files = (root / location / "system" / dirname).glob("*.conf")
|
||||||
|
if instance_unit_name:
|
||||||
|
inst_dirname = instance_unit_name + ".d"
|
||||||
|
files = chain(files, (root / location / "system" / inst_dirname).glob("*.conf"))
|
||||||
|
for path2 in sorted(files):
|
||||||
self._parse(root, path2)
|
self._parse(root, path2)
|
||||||
|
|
||||||
def _parse(self, root, path):
|
def _parse(self, root, path):
|
||||||
@@ -195,8 +200,11 @@ class SystemdUnit():
|
|||||||
# if we're enabling an instance, first extract the actual instance
|
# if we're enabling an instance, first extract the actual instance
|
||||||
# then figure out what the template unit is
|
# then figure out what the template unit is
|
||||||
template = re.match(r"[^@]+@(?P<instance>[^\.]*)\.", self.unit)
|
template = re.match(r"[^@]+@(?P<instance>[^\.]*)\.", self.unit)
|
||||||
|
instance_unit_name = None
|
||||||
if template:
|
if template:
|
||||||
instance = template.group('instance')
|
instance = template.group('instance')
|
||||||
|
if instance != "":
|
||||||
|
instance_unit_name = self.unit
|
||||||
unit = re.sub(r"@[^\.]*\.", "@.", self.unit, 1)
|
unit = re.sub(r"@[^\.]*\.", "@.", self.unit, 1)
|
||||||
else:
|
else:
|
||||||
instance = None
|
instance = None
|
||||||
@@ -208,7 +216,7 @@ class SystemdUnit():
|
|||||||
# ignore aliases
|
# ignore aliases
|
||||||
return
|
return
|
||||||
|
|
||||||
config = SystemdFile(self.root, path)
|
config = SystemdFile(self.root, path, instance_unit_name)
|
||||||
if instance == "":
|
if instance == "":
|
||||||
try:
|
try:
|
||||||
default_instance = config.get('Install', 'DefaultInstance')[0]
|
default_instance = config.get('Install', 'DefaultInstance')[0]
|
||||||
|
|||||||
Reference in New Issue
Block a user