【问题标题】:Yocto: bbappend file which remove System V init scriptYocto:删除 System V 初始化脚本的 bbappend 文件
【发布时间】:2017-01-01 20:10:34
【问题描述】:

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

所以我创建了一个 .bbappend 文件并尝试了类似:

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

但它不起作用,我不知道如何继续使用 bbappend 文件删除这个初始化脚本。

谢谢,皮埃尔-奥利维尔

【问题讨论】:

  • 我只是猜测,但如果你将函数命名为 do_install_append() 会怎样?

标签: init yocto bitbake recipe


【解决方案1】:

在 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 meta-openembedded 层下的 nginx.inc 文件描述:

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

又一次宾果游戏!

【讨论】:

  • 或者你可以使用INITSCRIPT_PARAMS = "disable"
  • 原来我错了。 Yocto (Sumo) 附带的版本没有这个选项,而 Ubuntu 16.04 有。我很抱歉。
【解决方案2】:

几件事:

  • 也许您正在使用 systemd?
  • 可能您添加了错误版本的食谱?
  • 也许你应该试试update-rc.d -f dnsmasq remove(注意-f应该在名字前面)
  • 也许您应该尝试像 INITSCRIPT_PARAMS = "stop 20 0 1 6 ." 一样覆盖 INITSCRIPT_PARAMS

【讨论】:

    猜你喜欢
    • 2017-01-04
    • 2020-09-30
    • 1970-01-01
    • 1970-01-01
    • 2016-10-01
    • 2013-09-04
    • 2015-07-06
    • 1970-01-01
    • 2021-06-02
    相关资源
    最近更新 更多