Yocto: bbappend file which remove System V init script
Asked Answered
K

2

6

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

Keelung answered 25/8, 2016 at 11:50 Comment(1)
I'm only guessing, but what if you name the function do_install_append()?Ascending
K
6

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!

Kowtow answered 5/11, 2018 at 21:59 Comment(2)
Or you could just use INITSCRIPT_PARAMS = "disable"Bierce
Turns out I'm wrong. The version shipped with Yocto (Sumo) doesn't have this option while Ubuntu 16.04 does. My apologies.Bierce
M
2

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 ."?
Mchenry answered 25/8, 2016 at 16:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.