Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yocto: bbappend file which remove System V init script

I'm currently installing dnsmasq with Yocto, but I would like to remove the automatic start.

So I create a .bbappend file and I tried something like :

pkg_postinst_${PN} () {
    update-rc.d dnsmasq -f remove
}

But it did not work, I don't know how to proceed to remove this init script with a bbappend file.

Thanks, Pierre-Olivier

like image 308
PierreOlivier Avatar asked Aug 25 '16 11:08

PierreOlivier


People also ask

What is Bbappend file in yocto?

bbappend file is to reference a modified version of the startup script to be copied in place of the original without changing the base openembedded-core and/or poky environments.

What is the difference between BB and Bbappend?

bbappend file resides in your layer, while the main . bb recipe file to which you are appending Metadata resides in a different layer. Being able to append information to an existing recipe not only avoids duplication, but also automatically applies recipe changes from a different layer into your layer.

What is Do_install_append?

The do_install_append function appends the provided block below the metadata already available in the original do_install function. It includes the command needed to copy our new configuration file into the package filesystem.


2 Answers

The correct way to disable a service under SysV is with INITSCRIPT_PARAMS:

From man update-rc.d

A  common  system administration error is to delete the links with
the thought that this will "disable" the service, i.e., that this
will pre‐ vent the service from being started.  However, if all links
have been deleted then the next  time  the  package  is  upgraded,
the  package's postinst  script will run update-rc.d again and this
will reinstall links at their factory default locations.  The correct
way to disable services is to configure the service as stopped in
all runlevels in which it is started by default.  In the  System  V
init  system  this  means renaming the service's symbolic links from
S to K.

Let me to reiterate

The correct way to disable services is to configure
the service as stopped in all runlevels in which it
is started by default.

But how we can know all runlevels in which a service is started by default? Well, if "update-rc.d LSB header" does not exist for /etc/init.d/script (which is the case for NGINX in Yocto - I use it as an example), then it is simple:

  • runlevel 0 - shutdown, => by default stop a service at this runlevel
  • runlevel 1 - single user mode, => usually stop a service at this runlevel
  • runlevel 6 - reboot, => that's trivial: stop a service at this runlevel

NGINX is described by nginx.inc file under Yocto meta-openembedded layer:

meta-openembedded/meta-webserver/recipes-httpd/nginx/nginx.inc

NGINX defines initial scripts as follows in nginx.inc file:

INITSCRIPT_NAME = "nginx"
INITSCRIPT_PARAMS = "defaults 92 20"

And the resulting service Start/Kill symlinks in Yocto rootfs are:

rootfs/etc/rc0.d/K20nginx -> ../init.d/nginx # Shutdown runlevel
rootfs/etc/rc1.d/K20nginx -> ../init.d/nginx # Single user mode runlevel
rootfs/etc/rc2.d/S92nginx -> ../init.d/nginx
rootfs/etc/rc3.d/S92nginx -> ../init.d/nginx
rootfs/etc/rc4.d/S92nginx -> ../init.d/nginx
rootfs/etc/rc5.d/S92nginx -> ../init.d/nginx
rootfs/etc/rc6.d/K20nginx -> ../init.d/nginx # Reboot runlevel

Also, this is confirmed by the update-rc.d.bbclass thas executes update-rc.d during rootfs creation. So, the way update-rc.d is called in meta/classes/update-rc.d.bbclass file is:

update-rc.d $OPT ${INITSCRIPT_NAME} ${INITSCRIPT_PARAMS}

Bingo!

Conclusion

To disable a service in SysV under Yocto we need to define:

INITSCRIPT_PARAMS = "stop 20 0 1 6 ."

But how to verify the resulting INITSCRIPT_PARAMS?

The effective INITSCRIPT_PARAMS environment variable should be verified before re-creating rootfs. The proper and simple way to do it is again using the great bitbake command:

bitbake nginx -e | grep INITSCRIPT_PARAMS

Now, let's re-create the image (core-image-full-cmdline in my case):

bitbake core-image-full-cmdline

We can easily see now, that all the remaining Start/Kill symlinks are:

rootfs/etc/rc0.d/K20nginx -> ../init.d/nginx # Shutdown runlevel
rootfs/etc/rc1.d/K20nginx -> ../init.d/nginx # Single user mode runlevel
rootfs/etc/rc6.d/K20nginx -> ../init.d/nginx # Reboot runlevel

Bingo once again!

like image 182
KostaZ Avatar answered Sep 28 '22 00:09

KostaZ


Several things:

  • maybe you're using systemd?
  • maybe you're bbappending to a wrong version of recipe?
  • maybe you should try update-rc.d -f dnsmasq remove (notice that -f should be in front of name)
  • maybe you should try overriding INITSCRIPT_PARAMS like INITSCRIPT_PARAMS = "stop 20 0 1 6 ."?
like image 31
Roman Khimov Avatar answered Sep 28 '22 00:09

Roman Khimov