Skip to contentSkip to conversation

systemd.bbclass: check whether systemctl works in

PATCH In review kai 2 participants 4 messages Oct 29, 2020 – Oct 30, 2020

lore
Share & tools
lore

kai

author
#0 lore raw

cover systemd.bbclass: check whether systemctl works in

From: Kai Kang <[email protected]>

It fails to run systemctl in a container even though it exists. Check with 'systemctl list-machines' to make sure systemctl works.

And there is another issue that /var/tmp is a dead link to volatile/tmp which doesn't exists. Changqing has sent a patch to fix it. My concern is in FHS, /var/tmp should not volatile. Could we make /var/tmp as a common directory rather than a link without extra config?

Ref:
https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch05s15.html

Kai Kang (1):
systemd.bbclass: check whether systemctl works in post scripts

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

PATCH 1/1 systemd.bbclass: check whether systemctl works in post scripts

From: Kai Kang <[email protected]>

When use a core image tarball as a docker image with 'docker import', it fails to install/remove package which calls systemctl in post scripts. Because it fais 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

Replace 'type systemctl' with 'systemctl list-machines' in package post scripts to check whether systemctl work rather than existence.

---
 meta/classes/systemd.bbclass | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
meta/classes/systemd.bbclass +2 -2
index 9e8a82c9f1..9938425e2d 100644
@@ -23,7 +23,7 @@ python __anonymous() {
 }
 
 systemd_postinst() {
-if type systemctl >/dev/null 2>/dev/null; then
+if systemctl list-machines >/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 list-machines >/dev/null 2>/dev/null; then
 	if [ -z "$D" ]; then
 		systemctl stop ${SYSTEMD_SERVICE_ESCAPED}
 
Signature · 1 line
2.17.1
#2 lore raw

Re: [OE-core] [PATCH 1/1] systemd.bbclass: check whether systemctl works in post scripts

Hello Kai,

Quoted 23 lines · On Thu, 29 Oct 2020 17:26:50 +0800 "kai" <[email protected]> wrote:

From: Kai Kang <[email protected]>

When use a core image tarball as a docker image with 'docker import', it fails to install/remove package which calls systemctl in post scripts. Because it fais 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

Replace 'type systemctl' with 'systemctl list-machines' in package post scripts to check whether systemctl work rather than existence.

---
 meta/classes/systemd.bbclass | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
meta/classes/systemd.bbclass +0 -0
index 9e8a82c9f1..9938425e2d 100644

meta/classes/systemd.bbclass python __anonymous() { · line 29

Quoted 8 lines
meta/classes/systemd.bbclass +1 -1
@@ -23,7 +23,7 @@ python __anonymous() {
 }
 
 systemd_postinst() {
-if type systemctl >/dev/null 2>/dev/null; then
+if systemctl list-machines >/dev/null 2>/dev/null; then
 	OPTS=""
 
 	if [ -n "$D" ]; then

Shouldn't this already have been run during image construction?

Doesn't this break our systemctl emulation (meta/recipes-core/systemd/systemd-systemctl/systemctl)?

meta/classes/systemd.bbclass fi · line 54

Quoted 9 lines
meta/classes/systemd.bbclass +1 -1
@@ -48,7 +48,7 @@ fi
 }
 
 systemd_prerm() {
-if type systemctl >/dev/null 2>/dev/null; then
+if systemctl list-machines >/dev/null 2>/dev/null; then
 	if [ -z "$D" ]; then
 		systemctl stop ${SYSTEMD_SERVICE_ESCAPED}
 

You're running the prerm hook inside a docker container?

Wouldn't it be more appropriate to remove the systemd DISTRO_FEATURE for a use-case like this?

Best regards,
Andreas

author
#3 lore raw

回复: [PATCH 1/1] systemd.bbclass: check whether systemctl works in post scripts

In reply to kai

Hi Andreas,

I am sorry that my email client goes wrong. So I have to reply this way.

Quoted 10 lines

Review

Quoted 6 lines

systemd_postinst() {

(quoted diff) +1 -1
-if type systemctl >/dev/null 2>/dev/null; then
+if systemctl list-machines >/dev/null 2>/dev/null; then
     OPTS=""
 
     if [ -n "$D" ]; then

Shouldn't this already have been run during image construction?

Doesn't this break our systemctl emulation (meta/recipes-core/systemd/systemd-systemctl/systemctl)?

The use case is similar with Fedora or Debian that modify image with command dnf, both on the real bsp or container.

It breaks the systemd-systemctl-native indeed. The reason to run systemctl to check whether it really works because it fails in container. And I suppose 'systemctl list-machines' is the most quick subcommand of systemctl. How about add a stub function to provide sub-common list-machines for systemd-systemctl-native?

Quoted 14 lines

Review fi · line 54

Quoted 11 lines
(quoted diff) +1 -1
@@ -48,7 +48,7 @@ fi
 }
 
 systemd_prerm() {
-if type systemctl >/dev/null 2>/dev/null; then
+if systemctl list-machines >/dev/null 2>/dev/null; then
     if [ -z "$D" ]; then
         systemctl stop ${SYSTEMD_SERVICE_ESCAPED}
 

You're running the prerm hook inside a docker container?

Quoted 1 line

Wouldn't it be more appropriate to remove the systemd DISTRO_FEATURE for a use-case like this?

There will always has an init manager there for oe-core. It should work for both sysvinit and systemd without extra configure to use as a docker image.

Thanks for your comment.

Kai

________________________________
发件人: Kang, Kai <[email protected]>
发送时间: 2020年10月29日 17:27
收件人: [email protected] <[email protected]> 主题: [PATCH 1/1] systemd.bbclass: check whether systemctl works in post scripts

From: Kai Kang <[email protected]>

When use a core image tarball as a docker image with 'docker import', it fails to install/remove package which calls systemctl in post scripts. Because it fais 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

Replace 'type systemctl' with 'systemctl list-machines' in package post scripts to check whether systemctl work rather than existence.

---
 meta/classes/systemd.bbclass | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
meta/classes/systemd.bbclass +2 -2
index 9e8a82c9f1..9938425e2d 100644
@@ -23,7 +23,7 @@ python __anonymous() {
 }
 
 systemd_postinst() {
-if type systemctl >/dev/null 2>/dev/null; then
+if systemctl list-machines >/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 list-machines >/dev/null 2>/dev/null; then
         if [ -z "$D" ]; then
                 systemctl stop ${SYSTEMD_SERVICE_ESCAPED}
 

--
2.17.1