为什么用systemd不能自动启动?

问题描述 投票:-1回答:1

Yocto版本是warrior.我做了一个带有GOgolang用户应用程序(https-server)的yocto项目,在raspi3上运行得很好,现在我试图在yocto图像上自动启动它,但没有得到它的工作,我知道有很多关于这个问题的其他问题,但我没有找到帮助的东西,例如,我试图按照这个帖子中的所有步骤来做。使用 yocto 启用 systemd 服务但它不能在raspi上自动启动。

这些文件在raspi的服务,我发现。

/lib/systemd/system/https-server.service 
/etc/systemd/system/multi-user.target.wants/https-server.service

如果我手动启动的话,应用程序本身运行得很好,它在raspi的usrbinhttps -server处。

我的 buildconflocal.conf:

IMAGE_INSTALL_append = " kernel-image kernel-devicetree sudo apt dnsmasq nano dhcpcd git glibc-utils localedef curl go https-server"
meta-https-server/
├── conf
│   └── layer.conf
└── recipes-https-server
    └── https-server
        ├── files
        │   ├── https-server.go
        │   ├── https-server.service
        │   ├── mytest
        │   ├── server.crt
        │   ├── server.key
        │   └── testvideo.mp4
        ├── go-sw.inc
        └── https-server.bb

https-server.bb

require go-sw.inc

inherit go systemd
#inherit go update-rc.d systemd


SRC_URI += "file://https-server.service"
SRC_URI += "file://https-server.go"

SYSTEMD_PACKAGES = "${PN}"
INITSCRIPT_PACKAGES = "${PN}"
SYSTEMD_SERVICE_${PN} = "https-server.service"

# Path
MY_KEY = "/data/yocto/2020-04-21-poky-warrior/poky-warrior/meta-https-server/recipes-https-server/https-server/files/server.key"
MY_CERT = "/data/yocto/2020-04-21-poky-warrior/poky-warrior/meta-https-server/recipes-https-server/https-server/files/server.crt"
TESTVIDEO = "/data/yocto/2020-04-21-poky-warrior/poky-warrior/meta-https-server/recipes-https-server/https-server/files/testvideo.mp4"
MY_TEST = "/data/yocto/2020-04-21-poky-warrior/poky-warrior/meta-https-server/recipes-https-server/https-server/files/mytest"

# COMPILER
do_compile() {
go build /data/yocto/2020-04-21-poky-warrior/poky-warrior/meta-https-server/recipes-https-server/https-server/files/https-server.go
}


# INSTALL
do_install() {
#   install -d to create directories, "${D}/${bindir}" is /usr/bin

#   systemd
    install -d ${D}${systemd_unitdir}/system
    install -m 0644 ${WORKDIR}/https-server.service ${D}${systemd_unitdir}/system

#   HTTPS certificate and key
    install -d "${D}/${bindir}"
    install -m 0755 "${MY_KEY}"    "${D}/${bindir}"
    install -m 0755 "${MY_CERT}"   "${D}/${bindir}"
    install -m 0777 "${TESTVIDEO}" "${D}/${bindir}"
    install -m 0777 "${MY_TEST}"   "${D}/${bindir}"

#   HTTPS Server Software
    install -m 0755 "${S}/build/https-server" "${D}/${bindir}"

}

FILES_${PN} += "${bindir}"
FILES_${PN} += "${libexecdir}"
FILES_${PN} += "${systemd_system_unitdir}"


REQUIRED_DISTRO_FEATURES= "systemd"

服务 https-server.service

[Unit]
Description=HTTPS Server sw startup script

[Service]
ExecStart=/usr/bin/https-server

[Install]
WantedBy=multi-user.target
yocto systemd
1个回答
0
投票

我找到了导致这个问题的原因。

在我的本地配置中 buildconflocal.conf中只有这个:

    DISTRO_FEATURES_append = " systemd "

在我添加了以下内容后

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

它工作得很好 进程https-server在启动时就开始了。我在启动后用ps检查了正在运行的进程,因为systemctl在我的core-image-minimal镜像上没有工作。

    root@raspberrypi3:~# ps
    [...]
    152 root      861m S    /usr/bin/https-server
    [...]
    root@raspberrypi3:~#

所以这就造成了不同的结果 不知道是不是我的DISTRO_FEATURES_append = "systemd "处缺失的空格也是错误的...... ??

    #DISTRO_FEATURES_append = " systemd"

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

@Nayfe 建议的 oe-pkgdata-util 是一个非常有用的工具。

user@machine:[...]/poky-warrior/build$ 
oe-pkgdata-util list-pkg-files -p https-server
https-server:
        /lib/systemd/system/https-server.service
        /usr/bin/https-server
        /usr/bin/mytest
        /usr/bin/server.crt
        /usr/bin/server.key
        /usr/bin/testvideo.mp4
https-server-dbg:
        /usr/bin/.debug/https-server
https-server-dev:
https-server-ptest:

我还按照 @Nayfe 的建议修改了上面的食谱 https-server.bb 以避免绝对路径。这并没有造成问题,但这是不好的风格。

不要使用datayocto2020-04-21-poky-warriorpoky-warriormeta-https-serverrecipes-https-serverhttps-serverfiles的前缀,而是添加SRC_URI中的每个文件。

require go-sw.inc

inherit go systemd

#  "${D}/${bindir}" is /usr/bin 
#  ${WORKDIR} is path at local directory, 
#  this can be used instead of absolute paths

SRC_URI += "file://https-server.service"
SRC_URI += "file://https-server.go"
SRC_URI += "file://server.key"
SRC_URI += "file://server.crt"
SRC_URI += "file://testvideo.mp4"
SRC_URI += "file://mytest"

SYSTEMD_PACKAGES = "${PN}"
INITSCRIPT_PACKAGES = "${PN}"
SYSTEMD_SERVICE_${PN} = "https-server.service"

# COMPILER
do_compile() {
go build ${WORKDIR}/https-server.go
}


# INSTALL
do_install() {
#   install -d to create directories, "${D}/${bindir}" is /usr/bin

#   systemd
    install -d ${D}${systemd_unitdir}/system
    install -m 0644 ${WORKDIR}/https-server.service ${D}${systemd_unitdir}/system

#   HTTPS certificate, key and testdata for https-server
    install -d "${D}/${bindir}"
    install -m 0755  ${WORKDIR}/server.key     "${D}/${bindir}"
    install -m 0755  ${WORKDIR}/server.crt     "${D}/${bindir}"
    install -m 0777  ${WORKDIR}/testvideo.mp4  "${D}/${bindir}"
    install -m 0777  ${WORKDIR}/mytest         "${D}/${bindir}"

#   HTTPS Server Software
    install -m 0755 "${WORKDIR}/build/https-server" "${D}/${bindir}"
}

# FILES_${PN} is Yocto’s way of specifying
# which files are expected to be installed along with which package
# (${PN} is a variable holding the main package’s name).
FILES_${PN} += "${bindir}"
FILES_${PN} += "${libexecdir}"
FILES_${PN} += "${systemd_system_unitdir}"

REQUIRED_DISTRO_FEATURES= "systemd"

感谢@kostix和@nayfe的建议。

© www.soinside.com 2019 - 2024. All rights reserved.