最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

linux - How to use update-alternatives Yocto class correctly? - Stack Overflow

programmeradmin1浏览0评论

I would appreciate any help with update-alternatives Yocto class: simply I cannot understand how it can be used and what are the correct options there.

The problem is simple: I need to install nginx-debug (my own build with --with-debug config) and non-debug nginx into one target image, so -debug version could take precedence (via ALTERNATIVE_PRIORITY) and I would have an option to remove it with dnf (so leaving image with non-debug version only). In other words, I need to have one main symlink called, say, /usr/sbin/nginx and it could point to two different targets: debug (nginx built with debugging support) and non-debug (plain build) in different times, without any further modifications, say, systemd units.

I looked into abovementioned class and wrote the following code (just portions of two recipes):

nginx.bb - non-debug version; it should appear as a default one with name of /usr/sbin/nginx

# I rename built binary of nginx to nginx.1 in do_install() task
...
inherit update-alternatives
# Lower the priority so we could override it with nginx-debug
ALTERNATIVE_PRIORITY = "10" 
ALTERNATIVE:${PN} = "nginx"

# Am I correct here? Should I specify [nginx] in all statements here?
ALTERNATIVE_TARGET[nginx] = "${sbindir_native}/nginx.1"
ALTERNATIVE_LINK_NAME[nginx] = "${sbindir_native}/nginx"

FILES:${PN} += "/"
CONFFILES:${PN} = "${sysconfdir}/${BPN}"
INSANE_SKIP:${PN} = "libdir"

nginx-debug.bb - debug version; it can be separately installed with dnf (not enabled by default), so I anticipate that /usr/sbin/nginx would point to its binary upon installation.

# Again, I setup built process and rename binary artifact to nginx-debug in do_install()
inherit update-alternatives

# This recipe should be a default one, substituting original binary
ALTERNATIVE_PRIORITY = "100"
ALTERNATIVE:${PN} = "nginx"
ALTERNATIVE_TARGET[nginx] = "${sbindir_native}/nginx-debug"
ALTERNATIVE_LINK_NAME[nginx] = "${sbindir_native}/nginx"

# Make package maximum lightweight
PACKAGES = "${PN}"
FILES:${PN} += "${sbindir_native}"
INHIBIT_PACKAGE_STRIP = "1"
INHIBIT_PACKAGE_DEBUG_SPLIT = "1"

And I should say it somehow works, but I am unable to perform dnf remove nginx-debug command as it gives me:

+ set -e
+ update-alternatives --remove nginx /usr/sbin/nginx-debug
mv: '/usr/sbin/nginx-debug' and '/usr/sbin/nginx-debug' are the same file

Also, if I install nginx (non-debug) version into clean system, it does not install any ALTERNATIVES but writes its binary. And I can't understand why it happens this way. Could you please help me understand the following:

  1. Am I right with TARGET and LINK_NAME given I need to perform the task of providing two binaries with one link?
  2. What can cause the problem with package removal? Am I correct with options for ALTERNATIVE_TARGET and ALTERNATIVE_LINK_NAME?

Thanks!

发布评论

评论列表(0)

  1. 暂无评论