简体   繁体   English

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

[英]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. 我目前正在使用Yocto安装dnsmasq,但我想删除自动启动。

So I create a .bbappend file and I tried something like : 所以我创建了一个.bbappend文件,我尝试了类似的东西:

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. 但它不起作用,我不知道如何继续使用bbappend文件删除此init脚本。

Thanks, Pierre-Olivier 谢谢,皮埃尔 - 奥利维尔

Several things: 几件事:

  • maybe you're using systemd? 也许你正在使用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) 也许你应该尝试update-rc.d -f dnsmasq remove (注意-f应该在名字前面)
  • maybe you should try overriding INITSCRIPT_PARAMS like INITSCRIPT_PARAMS = "stop 20 0 1 6 ." 也许你应该尝试重写INITSCRIPT_PARAMSINITSCRIPT_PARAMS = "stop 20 0 1 6 ." ?

The correct way to disable a service under SysV is with INITSCRIPT_PARAMS : 在SysV下禁用服务的正确方法是使用INITSCRIPT_PARAMS

From man update-rc.d 来自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: 好吧,如果/etc/init.d/script不存在“update-rc.d LSB header”(Yocto中的NGINX也是如此 - 我以它为例),那么它很简单:

  • runlevel 0 - shutdown, => by default stop a service at this runlevel runlevel 0 - shutdown,=>默认情况下在此运行级别停止服务
  • runlevel 1 - single user mode, => usually stop a service at this runlevel 运行级别1 - 单用户模式,=>通常在此运行级别停止服务
  • runlevel 6 - reboot, => that's trivial: stop a service at this runlevel runlevel 6 - reboot,=>这很简单:在这个运行级别停止服务

NGINX is described by nginx.inc file under Yocto meta-openembedded layer: NGIX由Yocto meta-openembedded层下的nginx.inc文件描述:

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

NGINX defines initial scripts as follows in nginx.inc file: NGINX在nginx.inc文件中定义了如下初始脚本:

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

And the resulting service Start/Kill symlinks in Yocto rootfs are: 在Yocto rootfs中生成的服务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/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. 此外, update-rc.d.bbclass在rootfs创建期间执行update-rc.d确认了这一点。 So, the way update-rc.d is called in meta/classes/update-rc.d.bbclass file is: 因此,在meta/classes/update-rc.d.bbclass文件中调用update-rc.d的方式是:

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

Bingo! 答对了!

Conclusion 结论

To disable a service in SysV under Yocto we need to define: 要在Yocto下禁用SysV中的服务,我们需要定义:

INITSCRIPT_PARAMS = "stop 20 0 1 6 ."

But how to verify the resulting INITSCRIPT_PARAMS? 但是如何验证生成的INITSCRIPT_PARAMS?

The effective INITSCRIPT_PARAMS environment variable should be verified before re-creating rootfs. 在重新创建rootfs之前,应验证有效的INITSCRIPT_PARAMS环境变量。 The proper and simple way to do it is again using the great bitbake command: 正确而简单的方法是再次使用伟大的bitbake命令:

bitbake nginx -e | grep INITSCRIPT_PARAMS

Now, let's re-create the image ( core-image-full-cmdline in my case): 现在,让我们重新创建图像(在我的情况下, core-image-full-cmdline ):

bitbake core-image-full-cmdline

We can easily see now, that all the remaining Start/Kill symlinks are: 我们现在可以很容易地看到,所有剩余的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

Bingo once again! 宾果再一次!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM