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/systemctl39
1 files changed, 29 insertions, 10 deletions
diff --git a/meta/recipes-core/systemd/systemd-systemctl/systemctl b/meta/recipes-core/systemd/systemd-systemctl/systemctl
index 8837f54e16..6324319a45 100755
--- a/meta/recipes-core/systemd/systemd-systemctl/systemctl
+++ b/meta/recipes-core/systemd/systemd-systemctl/systemctl
@@ -57,7 +57,7 @@ class SystemdFile():
if skip_re.match(line):
continue
- line = line.rstrip("\n")
+ line = line.strip()
m = section_re.match(line)
if m:
if m.group('section') not in self.sections:
@@ -160,7 +160,9 @@ def add_link(path, target):
class SystemdUnitNotFoundError(Exception):
- pass
+ def __init__(self, path, unit):
+ self.path = path
+ self.unit = unit
class SystemdUnit():
@@ -172,7 +174,7 @@ class SystemdUnit():
def _path_for_unit(self, unit):
for location in locations:
path = self.root / location / "system" / unit
- if path.exists():
+ if path.exists() or path.is_symlink():
return path
raise SystemdUnitNotFoundError(self.root, unit)
@@ -189,7 +191,7 @@ class SystemdUnit():
except KeyError:
pass
- def enable(self):
+ def enable(self, caller_unit=None):
# if we're enabling an instance, first extract the actual instance
# then figure out what the template unit is
template = re.match(r"[^@]+@(?P<instance>[^\.]*)\.", self.unit)
@@ -224,7 +226,11 @@ class SystemdUnit():
try:
for also in config.get('Install', 'Also'):
- SystemdUnit(self.root, also).enable()
+ try:
+ if caller_unit != also:
+ SystemdUnit(self.root, also).enable(unit)
+ except SystemdUnitNotFoundError as e:
+ sys.exit("Error: Systemctl also enable issue with %s (%s)" % (service, e.unit))
except KeyError:
pass
@@ -265,7 +271,10 @@ def preset_all(root):
state = presets.state(service)
if state == "enable" or state is None:
- SystemdUnit(root, service).enable()
+ try:
+ SystemdUnit(root, service).enable()
+ except SystemdUnitNotFoundError:
+ sys.exit("Error: Systemctl preset_all issue in %s" % service)
# If we populate the systemd links we also create /etc/machine-id, which
# allows systemd to boot with the filesystem read-only before generating
@@ -282,7 +291,7 @@ def main():
sys.exit("Python 3.4 or greater is required")
parser = argparse.ArgumentParser()
- parser.add_argument('command', nargs=1, choices=['enable', 'mask',
+ parser.add_argument('command', nargs='?', choices=['enable', 'mask',
'preset-all'])
parser.add_argument('service', nargs=argparse.REMAINDER)
parser.add_argument('--root')
@@ -300,13 +309,23 @@ def main():
locations.append(BASE_LIBDIR / "systemd")
locations.append(LIBDIR / "systemd")
- command = args.command[0]
+ command = args.command
+ if not command:
+ parser.print_help()
+ return 0
+
if command == "mask":
for service in args.service:
- SystemdUnit(root, service).mask()
+ try:
+ SystemdUnit(root, service).mask()
+ except SystemdUnitNotFoundError as e:
+ sys.exit("Error: Systemctl main mask issue in %s (%s)" % (service, e.unit))
elif command == "enable":
for service in args.service:
- SystemdUnit(root, service).enable()
+ try:
+ SystemdUnit(root, service).enable()
+ except SystemdUnitNotFoundError as e:
+ sys.exit("Error: Systemctl main enable issue in %s (%s)" % (service, e.unit))
elif command == "preset-all":
if len(args.service) != 0:
sys.exit("Too many arguments.")