<div dir="ltr">Hi,<br><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Pau Espin Pedrol<br></div></div></div></div>
<br><div class="gmail_quote">2016-09-08 4:33 GMT+02:00 ChenQi <span dir="ltr">&lt;<a href="mailto:Qi.Chen@windriver.com" target="_blank">Qi.Chen@windriver.com</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000"><div><div class="h5">
    <div>On 09/07/2016 08:14 PM, Pau Espin
      Pedrol wrote:<br>
    </div>
    <blockquote type="cite">
      
      <div dir="ltr"><br>
        <div class="gmail_extra">
          <div class="gmail_quote">2016-09-07 11:22 GMT+02:00 Chen Qi <span dir="ltr">&lt;<a href="mailto:Qi.Chen@windriver.com" target="_blank">Qi.Chen@windriver.com</a>&gt;</span>:<br>
            <blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">Add new variable SYSTEMD_USER_SERVICE
              and SYSTEM_USER_AUTO_ENABLE<br>
              to manage user services. Their usage is like
              SYSTEMD_SERVICE and<br>
              SYSTEMD_AUTO_ENABLE.<br>
              <br>
              [YOCTO #7800]<br>
              <br>
              Signed-off-by: Chen Qi &lt;<a href="mailto:Qi.Chen@windriver.com" target="_blank">Qi.Chen@windriver.com</a>&gt;<br>
              ---<br>
               meta/classes/systemd.bbclass | 17 +++++++++++++----<br>
               1 file changed, 13 insertions(+), 4 deletions(-)<br>
              <br>
              diff --git a/meta/classes/systemd.bbclass
              b/meta/classes/systemd.bbclass<br>
              index db7873f..78cec97 100644<br>
              --- a/meta/classes/systemd.bbclass<br>
              +++ b/meta/classes/systemd.bbclass<br>
              @@ -7,6 +7,7 @@ SYSTEMD_PACKAGES_class-natives<wbr>dk ?=
              &quot;&quot;<br>
              <br>
               # Whether to enable or disable the services on
              installation.<br>
               SYSTEMD_AUTO_ENABLE ??= &quot;enable&quot;<br>
              +SYSTEMD_USER_AUTO_ENABLE ??= &quot;enable&quot;<br>
              <br>
               # This class will be included in any recipe that supports
              systemd init scripts,<br>
               # even if systemd is not in DISTRO_FEATURES.  As such
              don&#39;t make any changes<br>
              @@ -30,10 +31,14 @@ fi<br>
              <br>
               if type systemctl &gt;/dev/null 2&gt;/dev/null; then<br>
                      systemctl $OPTS ${SYSTEMD_AUTO_ENABLE}
              ${SYSTEMD_SERVICE}<br>
              +       systemctl $OPTS --global
              ${SYSTEMD_USER_AUTO_ENABLE} ${SYSTEMD_USER_SERVICE} <br>
            </blockquote>
            <div><br>
            </div>
            <div>I&#39;m not sure having these 2 systemctl being executed
              together everytime is a good idea. What if a recipe has a
              user service and no system service?</div>
          </div>
        </div>
      </div>
    </blockquote>
    <br></div></div>
    Hi Pau Espin Pedrol,<br>
    <br>
    Thanks for your review.<br>
    <br>
    The postinstall script runs successfully with expected result at
    rootfs time. But your question reminds me of the situation of the
    on-target install/remove situation. I think I&#39;ll need to make a new
    patch to make sure things work in both situations.<br>
    <br>
    The key point here is that &#39;systemctl&#39; at rootfs time is a shell
    script written by ourselves and &#39;systemctl&#39; on target is that
    provided by systemd.<span class=""><br></span></div></blockquote><div><br></div><div>Yes, I was unaware of the existance of that OE script when I worked on this. Why are we using that script at build time instead of using systemd&#39;s systemctl? Any good reason for that? git log only shows it was imported from another repo a while ago.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div bgcolor="#FFFFFF" text="#000000"><span class="">
    <br>
    <blockquote type="cite">
      <div dir="ltr">
        <div class="gmail_extra">
          <div class="gmail_quote">
            <div> We are calling the first one with an empty system
              service? Or we are may be enabling a systemd system
              service which should not be enabled according to the
              recipe? I have the feeling this kind of cases are not
              being catch in here and other pkg scripts in this commit.<br>
              <br>
            </div>
            <div>It is far from perfect, but in case you didn&#39;t, you may
              want to have a look at my initial/previous commit to try
              to fix the issue: <a href="https://www.mail-archive.com/openembedded-devel@lists.openembedded.org/msg42187.html" target="_blank">https://www.mail-archive.com/<wbr>openembedded-devel@lists.<wbr>openembedded.org/msg42187.html</a><br>
            </div>
            <div> </div>
            <blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">
              <br>
                      if [ -z &quot;$D&quot; -a &quot;${SYSTEMD_AUTO_ENABLE}&quot; =
              &quot;enable&quot; ]; then<br>
                              systemctl restart ${SYSTEMD_SERVICE}<br>
                      fi<br>
              +       if [ -z &quot;$D&quot; -a &quot;${SYSTEMD_USER_AUTO_ENABLE}&quot; =
              &quot;enable&quot; ]; then<br>
              +               systemctl --global restart
              ${SYSTEMD_USER_SERVICE}<br>
              +       fi<br>
               fi<br>
               }<br>
              <br>
              @@ -47,9 +52,11 @@ fi<br>
               if type systemctl &gt;/dev/null 2&gt;/dev/null; then<br>
                      if [ -z &quot;$D&quot; ]; then<br>
                              systemctl stop ${SYSTEMD_SERVICE}<br>
              +               systemctl --global stop
              ${SYSTEMD_USER_SERVICE}<br>
            </blockquote>
            <div><br>
            </div>
            <div>I think this is not gonna work, you cannot call
              --global with stop afair. I&#39;m not sure which is the good
              solution for this though, but you should ideally go
              through all systemd user sessions and call &quot;systemctl
              --user stop&quot;. No idea if that&#39;s actually easily feasible.<br>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br></span>
    The service is enabled and started with &#39;--global&#39; option, and
    stopping it with &#39;--global&#39; option seems reasonable to me. If
    there&#39;s some special case, let&#39;s look into it then.<br>
    <br></div></blockquote><div><br><br></div><div>Did you try running it in a running image? As in taking the ipkg, and reinstalling it live in the image with systemd&#39;s systemctl. I bet you will get an error from systemctl for both &quot;--gobal restart&quot; and &quot;--global stop&quot;. At least it used to be like that afair.<br></div><div><br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div bgcolor="#FFFFFF" text="#000000">
    Best Regards,<br>
    Chen Qi<div><div class="h5"><br>
    <br>
    <blockquote type="cite">
      <div dir="ltr">
        <div class="gmail_extra">
          <div class="gmail_quote">
            <div> </div>
            <blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">
                      fi<br>
              <br>
                      systemctl $OPTS disable ${SYSTEMD_SERVICE}<br>
              +       systemctl $OPTS --global disable
              ${SYSTEMD_USER_SERVICE}<br>
               fi<br>
               }<br>
              <br>
              @@ -139,12 +146,14 @@ python systemd_populate_packages() {<br>
                   def systemd_check_services():<br>
                       searchpaths = [oe.path.join(d.getVar(&quot;syscon<wbr>fdir&quot;,
              True), &quot;systemd&quot;, &quot;system&quot;),]<br>
                       searchpaths.append(d.getVar(&quot;<wbr>systemd_system_unitdir&quot;,
              True))<br>
              +        searchpaths.append(oe.path.joi<wbr>n(d.getVar(&quot;sysconfdir&quot;,
              True), &quot;systemd&quot;, &quot;user&quot;))<br>
              +        searchpaths.append(d.getVar(&quot;s<wbr>ystemd_user_unitdir&quot;,
              True))<br>
                       systemd_packages = d.getVar(&#39;SYSTEMD_PACKAGES&#39;,
              True)<br>
              <br>
                       keys = &#39;Also&#39;<br>
                       # scan for all in SYSTEMD_SERVICE[]<br>
                       for pkg_systemd in systemd_packages.split():<br>
              -            for service in get_package_var(d,
              &#39;SYSTEMD_SERVICE&#39;, pkg_systemd).split():<br>
              +            for service in (get_package_var(d,
              &#39;SYSTEMD_SERVICE&#39;, pkg_systemd) + get_package_var(d,
              &#39;SYSTEMD_USER_SERVICE&#39;, pkg_systemd)).split():<br>
                               path_found = &#39;&#39;<br>
              <br>
                               # Deal with adding, for example,
              &#39;<a href="mailto:ifplugd@eth0.service" target="_blank">ifplugd@eth0.service</a>&#39; from<br>
              @@ -165,14 +174,14 @@ python systemd_populate_packages() {<br>
                               if path_found != &#39;&#39;:<br>
                                   systemd_add_files_and_parse(p<wbr>kg_systemd,
              path_found, service, keys)<br>
                               else:<br>
              -                    raise bb.build.FuncFailed(&quot;SYSTEMD_S<wbr>ERVICE_%s
              value %s does not exist&quot; % \<br>
              -                        (pkg_systemd, service))<br>
              +                    raise bb.build.FuncFailed(&quot;SYSTEMD_S<wbr>ERVICE_%s
              or SYSTEMD_USER_SERVICE_%s value %s does not exist&quot; % \<br>
              +                        (pkg_systemd, pkg_systemd,
              service))<br>
              <br>
                   # Run all modifications once when creating package<br>
                   if os.path.exists(d.getVar(&quot;D&quot;, True)):<br>
                       for pkg in d.getVar(&#39;SYSTEMD_PACKAGES&#39;,
              True).split():<br>
                           systemd_check_package(pkg)<br>
              -            if d.getVar(&#39;SYSTEMD_SERVICE_&#39; + pkg, True):<br>
              +            if d.getVar(&#39;SYSTEMD_SERVICE_&#39; + pkg, True)
              or d.getVar(&#39;SYSTEMD_USER_SERVICE<wbr>_&#39; + pkg, True):<br>
                               systemd_generate_package_scri<wbr>pts(pkg)<br>
                       systemd_check_services()<br>
               }<br>
              <span><font color="#888888">--<br>
                  1.9.1<br>
                  <br>
                  --<br>
                  ______________________________<wbr>_________________<br>
                  Openembedded-core mailing list<br>
                  <a href="mailto:Openembedded-core@lists.openembedded.org" target="_blank">Openembedded-core@lists.openem<wbr>bedded.org</a><br>
                  <a rel="noreferrer" href="http://lists.openembedded.org/mailman/listinfo/openembedded-core" target="_blank">http://lists.openembedded.org/<wbr>mailman/listinfo/openembedded-<wbr>core</a><br>
                </font></span></blockquote>
          </div>
          <br>
        </div>
      </div>
    </blockquote>
    <br>
  </div></div></div>

</blockquote></div><br></div></div>