【问题标题】:Yocto Systemd ConfigurationYocto 系统配置
【发布时间】:2022-01-21 17:44:38
【问题描述】:

我正在尝试在启动时启动服务,但是我在构建时遇到了问题。 这是我的自定义层中的树结构

michael@michael-VirtualBox:~/Documents/simple_daemon/sources/meta-simpledaemon$ tree
.
├── conf
│   └── layer.conf
├── COPYING.MIT
├── README
└── recipes-example
    ├── example
    │   └── example_0.1.bb
    └── simpledaemon
        ├── files
        │   └── simpledaemon.service
        └── simpledaemon_git.bb

在我的 local.conf 中,我在末尾添加了以下内容:

IMAGE_INSTALL_append = " bbexample "
IMAGE_INSTALL_append = " simpledaemon "
IMAGE_INSTALL_append = " packagegroup-core-ssh-openssh "
IMAGE_INSTALL_append = " openssh-sftp-server "


DISTRO_FEATURES_append = " systemd"
VIRTUAL-RUNTIME_init_manager = " systemd"
DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
VIRTUAL-RUNTIME_initscripts = ""

我的.bb文件如下:

# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)

# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is
# your responsibility to verify that the values are complete and correct.
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=ca119cf6dcda0f0883a416a3e7f94cc2"

SRC_URI = "git://github.com/MichaelBMiner/simpledaemon;protocol=https"

# Modify these as desired
PV = "1.0+git${SRCPV}"
SRCREV = "a37a89df4d53bca97c12c8908cbe8552032417b4"

inherit systemd

S = "${WORKDIR}/git"

SYSTEMD_SERVICE_${PN} = "simpledaemon.service"
do_compile () {
    ${CC} ${LDFLAGS} simpledaemon.c -o simpledaemon
}
do_install () {
    install -d ${D}${bindir}
    install -m 0755 ${WORKDIR}/simpledaemon ${D}${bindir}
    install -d ${D}${systemd_unitdir}/system
    install -m 0644 ${WORKDIR}/simpledaemon.service ${D}${systemd_unitdir}/system sed -i -e     's,@BINDIR@,${bindir},g' ${D}${systemd_unitdir}/system/simpledaemon.service
}

# NOTE: if this software is not capable of being built in a separate build directory
# from the source, you should replace autotools with autotools-brokensep in the
# inherit line
inherit autotools

# Specify any options you want to pass to the configure script using EXTRA_OECONF:
EXTRA_OECONF = ""

我的simpledaemon.service如下:

[Unit]
Description=Example service
[Service]
Type=forking
ExecStart=@BINDIR@/simple-service
[Install]
WantedBy=multi-user.target

我从《使用 Yocto Project Cookbook 第二版进行嵌入式 Linux 开发》一书中获得了所有这些信息。

在我尝试添加这项新服务之前,我的所有构建都已成功。这本书没有提到 systemd 服务的 init shell 脚本。我还从 GitHub 中提取代码,而不是在我的构建目录中提取代码(您可以查看 repo)。

当我运行bitbake 时,我收到错误Didn't find service unit 'simpledaemon.service', specified in SYSTEMD_SERVICE_simpledaemon.。这告诉我这是一个路径错误,我只能假设它是由我的 GitHub 结构引起的。任何人都可以对此有所了解吗?

【问题讨论】:

    标签: yocto systemd bitbake nxp-microcontroller


    【解决方案1】:

    您的食谱存在一些问题导致您的错误:

    1。使用正确的SRCREV:

    SRCREV = "a37a89df4d53bca97c12c8908cbe8552032417b4"
    

    上面的SRCREV 指的是在添加.service 文件之前在您的存储库中的一次提交。将此更改为最新提交,2140a0646b3ffc6595c50ac549dc6f1220f66c28

    2。删除 autotools 已经描述的步骤:

    由于您的源代码使用 autotools 并且您的 Yocto 配方继承了 autotools 类,Yocto 将自动运行 ./configuremakemake install 的等效项来配置/编译/安装此软件包。

    因此,您可以删除整个 do_compile 任务以及手动安装二进制文件的 do_install 的前几行:

    do_compile () {
        ${CC} ${LDFLAGS} simpledaemon.c -o simpledaemon
    }
    
    do_install () {
        install -d ${D}${bindir}
        install -m 0755 ${WORKDIR}/simpledaemon ${D}${bindir}
    

    3。使用do_install_append安装systemd服务

    配方文件末尾的 inherit autotools 会导致您的 do_install 任务被覆盖,因为 autotools 类将其设置为 autotools 样式的方法。

    由于您需要运行 autotools do_install,还需要一些您自己的代码(安装 systemd 服务),您可以将继承向上移动并与 systemd 结合:

    inherit autotools systemd
    

    然后,定义一个 do_install_append 函数来附加安装 systemd 服务所需的额外步骤:

    do_install_append () {
        install -d ${D}${systemd_system_unitdir}
        install -m 0644 ${S}/simpledaemon.service ${D}${systemd_system_unitdir}
        sed -i -e 's,@BINDIR@,${bindir},g' ${D}${systemd_system_unitdir}/simpledaemon.service
    }
    

    您原来的do_install 也有很多错误:

    1. simpledaemon.service 文件是从 ${S} 安装的,它是源目录(即 git 目录),而不是 ${WORKDIR}
    2. sed 命令应该在新的一行
    3. (优化)您可以使用${systemd_system_unitdir} 代替${systemd_unitdir}/system

    4。删除未使用的EXTRA_OECONF = ""

    EXTRA_OECONF 设置为空将覆盖它拥有的任何默认值,这通常由 Yocto 发行版定义。如果您确实需要./configure 的额外参数,请考虑使用PACKAGECONFIG 或最后使用EXTRA_OECONF += "--foo-bar"


    完整配方:

    LICENSE = "MIT"
    LIC_FILES_CHKSUM = "file://LICENSE;md5=ca119cf6dcda0f0883a416a3e7f94cc2"
    
    SRC_URI = "git://github.com/MichaelBMiner/simpledaemon;protocol=https"
    
    PV = "1.0+git${SRCPV}"
    SRCREV = "2140a0646b3ffc6595c50ac549dc6f1220f66c28"
    
    inherit systemd autotools
    
    S = "${WORKDIR}/git"
    
    SYSTEMD_SERVICE_${PN} = "simpledaemon.service"
    
    do_install_append () {
        install -d ${D}${systemd_system_unitdir}
        install -m 0644 ${S}/simpledaemon.service ${D}${systemd_system_unitdir}
        sed -i -e 's,@BINDIR@,${bindir},g' ${D}${systemd_system_unitdir}/simpledaemon.service
    }
    

    调试提示

    调试配方的一种有用方法是将以下命令的输出转储到文件并检查它:

    bitbake -e your-recipe-or-image-name
    

    如果您检查 bitbake -e simpledaemon 的输出以查找原始配方,并查找 do_install 的最终定义(搜索以 do_install 开头的行)。很明显,解析后,该函数没有包含您安装服务代码的步骤。

    您可以在Viewing Variable Values 下的手册中阅读有关此技术的更多信息。

    【讨论】:

    • 这是一些很棒的建议!今天下午我会试试这个。
    • 我按照你的建议做了,我现在正在建立我的形象。我希望它很快就会完成。你知道任何可以展示如何使用私有 GitLab/GitHub 存储库的资源吗?
    • 在下面,Yocto 运行与您手动运行相同的 git clone ... 命令,因此只要您在用户帐户上正确设置了 SSH 密钥,就不会遇到任何问题来自私人 git 存储库。您只需要确保 SRC_URI 指定 Yocto 应该使用 SSH 来获取,例如SRC_URI = "git://git@github.com/username/project.git;protocol=ssh;branch=master"
    【解决方案2】:

    你能把simpledaemon dir 移到示例dir 中吗?

    您可以使用obmc-op-control-host_git.bb 作为参考。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-07
      • 2020-07-28
      • 2016-08-04
      • 2018-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-03
      相关资源
      最近更新 更多