Yocto:删除System V init脚本的bbappend文件

时间:2016-08-25 11:50:28

标签: init yocto bitbake recipe

我目前正在使用Yocto安装dnsmasq,但我想删除自动启动。

所以我创建了一个.bbappend文件,我尝试了类似的东西:

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

但它不起作用,我不知道如何继续使用bbappend文件删除此init脚本。

谢谢,Pierre-Olivier

2 个答案:

答案 0 :(得分:2)

有几件事:

  • 也许你正在使用systemd?
  • 也许你的食谱错误了吗?
  • 也许你应该尝试update-rc.d -f dnsmasq remove(注意-f应该在名字前面)
  • 也许您应该尝试覆盖INITSCRIPT_PARAMS,如INITSCRIPT_PARAMS = "stop 20 0 1 6 ."

答案 1 :(得分:2)

在SysV下禁用服务的正确方法是使用INITSCRIPT_PARAMS

来自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.

让我重申

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

但是如何知道默认情况下启动服务的所有运行级别? 好吧,如果/etc/init.d/script不存在“ update-rc.d LSB标头” (Yocto中的NGINX就是这种情况-我以它为例), 那么很简单:

  • 运行级别0-关闭,默认情况下=>在此运行级别停止服务
  • 运行级别1-单用户模式,=>通常在此运行级别停止服务
  • 运行级别6-重新启动,=>很简单:在此运行级别停止服务

NGINX由Yocto nginx.inc层下的meta-openembedded文件描述:

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

NGINX在nginx.inc文件中定义了以下初始脚本:

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

Yocto rootfs中产生的服务启动/杀死符号链接为:

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

此外,这可以通过update-rc.d.bbclass的执行来确认 update-rc.d在rootfs创建期间。因此,update-rc.d的方式是 在meta/classes/update-rc.d.bbclass文件中调用的是:

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

宾果!

结论

要在Yocto下禁用SysV中的服务,我们需要定义:

INITSCRIPT_PARAMS = "stop 20 0 1 6 ."

但是如何验证生成的INITSCRIPT_PARAMS?

有效的INITSCRIPT_PARAMS环境变量应 在重新创建rootfs之前先进行验证。正确而简单的方法 再次使用出色的bitbake命令:

bitbake nginx -e | grep INITSCRIPT_PARAMS

现在,让我们重新创建图像(在我的情况下为core-image-full-cmdline):

bitbake core-image-full-cmdline

现在我们可以很容易地看到,所有剩余的Start / Kill符号链接是:

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

宾果游戏再次出现!