我试图启动一个服务的启动,但我有问题的建设。这是我自定义层中的树结构。
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
我从“使用第二版嵌入式Linux开发”一书中获得了所有这些信息。
在我尝试添加这个新服务之前,我的所有构建都是成功的。这本书没有提到systemd服务的init脚本。我还从GitHub中提取代码,而不是在构建目录中提取代码(您可以查看回购)。
当我运行bitbake
时,会得到错误Didn't find service unit 'simpledaemon.service', specified in SYSTEMD_SERVICE_simpledaemon.
。这告诉我,这是一个路径错误,我只能假设它是由我的GitHub结构产生的。有人能在这上面照点光吗?
发布于 2022-01-23 10:42:47
你的食谱中有几个问题会导致你的错误:
1.使用正确的SRCREV
SRCREV = "a37a89df4d53bca97c12c8908cbe8552032417b4“
上面的SRCREV
是指在添加.service
文件之前在存储库中提交。将此更改为最新提交,2140a0646b3ffc6595c50ac549dc6f1220f66c28
2.删除自动工具已经描述的步骤:
由于您的源代码使用自动工具,而Yocto食谱继承了autotools类,所以Yocto将自动运行等效的./configure
、make
、make install
来配置/编译/安装这个包。
因此,可以删除整个do_compile
任务和手动安装二进制文件的do_install
的前几行:
do_compile () {{CC} ${LDFLAGS} simpledaemon.c -o simpledaemon } do_install () { -d ${D}${bindir}安装-m 0755 ${WORKDIR}/simpledaemon ${D}${bindir}
3.使用do_install_append
安装systemd服务
食谱文件末尾的inherit autotools
会导致do_install
任务被覆盖,因为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
中也有一些错误:
simpledaemon.service
文件是从${S}
安装的,它是源目录(即git目录),而不是${WORKDIR}
。sed
命令应该在新行上${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
开头的行)。很明显,解析之后,函数不包含安装服务代码的步骤。
您可以在手册中(在查看变量值下)阅读更多有关此技术的内容。
发布于 2022-01-22 04:19:31
您能在示例simpledaemon
中移动dir
dir吗?
您可以使用git.bb作为参考。
https://stackoverflow.com/questions/70805499
复制相似问题