Yocto系统配置 [英] Yocto Systemd Configuration

查看:10
本文介绍了Yocto系统配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 = ""

我的impledaemon.service如下:

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

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

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

当我运行bitbake时,出现错误Didn't find service unit 'simpledaemon.service', specified in SYSTEMD_SERVICE_simpledaemon.。这告诉我这是一个路径错误,我只能假设它是由我的GitHub结构引起的。有人能照亮这个吗?

推荐答案

食谱中有一些问题会导致您的错误:

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安装system d服务

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

由于您需要运行AutoToolsdo_install,还需要您自己的一些代码(用于安装systemd服务),因此您可以向上移动Inherit并将其与systemd服务组合:

inherit autotools systemd

和,然后定义一个do_install_append函数,以附加安装您的system d服务所需的额外步骤:

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下的手册中阅读有关此技术的更多信息。

这篇关于Yocto系统配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆