Skip to contentSkip to conversation

systemd.bbclass: only restart the service when it is running at systemd_postinst

PATCH Superseded Li Zhijian 1 participant 2 messages Nov 4, 2013 – Nov 5, 2013

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Li Zhijian

author
#0 lore raw

PATCH 1/1 systemd.bbclass: only restart the service when it is running at systemd_postinst

From: Li Zhijian <[email protected]>

If systemd_postinst is installed as a delayed package scriptlet (installed to /etc/rpm-postints/${PN}) which would be executed at the first time of OS startup. And then this script would block when it is trying to call systemctl to restart service.

It seems that it is not a good timing to restart service at run-postinsts. I test serval services which has supported systemd(uuidd/avahi-daemon), all of them will block the startup.

Steps to reproduce:
1) Installed systemd_postinst as a delayed package scriptlet i.e. Append Following lines to meta/recipes-core/busybox/busybox.inc

pkg_postinst_${PN}-syslog () {
       if [ "x$D" != "x" ] ; then
               exit 1
       fi
}
2) build a rootfs
# bitbake core-image-minimal
3) startup this rootfs

OS would block at /etc/rpm-postinsts/busybox-syslog, like follows [ ***] A start job is running ro Run pending postinsts

This patch can fix the block problem, and make the service is consistent with the original status

---
 meta/classes/systemd.bbclass |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
meta/classes/systemd.bbclass +2 -0
index 8084251..9fef667 100644
@@ -30,7 +30,8 @@ fi
 if type systemctl >/dev/null 2>/dev/null; then
 	systemctl $OPTS ${SYSTEMD_AUTO_ENABLE} ${SYSTEMD_SERVICE}
 -	if [ -z "$D" -a "${SYSTEMD_AUTO_ENABLE}" = "enable" ]; then
+	if [ -z "$D" ] && [ systemctl status ${SYSTEMD_SERVICE} &>/dev/null ]; then
+		# if service is running, restart it
 		systemctl restart ${SYSTEMD_SERVICE}
 	fi
 fi
Signature · 1 line
1.7.1
author
#1 lore raw

This patch is incorrect, please ignore it

i would send v2 soon.

Quoted 37 lines · Li Zhijian

From: Li Zhijian <[email protected]>

If systemd_postinst is installed as a delayed package scriptlet (installed to /etc/rpm-postints/${PN}) which would be executed at the first time of OS startup. And then this script would block when it is trying to call systemctl to restart service.

It seems that it is not a good timing to restart service at run-postinsts. I test serval services which has supported systemd(uuidd/avahi-daemon), all of them will block the startup.

Steps to reproduce:
1) Installed systemd_postinst as a delayed package scriptlet i.e. Append Following lines to meta/recipes-core/busybox/busybox.inc

pkg_postinst_${PN}-syslog () {
        if [ "x$D" != "x" ] ; then
                exit 1
        fi
}
2) build a rootfs
# bitbake core-image-minimal
3) startup this rootfs

OS would block at /etc/rpm-postinsts/busybox-syslog, like follows [ ***] A start job is running ro Run pending postinsts

This patch can fix the block problem, and make the service is consistent with the original status

---
  meta/classes/systemd.bbclass |    3 ++-
  1 files changed, 2 insertions(+), 1 deletions(-)
meta/classes/systemd.bbclass +0 -0
index 8084251..9fef667 100644

meta/classes/systemd.bbclass fi · line 33

Quoted 4 lines
meta/classes/systemd.bbclass +1 -0
@@ -30,7 +30,8 @@ fi
  if type systemctl >/dev/null 2>/dev/null; then
  	systemctl $OPTS ${SYSTEMD_AUTO_ENABLE} ${SYSTEMD_SERVICE}
  -	if [ -z "$D" -a "${SYSTEMD_AUTO_ENABLE}" = "enable" ]; then
+	if [ -z "$D" ] && [ systemctl status ${SYSTEMD_SERVICE} &>/dev/null ]; then

Should be:

if [ -z "$D" ] && systemctl status ${SYSTEMD_SERVICE} &>/dev/null; then

Signature · 2 lines
Best regards.
Li Zhijian
Quoted 4 lines
meta/classes/systemd.bbclass +1 -0
+		# if service is running, restart it
  		systemctl restart ${SYSTEMD_SERVICE}
  	fi
  fi
Signature · 2 lines
Best regards.
Li Zhijian (8555)