Skip to contentSkip to conversation

Update the criterion whether command systemctl available in systemd.bbclass

PATCH New kai 1 participant 3 messages Dec 2, 2020

lore
Share & tools
lore

kai

author
#0 lore raw

v3 cover Update the criterion whether command systemctl available in systemd.bbclass

From: Kai Kang <[email protected]>

v3:
* update commit messages to make more clearer

Kai Kang (2):
systemd-systemctl-native: capable to call without argument systemd.bbclass: update command to check systemctl available

 meta/classes/systemd.bbclass                          | 4 ++--
 meta/recipes-core/systemd/systemd-systemctl/systemctl | 8 ++++++--
 2 files changed, 8 insertions(+), 4 deletions(-)
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v3 1/2 systemd-systemctl-native: capable to call without argument

From: Kai Kang <[email protected]>

In systemd.bbclass, it will replace criterion command 'type systemctl' with 'systemctl' without any argument to judge whether command systemctl is available. The change is to fix install/remove package error in container when command systemctl exists but not callable.

Make native systemctl wrapper prints help mesages if called without any argument to follow the update.

---
 meta/recipes-core/systemd/systemd-systemctl/systemctl | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
meta/recipes-core/systemd/systemd-systemctl/systemctl +6 -2
index 990de1ab39..de733e255b 100755
@@ -282,7 +282,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,7 +300,11 @@ 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()
Signature · 1 line
2.17.1
author
#2 lore raw

PATCH v3 2/2 systemd.bbclass: update command to check systemctl available

In reply to kai

From: Kai Kang <[email protected]>

When use a core image with systemd as docker image, it fails to install/remove package which calls systemctl in post scripts. It fails to run systemctl in a container:

bash-5.0# systemctl
System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down

So replace the criterion command 'type systemctl' with 'systemctl' in package post scripts to check whether systemctl available.

---
 meta/classes/systemd.bbclass | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
meta/classes/systemd.bbclass +2 -2
index 9e8a82c9f1..9ec465c759 100644
@@ -23,7 +23,7 @@ python __anonymous() {
 }
 
 systemd_postinst() {
-if type systemctl >/dev/null 2>/dev/null; then
+if systemctl >/dev/null 2>/dev/null; then
 	OPTS=""
 
 	if [ -n "$D" ]; then
@@ -48,7 +48,7 @@ fi
 }
 
 systemd_prerm() {
-if type systemctl >/dev/null 2>/dev/null; then
+if systemctl >/dev/null 2>/dev/null; then
 	if [ -z "$D" ]; then
 		systemctl stop ${SYSTEMD_SERVICE_ESCAPED}
 
Signature · 1 line
2.17.1