<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>15428</bug_id>
          
          <creation_ts>2024-03-07 15:06:10 +0000</creation_ts>
          <short_desc>postinstall failures with opkg in systemd enabled images</short_desc>
          <delta_ts>2024-03-30 22:34:44 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>11</classification_id>
          <classification>Runtime</classification>
          <product>System Startup</product>
          <component>system-startup</component>
          <version>unspecified</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>High</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>5.0 M4</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Richard Purdie">richard.purdie</reporter>
          <assigned_to name="Tim Orling">tim.orling</assigned_to>
          <cc>alexandre.belloni</cc>
    
    <cc>changqing.li</cc>
    
    <cc>joaomarcos.costa</cc>
    
    <cc>kevin.tian</cc>
    
    <cc>Qi.Chen</cc>
    
    <cc>randy.macleod</cc>
    
    <cc>ross.burton</cc>
    
    <cc>tim.orling</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>No (bug/feature does not impact docs)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>98404</commentid>
    <comment_count>0</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2024-03-07 15:06:10 +0000</bug_when>
    <thetext>We&apos;re seeing an issue where opkg sometimes fails trying to run-postinsts. This only seems to happen in systemd based images. The postinstall.log file contains:

Traceback (most recent call last):
  File &quot;/home/pokybuild/yocto-worker/qemux86-64-alt/build/meta/lib/oeqa/core/decorator/__init__.py&quot;, line 35, in wrapped_f
    return func(*args, **kwargs)
  File &quot;/home/pokybuild/yocto-worker/qemux86-64-alt/build/meta/lib/oeqa/runtime/cases/parselogs.py&quot;, line 185, in test_parselogs
    self.assertEqual(errcount, 0, msg=self.msg)
AssertionError: 1 != 0 : Log: /home/pokybuild/yocto-worker/qemux86-64-alt/build/build/tmp/work/qemux86_64-poky-linux/core-image-full-cmdline/1.0/target_logs/postinstall.log
-----------------------
Central error: * opkg_cmd_exec: Command failed to capture privilege lock: Resource temporarily unavailable.
***********************
 * opkg_lock: Could not lock /run/opkg.lock: Resource temporarily unavailable.
 * opkg_cmd_exec: Command failed to capture privilege lock: Resource temporarily unavailable.
***********************
1 errors found in logs.

https://autobuilder.yoctoproject.org/typhoon/#/builders/109/builds/7500/steps/14/logs/stdio (core-image-full-cmdline, alma9-ty-2, qemux86-64-alt)
https://autobuilder.yoctoproject.org/typhoon/#/builders/101/builds/7406/steps/14/logs/stdio (core-image-full-cmdline, fedora39-ty-2, qemux86-alt)
https://autobuilder.yoctoproject.org/typhoon/#/builders/109/builds/7496/steps/13/logs/stdio (core-image-full-cmdline, fedora38-ty-3, qemux86-64-alt)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98412</commentid>
    <comment_count>1</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2024-03-07 15:17:15 +0000</bug_when>
    <thetext>Added Qi and Changqing in case they have some idea of how systemd could be involved in this opkg lock problem. We (WR) don&apos;t use opkg but we can help if we have an idea of what the underlying problem is.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98421</commentid>
    <comment_count>2</comment_count>
    <who name="Tim Orling">tim.orling</who>
    <bug_when>2024-03-07 16:04:40 +0000</bug_when>
    <thetext>RP suggested putting a wrapper around the opkg calls to emit what it is trying to install/do.

His instinct/hunch is also that it is systemd related.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98430</commentid>
    <comment_count>3</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2024-03-07 23:16:12 +0000</bug_when>
    <thetext>Two failures in https://autobuilder.yoctoproject.org/typhoon/#/builders/101/builds/7411/steps/14/logs/stdio core-image-full-cmdline and core-image-sato-sdk</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98431</commentid>
    <comment_count>4</comment_count>
    <who name="Tim Orling">tim.orling</who>
    <bug_when>2024-03-08 00:02:33 +0000</bug_when>
    <thetext>That build was Worker: alma9-ty-2</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98432</commentid>
    <comment_count>5</comment_count>
    <who name="Chen Qi">Qi.Chen</who>
    <bug_when>2024-03-08 02:26:45 +0000</bug_when>
    <thetext>Hi All,

If this is only failing for systemd, then my guess is that the problem might be related to the &apos;DefaultDependencies=no&apos; setting in meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts.service.

Both sysvinit and systemd are only running &apos;run-postinsts&apos;, but sysvinit is using &apos;INITSCRIPT_PARAMS = &quot;start 99 S .&quot;&apos;, this means the script is run as the last script in /etc/rcS.d.

Regards,
Qi</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98433</commentid>
    <comment_count>6</comment_count>
    <who name="Chen Qi">Qi.Chen</who>
    <bug_when>2024-03-08 02:46:44 +0000</bug_when>
    <thetext>Sorry about the noise. Giving it a second thought, I found my above comment useless.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98434</commentid>
    <comment_count>7</comment_count>
    <who name="Tim Orling">tim.orling</who>
    <bug_when>2024-03-08 05:52:08 +0000</bug_when>
    <thetext>Each of the /var/lib/opkg/info/${PN}.postinst scripts has `set -e` in it, so I thought let&apos;s try removing that. Hoping to catch failures as they happen.

I&apos;m trying a couple builds with only that commit now to see if they fail.

The run-postinst.service has no retry or timeout capability, so I thought let us try adding that.

I tried a couple builds with both commits and they did not fail.

https://git.yoctoproject.org/poky-contrib/log/?h=timo/opkg_postinst_15428

In my attempts, I am trying to only test on the combinations that have previously failed:

qemux86-64-alt, qemux86-alt
alma9-ty-2, fedora39-ty-2, fedora38-ty-3

If there is an &quot;easy&quot; way to script staging builds (and then basically looping them) it would help a lot. I suppose this is a case for a custom branch of yocto-autobuilder-helper...

I locally tested the culprit image targets in loops of 100 and 50 and they did not fail (sadly, not 100% confident I am replicating the test configuration). These loops were not with the above branch... just with master-next. I have no reason to suspect host distro is a factor, but my host is ubuntu-22.04 on AMD x86-64. So far the failures are on &quot;rpm&quot; based distros. 

I&apos;d like to loop on the AB (once a build finishes, run it again for N runs with the same configuration on the same worker) to try to get some statistics on how frequent the failure is (and while also trying to further instrument the failure). Back a few years ago when we had intermittent (and much rarer) failures, Randy Witt would loop in docker containers for something like 100,000 runs over a weekend to get a reliable fingerprint of the culprit. As I recall that failure (something rare in bitbake) was about a 0.3% failure rate...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98435</commentid>
    <comment_count>8</comment_count>
    <who name="Tim Orling">tim.orling</who>
    <bug_when>2024-03-08 06:04:09 +0000</bug_when>
    <thetext>I just realized `set -e` is &quot;Exit immediately if a command exits with a non-zero status.&quot; which is probably what we want. Turning that off will probably give us bizarre delayed errors, if any (like we have now?).

When I am less brain fogged I will take another look at better instrumentation of the opkg run-postinsts. Probably `set -x` &quot;Print commands and their arguments as they are executed.&quot; will help, but that will be more code, adding a &quot;def add_set_x_to_scriptlets(pkg):&quot; or maybe just replace all instances of `set -e` with `set -x` in all the scriptlets to make it &quot;easy&quot;.

https://git.yoctoproject.org/poky/tree/meta/lib/oe/packagedata.py#n209</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98443</commentid>
    <comment_count>9</comment_count>
    <who name="Tim Orling">tim.orling</who>
    <bug_when>2024-03-09 04:01:08 +0000</bug_when>
    <thetext>Trying a new testing branch (set -e -x for opkg postinsts):

https://git.yoctoproject.org/poky-contrib/tree/?h=timo/opkg_postinst_debug

alma-9-ty-2, qemux86-64-alt</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98445</commentid>
    <comment_count>10</comment_count>
    <who name="Tim Orling">tim.orling</who>
    <bug_when>2024-03-09 18:51:05 +0000</bug_when>
    <thetext>Related query on the mailing list:
https://lore.kernel.org/all/CAMKF1spKdnjMFpD=Qf_1vCzOeAN-Xg5GqQJviNLPXRq6md-tbQ@mail.gmail.com/T/</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98478</commentid>
    <comment_count>11</comment_count>
    <who name="Tim Orling">tim.orling</who>
    <bug_when>2024-03-14 15:09:45 +0000</bug_when>
    <thetext>RP&apos;s idea was to replace opkg binary with a script that appends the opkg call/arguments, process number, dump the process tree at the time. Trying to figure out if two things are running at the same time.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98479</commentid>
    <comment_count>12</comment_count>
    <who name="Tim Orling">tim.orling</who>
    <bug_when>2024-03-14 15:15:44 +0000</bug_when>
    <thetext>Re-running https://autobuilder.yoctoproject.org/typhoon/#/builders/101/builds/7411/steps/14/logs/stdio

did not fail

https://autobuilder.yoctoproject.org/typhoon/#/builders/101/builds/7446</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98500</commentid>
    <comment_count>13</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2024-03-16 17:07:19 +0000</bug_when>
    <thetext>I had a look at an opkg created core-image-full-cmdline and what is interesting is that run-postinsts is removed at the end of rootfs construction as there are no deferred postinsts in the image.

I checked a failed build on the autobuilder and confirmed that a failed image did not have any deferred postinsts and did not have run-postinsts installed.

I also confirmed the systemd logs do show a run-postinsts service being added/removed in the failed build.

What this tells us is that it is likely the opkg test case itself:

oeqa/runtime/cases/opkg.py:        self.pkg(&apos;remove run-postinsts-dev&apos;)
oeqa/runtime/cases/opkg.py:        self.pkg(&apos;install run-postinsts-dev&apos;)

is the thing which is installing/running the postinsts package and perhaps the package manager itself racing against the systemd service running.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98501</commentid>
    <comment_count>14</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2024-03-16 17:08:29 +0000</bug_when>
    <thetext>I&apos;d also note you can log opkg activity both during rootfs construction and on target with:

diff --git a/meta/recipes-devtools/opkg/opkg/wrapper b/meta/recipes-devtools/opkg/opkg/wrapper
new file mode 100644
index 00000000000..0e8902771f0
--- /dev/null
+++ b/meta/recipes-devtools/opkg/opkg/wrapper
@@ -0,0 +1,8 @@
+#!/bin/bash
+realpath=`readlink -fn $0`
+realdir=`dirname $realpath`
+echo &quot;New call $$&quot; &gt;&gt; /tmp/opkglog
+date &gt;&gt; /tmp/opkglog
+ps &gt;&gt; /tmp/opkglog
+echo &quot;$@&quot; &gt;&gt; /tmp/opkglog
+exec -a $realdir/opkg $realdir/opkg.real &quot;$@&quot;
diff --git a/meta/recipes-devtools/opkg/opkg_0.6.3.bb b/meta/recipes-devtools/opkg/opkg_0.6.3.bb
index 9592ffc5d6d..7f42b8ed7bc 100644
--- a/meta/recipes-devtools/opkg/opkg_0.6.3.bb
+++ b/meta/recipes-devtools/opkg/opkg_0.6.3.bb
@@ -17,6 +17,7 @@ SRC_URI = &quot;http://downloads.yoctoproject.org/releases/${BPN}/${BPN}-${PV}.tar.gz
            file://0001-opkg_conf-create-opkg.lock-in-run-instead-of-var-run.patch \
            file://0001-libopkg-Use-libgen.h-to-provide-basename-API.patch \
            file://run-ptest \
+           file://wrapper \
            &quot;
 
 SRC_URI[sha256sum] = &quot;f3938e359646b406c40d5d442a1467c7e72357f91ab822e442697529641e06de&quot;
@@ -54,6 +55,8 @@ do_install:append () {
 
        # We need to create the lock directory
        install -d ${D}${OPKGLIBDIR}/opkg
+       mv ${D}${bindir}/opkg ${D}${bindir}/opkg.real
+       install -m 0755 ${WORKDIR}/wrapper ${D}${bindir}/opkg
 }
 
 do_install_ptest () {
@@ -70,7 +73,7 @@ def qa_check_solver_deprecation (pn, d, messages):
         oe.qa.handle_error(&quot;internal-solver-deprecation&quot;, &quot;The opkg internal solver will be deprecated in future opkg releases. Consider enabling \&quot;libsolv\&quot; in PACKAGECONFIG.&quot;, d)
 
 
-RDEPENDS:${PN} = &quot;${VIRTUAL-RUNTIME_update-alternatives} opkg-arch-config libarchive&quot;
+RDEPENDS:${PN} = &quot;${VIRTUAL-RUNTIME_update-alternatives} opkg-arch-config libarchive bash&quot;
 RDEPENDS:${PN}:class-native = &quot;&quot;
 RDEPENDS:${PN}:class-nativesdk = &quot;&quot;
 RDEPENDS:${PN}-ptest += &quot;make binutils python3-core python3-compression bash python3-crypt python3-io&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98504</commentid>
    <comment_count>15</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2024-03-16 21:23:03 +0000</bug_when>
    <thetext>The on target command sequence triggered by the tests is:

opkg update
opkg remove run-postinsts-dev
opkg install run-postinsts-dev
configure

where configure is being run by run-postinsts</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98505</commentid>
    <comment_count>16</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2024-03-16 21:48:36 +0000</bug_when>
    <thetext>Which leads to a reproducer:

diff --git a/meta/classes-recipe/systemd.bbclass b/meta/classes-recipe/systemd.bbclass
index 48b364c1d4d..3bb28442bd1 100644
--- a/meta/classes-recipe/systemd.bbclass
+++ b/meta/classes-recipe/systemd.bbclass
@@ -49,6 +49,7 @@ if systemctl &gt;/dev/null 2&gt;/dev/null; then
                if [ &quot;${SYSTEMD_AUTO_ENABLE}&quot; = &quot;enable&quot; ]; then
                        systemctl --no-block restart ${SYSTEMD_SERVICE_ESCAPED}
                fi
+               sleep 5
        fi
 fi
 }

then bitbake core-image-full-cmdline -c testimage</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98560</commentid>
    <comment_count>17</comment_count>
    <who name="Tim Orling">tim.orling</who>
    <bug_when>2024-03-21 14:49:18 +0000</bug_when>
    <thetext>*** Bug 15450 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98569</commentid>
    <comment_count>18</comment_count>
    <who name="Tim Orling">tim.orling</who>
    <bug_when>2024-03-21 16:49:08 +0000</bug_when>
    <thetext>Looks like a do-while loop in opkg_lock() is working:
https://autobuilder.yoctoproject.org/typhoon/#/builders/109/builds/7578

https://git.yoctoproject.org/poky-contrib/commit/?h=timo/opkg_postinst_debug&amp;id=10786c2391e3272db4231de93c706f82239c7965

Patch submitted to upstream opkg:
https://lists.yoctoproject.org/g/opkg/message/60

Patch submitted for interim fix:
https://patchwork.yoctoproject.org/project/oe-core/patch/20240321164744.3007283-1-tim.orling@konsulko.com/</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98574</commentid>
    <comment_count>19</comment_count>
    <who name="Tim Orling">tim.orling</who>
    <bug_when>2024-03-21 20:36:38 +0000</bug_when>
    <thetext>Working in parallel on the other approach (flock in run-postinsts itself):

https://git.yoctoproject.org/poky-contrib/log/?h=timo/opkg_lock_flock_run-postinsts

Brings up an interesting failure that I saw on target when trying to manually
run the opkg oeqa runtime test steps previously:

Traceback (most recent call last):
  File &quot;.../workspace-upgrades/build/../poky/meta/lib/oeqa/core/decorator/__init__.py&quot;, line 35, in wrapped_f
    return func(*args, **kwargs)
  File &quot;.../workspace-upgrades/build/../poky/meta/lib/oeqa/core/decorator/__init__.py&quot;, line 35, in wrapped_f
    return func(*args, **kwargs)
  [Previous line repeated 1 more time]
  File &quot;.../workspace-upgrades/poky/meta/lib/oeqa/runtime/cases/opkg.py&quot;, line 59, in test_opkg_install_from_repo
    self.pkg(&apos;install run-postinsts-dev&apos;)
  File &quot;.../workspace-upgrades/poky/meta/lib/oeqa/runtime/cases/opkg.py&quot;, line 19, in pkg
    self.assertEqual(status, expected, message)
AssertionError: 255 != 0 : opkg install run-postinsts-dev
 * opkg_prepare_url_for_install: Couldn&apos;t find anything to satisfy &apos;run-postinsts-dev&apos;.

I assume it needs an ipk package-feed to work in this case (after removing the
run-postinsts-dev package, it tries to install the same package and then run configure)?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98578</commentid>
    <comment_count>20</comment_count>
    <who name="Chen Qi">Qi.Chen</who>
    <bug_when>2024-03-22 03:01:51 +0000</bug_when>
    <thetext>I just found a related issue.
We&apos;re using the same SYSTEMD_AUTO_ENABLE variable to control two different actions: enable &amp; start/restart after target installation.

The related codes are:
systemd_postinst() {
if systemctl &gt;/dev/null 2&gt;/dev/null; then
        OPTS=&quot;&quot;

        if [ -n &quot;$D&quot; ]; then
                OPTS=&quot;--root=$D&quot;
        fi

        if [ &quot;${SYSTEMD_AUTO_ENABLE}&quot; = &quot;enable&quot; ]; then
                for service in ${SYSTEMD_SERVICE_ESCAPED}; do
                        systemctl ${OPTS} enable &quot;$service&quot;
                done
        fi

        if [ -z &quot;$D&quot; ]; then
                systemctl daemon-reload
                systemctl preset ${SYSTEMD_SERVICE_ESCAPED}

                if [ &quot;${SYSTEMD_AUTO_ENABLE}&quot; = &quot;enable&quot; ]; then
                        systemctl --no-block restart ${SYSTEMD_SERVICE_ESCAPED}
                fi
        fi
fi
}

A new variable seems needed. Not sure its suitable name. SYSTEMD_AUTO_START_AFTER_TARGET_INSTALLATION?

The run-postinsts script is not run when installed on sysvinit targets, but it&apos;s run on systemd targets. It seems that this service should be enabled but not immediately started/restarted when installed on target.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98589</commentid>
    <comment_count>21</comment_count>
    <who name="João Marcos Costa">joaomarcos.costa</who>
    <bug_when>2024-03-22 16:15:57 +0000</bug_when>
    <thetext>https://autobuilder.yoctoproject.org/typhoon/#/builders/109/builds/7572/steps/14/logs/stdio

qemux86-64-alt debian11-ty-1

Traceback (most recent call last):
  File &quot;/home/pokybuild/yocto-worker/qemux86-64-alt/build/meta/lib/oeqa/core/decorator/__init__.py&quot;, line 35, in wrapped_f
    return func(*args, **kwargs)
  File &quot;/home/pokybuild/yocto-worker/qemux86-64-alt/build/meta/lib/oeqa/runtime/cases/parselogs.py&quot;, line 185, in test_parselogs
    self.assertEqual(errcount, 0, msg=self.msg)
AssertionError: 1 != 0 : Log: /home/pokybuild/yocto-worker/qemux86-64-alt/build/build/tmp/work/qemux86_64-poky-linux/core-image-full-cmdline/1.0/target_logs/postinstall.log
-----------------------
Central error: * opkg_cmd_exec: Command failed to capture privilege lock: Resource temporarily unavailable.
***********************
 * opkg_lock: Could not lock /run/opkg.lock: Resource temporarily unavailable.
 * opkg_cmd_exec: Command failed to capture privilege lock: Resource temporarily unavailable.
***********************
1 errors found in logs.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98596</commentid>
    <comment_count>22</comment_count>
    <who name="Tim Orling">tim.orling</who>
    <bug_when>2024-03-22 20:17:44 +0000</bug_when>
    <thetext>(In reply to Chen Qi from comment #20)
&gt; I just found a related issue.
&gt; We&apos;re using the same SYSTEMD_AUTO_ENABLE variable to control two different
&gt; actions: enable &amp; start/restart after target installation.

restart is clearly the problem :)

&gt; 
&gt; The related codes are:
&gt; systemd_postinst() {
&gt; if systemctl &gt;/dev/null 2&gt;/dev/null; then
&gt;         OPTS=&quot;&quot;
&gt; 
&gt;         if [ -n &quot;$D&quot; ]; then
&gt;                 OPTS=&quot;--root=$D&quot;
&gt;         fi
&gt; 
&gt;         if [ &quot;${SYSTEMD_AUTO_ENABLE}&quot; = &quot;enable&quot; ]; then
&gt;                 for service in ${SYSTEMD_SERVICE_ESCAPED}; do
&gt;                         systemctl ${OPTS} enable &quot;$service&quot;
&gt;                 done
&gt;         fi
&gt; 
&gt;         if [ -z &quot;$D&quot; ]; then
&gt;                 systemctl daemon-reload
&gt;                 systemctl preset ${SYSTEMD_SERVICE_ESCAPED}
&gt; 
&gt;                 if [ &quot;${SYSTEMD_AUTO_ENABLE}&quot; = &quot;enable&quot; ]; then
&gt;                         systemctl --no-block restart
&gt; ${SYSTEMD_SERVICE_ESCAPED}
&gt;                 fi
&gt;         fi
&gt; fi
&gt; }
&gt; 
&gt; A new variable seems needed. Not sure its suitable name.
&gt; SYSTEMD_AUTO_START_AFTER_TARGET_INSTALLATION?

Interesting idea. I somehow think some kind of &quot;smarter&quot; systemd service
dependencies/rules would help.

I did try a little bit of investigation into the service itself, although
I am not claiming to be fully understanding all the nuances of this bug.

diff --git a/meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts.service b/meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts.service
index b6b81d5c1a1..19331d656a5 100644
--- a/meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts.service
+++ b/meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts.service
@@ -1,6 +1,7 @@
 [Unit]
 Description=Run pending postinsts
 DefaultDependencies=no
+StartLimitIntervalSec=5
 After=systemd-remount-fs.service systemd-tmpfiles-setup.service tmp.mount ldconfig.service
 Before=sysinit.target
 
@@ -9,7 +10,10 @@ Type=oneshot
 ExecStart=#SBINDIR#/run-postinsts
 ExecStartPost=#BASE_BINDIR#/systemctl --no-reload disable run-postinsts.service
 RemainAfterExit=yes
-TimeoutSec=0
+TimeoutSec=1
+Restart=on-failure
+RestartSec=1
+StartLimitBurst=3
 
 [Install]
 WantedBy=sysinit.target

&gt; 
&gt; The run-postinsts script is not run when installed on sysvinit targets, but
&gt; it&apos;s run on systemd targets. It seems that this service should be enabled
&gt; but not immediately started/restarted when installed on target.

As I understand it, the rust-postinsts script _is_ run for sysvinit?
https://git.yoctoproject.org/poky/tree/meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts.init

#!/bin/sh

run-postinsts</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98601</commentid>
    <comment_count>23</comment_count>
    <who name="Chen Qi">Qi.Chen</who>
    <bug_when>2024-03-25 05:48:07 +0000</bug_when>
    <thetext>(In reply to Tim Orling from comment #22)
&gt; (In reply to Chen Qi from comment #20)
&gt; &gt; I just found a related issue.
&gt; &gt; We&apos;re using the same SYSTEMD_AUTO_ENABLE variable to control two different
&gt; &gt; actions: enable &amp; start/restart after target installation.
&gt; 
&gt; restart is clearly the problem :)
&gt; 
&gt; &gt; 
&gt; &gt; The related codes are:
&gt; &gt; systemd_postinst() {
&gt; &gt; if systemctl &gt;/dev/null 2&gt;/dev/null; then
&gt; &gt;         OPTS=&quot;&quot;
&gt; &gt; 
&gt; &gt;         if [ -n &quot;$D&quot; ]; then
&gt; &gt;                 OPTS=&quot;--root=$D&quot;
&gt; &gt;         fi
&gt; &gt; 
&gt; &gt;         if [ &quot;${SYSTEMD_AUTO_ENABLE}&quot; = &quot;enable&quot; ]; then
&gt; &gt;                 for service in ${SYSTEMD_SERVICE_ESCAPED}; do
&gt; &gt;                         systemctl ${OPTS} enable &quot;$service&quot;
&gt; &gt;                 done
&gt; &gt;         fi
&gt; &gt; 
&gt; &gt;         if [ -z &quot;$D&quot; ]; then
&gt; &gt;                 systemctl daemon-reload
&gt; &gt;                 systemctl preset ${SYSTEMD_SERVICE_ESCAPED}
&gt; &gt; 
&gt; &gt;                 if [ &quot;${SYSTEMD_AUTO_ENABLE}&quot; = &quot;enable&quot; ]; then
&gt; &gt;                         systemctl --no-block restart
&gt; &gt; ${SYSTEMD_SERVICE_ESCAPED}
&gt; &gt;                 fi
&gt; &gt;         fi
&gt; &gt; fi
&gt; &gt; }
&gt; &gt; 
&gt; &gt; A new variable seems needed. Not sure its suitable name.
&gt; &gt; SYSTEMD_AUTO_START_AFTER_TARGET_INSTALLATION?
&gt; 
&gt; Interesting idea. I somehow think some kind of &quot;smarter&quot; systemd service
&gt; dependencies/rules would help.
&gt; 
&gt; I did try a little bit of investigation into the service itself, although
&gt; I am not claiming to be fully understanding all the nuances of this bug.
&gt; 
&gt; diff --git
&gt; a/meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts.service
&gt; b/meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts.service
&gt; index b6b81d5c1a1..19331d656a5 100644
&gt; --- a/meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts.service
&gt; +++ b/meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts.service
&gt; @@ -1,6 +1,7 @@
&gt;  [Unit]
&gt;  Description=Run pending postinsts
&gt;  DefaultDependencies=no
&gt; +StartLimitIntervalSec=5
&gt;  After=systemd-remount-fs.service systemd-tmpfiles-setup.service tmp.mount
&gt; ldconfig.service
&gt;  Before=sysinit.target
&gt;  
&gt; @@ -9,7 +10,10 @@ Type=oneshot
&gt;  ExecStart=#SBINDIR#/run-postinsts
&gt;  ExecStartPost=#BASE_BINDIR#/systemctl --no-reload disable
&gt; run-postinsts.service
&gt;  RemainAfterExit=yes
&gt; -TimeoutSec=0
&gt; +TimeoutSec=1
&gt; +Restart=on-failure
&gt; +RestartSec=1
&gt; +StartLimitBurst=3
&gt;  
&gt;  [Install]
&gt;  WantedBy=sysinit.target
&gt; 
&gt; &gt; 
&gt; &gt; The run-postinsts script is not run when installed on sysvinit targets, but
&gt; &gt; it&apos;s run on systemd targets. It seems that this service should be enabled
&gt; &gt; but not immediately started/restarted when installed on target.
&gt; 
&gt; As I understand it, the rust-postinsts script _is_ run for sysvinit?
&gt; https://git.yoctoproject.org/poky/tree/meta/recipes-devtools/run-postinsts/
&gt; run-postinsts/run-postinsts.init
&gt; 
&gt; #!/bin/sh
&gt; 
&gt; run-postinsts

For target installation, this run-postinsts.init script is installed and then enabled by update-rc.d, but it&apos;s not run immediately after the installation.
This difference makes this bug systemd specific, as it&apos;s run immediately after installation in systemd systems.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98628</commentid>
    <comment_count>24</comment_count>
    <who name="Alexandre Belloni">alexandre.belloni</who>
    <bug_when>2024-03-27 19:35:45 +0000</bug_when>
    <thetext>https://autobuilder.yoctoproject.org/typhoon/#/builders/101/builds/7487

qemux86-alt fedora38-ty-6</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98630</commentid>
    <comment_count>25</comment_count>
    <who name="Alexandre Belloni">alexandre.belloni</who>
    <bug_when>2024-03-27 20:19:43 +0000</bug_when>
    <thetext>https://autobuilder.yoctoproject.org/typhoon/#/builders/101/builds/7502/steps/14/logs/stdio

qemux86-alt fedora38-ty-3</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98636</commentid>
    <comment_count>26</comment_count>
    <who name="Alexandre Belloni">alexandre.belloni</who>
    <bug_when>2024-03-27 21:31:25 +0000</bug_when>
    <thetext>https://autobuilder.yoctoproject.org/typhoon/#/builders/109/builds/7496/steps/13/logs/stdio

qemux86-64-alt fedora38-ty-3</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98643</commentid>
    <comment_count>27</comment_count>
    <who name="Alexandre Belloni">alexandre.belloni</who>
    <bug_when>2024-03-27 21:56:46 +0000</bug_when>
    <thetext>https://autobuilder.yoctoproject.org/typhoon/#/builders/109/builds/7554/steps/14/logs/stdio

qemux86-64-alt debian12-ty-1</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98645</commentid>
    <comment_count>28</comment_count>
    <who name="Alexandre Belloni">alexandre.belloni</who>
    <bug_when>2024-03-27 22:01:47 +0000</bug_when>
    <thetext>https://autobuilder.yoctoproject.org/typhoon/#/builders/109/builds/7500/steps/14/logs/stdio

qemux86-64-alt alma9-ty-2</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98649</commentid>
    <comment_count>29</comment_count>
    <who name="Alexandre Belloni">alexandre.belloni</who>
    <bug_when>2024-03-27 22:31:45 +0000</bug_when>
    <thetext>https://autobuilder.yoctoproject.org/typhoon/#/builders/101/builds/7451/steps/15/logs/stdio
qemux86-alt opensuse154-ty-3</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98679</commentid>
    <comment_count>30</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2024-03-30 22:34:44 +0000</bug_when>
    <thetext>I think there may be a better way to do this with opkg support but for now, work around it:

https://git.yoctoproject.org/poky/commit/?id=7c916d8f1bfd6b8036311d534a08b2f71464a3cd</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>