【问题标题】:yocto systemd can service not start after bootyocto systemd 启动后无法启动服务
【发布时间】:2020-05-11 17:42:08
【问题描述】:

我尝试将 can0 添加到 systemd 以在我的 imx8 板上启动时自动启动。 但我无法使用这些配置:

$tree recipes-core/
----------------------------------------
recipes-core/
└── systemd
    ├── systemd-machine-units
    │   ├── 10-eth0.network
    │   ├── 10-eth1.network
    │   ├── 90-dhcp-default.network
    │   ├── can0.service
    │   └── can1.service
    └── systemd-machine-units_1.0.bbappend

2 directories, 6 files
$ cat systemd-machine-units_1.0.bbappend 
-------------------------------------------------------------
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"

# all our boards have at least one native network port
SRC_URI = " \
    file://10-eth0.network \
    file://90-dhcp-default.network \
    file://10-eth1.network \
    file://can0.service \
    file://can1.service \
"

SYSTEMD_SERVICE_${PN} = "can0.service can1.service"


do_install_append() {
    install -d ${D}${systemd_unitdir}/network/
    install -m 0644 "${WORKDIR}/10-eth0.network" ${D}${systemd_unitdir}/network/
    install -m 0644 "${WORKDIR}/90-dhcp-default.network" ${D}${systemd_unitdir}/network/
    install -m 0644 "${WORKDIR}/10-eth1.network" ${D}${systemd_unitdir}/network/
    install -d ${D}${systemd_system_unitdir}/
    install -m 0644 "${WORKDIR}/can0.service" ${D}${systemd_system_unitdir}/
    install -m 0644 "${WORKDIR}/can1.service" ${D}${systemd_system_unitdir}/

}

FILES_${PN} = "\
    ${systemd_system_unitdir} \
    ${systemd_unitdir}/network/ \
"
$cat can0.service 
--------------------------------------------------------------------------------
# For 2.0B legacy mode, arbitration bit rate (bitrate) and
# payload bit rate (dbitrate) have the same value - not higher than 1Mbps.
# CAN frames are limited to max 8 bytes in this case
# if target does not support FD, fg settings are not accepted by ip link set
[Unit]
Description=can0 interface setup

[Service]
Type=simple
RemainAfterExit=yes
ExecStart=/sbin/ip link set can0 up type can bitrate 500000
ExecStop=/sbin/ip link set can0 down

[Install]
WantedBy=basic.target

在目标根上搜索 can0.service 但未找到:

$cd lib/systemd/ && find -name "*can*"
--------------------------------------------
./system/wpa_supplicant.service
./system/wpa_supplicant-nl80211@.service
./system/wpa_supplicant@.service
./system/wpa_supplicant-wired@.service

我还尝试使用这些文件添加 systemd_%.bbappend : (另外systemd树也和下面的代码不同。can0.service在service_%.bbappend文件附近的文件夹下)

FILESEXTRAPATHS_prepend := "${THISDIR}/files:"

SRC_URI += "file://can0.service"

SYSTEMD_SERVICE_${PN} = "can0.service can1.service"

FILES_${PN} += "{sysconfdir}/systemd/system/* "

do_install_append() {
    install -d ${D}${systemd_unitdir}/system/
    install -m 0644 ${WORKDIR}/*.service ${D}${systemd_unitdir}/system/
}

can0.service 由上述 systemd_%.bbappend 创建,但在启动时不会自动启动。只是 can0.service 似乎在目标的 /lib/systemd/system 文件夹中。

我的错误是什么?有人可以帮帮我吗?

【问题讨论】:

  • journalctl -u can0 说什么?
  • @OleksandrKravchuk 什么也不说。 (没有条目)
  • 服务还在运行吗? systemctl status cat0
  • @OleksandrKravchuk 没有运行。我的 bbappend 没有将 can0.service 添加到 rootfs。
  • @OleksandrKravchuk:我完成了构建。 systemd_%.append 按照我的预期将 can0.service 添加到 /lib/systemd/system 但是:$systemctl status can0 表示:��● can0.service - can0 接口设置已加载:已加载 (/lib/systemd/system/can0.服务;禁用;供应商预设:启用)活动:非活动(死)1 月 25 日 21:56:55 tqma8xqp-mba8xx systemd[1]: [[0;1;39m[[0;1;31m[[0;1; 39m/lib/systemd/system/can0.service:16:“安装”部分中的未知左值“FILES_${PN} +”[[0m

标签: yocto systemd


【解决方案1】:

上面发布的 cat0 服务状态显示该服务未启用。

您可以使用命令systemctl enable cat0 启用此服务,然后尝试重新启动系统。

系统重启后,处于启用状态的服务会自动出现。

【讨论】:

  • 是的,你是对的。现在,如果我写 systemctl enable can0 ,每次系统重启都可以。但是为什么我必须写这个命令呢?重启后我不能没有这个命令吗?当我将图像写入 sdcard linux 等待时,我也是第一次重新启动
【解决方案2】:

enable 会将指定的单元挂接到相关位置,以便在启动或其他情况下自动启动,具体取决于单元文件中指定的内容。

从 systemctl 版本 220 开始,启用和禁用支持 --now 开关以在启用/禁用的同时启动/停止服务。

例如systemctl --now enable foobar.service

使用 systemctl --version 检查您安装的版本。

【讨论】:

  • 首先感谢您的帮助。您的建议对我很有帮助。所以我添加了你说的现在一切看起来都很好但没有开始(我认为它必须开始)。我在@systemctl status can0 得到这个日志:��● can0.service - can0 interface setup Loaded: loaded (/lib/systemd/system/can0.service; disabled; vendor preset: en abled) Active: inactive (dead)
【解决方案3】:

添加

inherit systemd

SYSTEMD_AUTO_ENABLE ??= "enable"

食谱对我有用。现在该服务在刷新图像后自动启用。

【讨论】:

    猜你喜欢
    • 2015-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-31
    • 2021-01-08
    • 1970-01-01
    相关资源
    最近更新 更多