在 Yocto 中以非 root 用户身份安装守护进程

问题描述

 if [ -f "${S}/abc/abcd.service" ]; then
      install -m 0644 ${S}/abc/abcd.service -D ${D}${systemd_unitdir}/system/abcd.service
      ln -sf ${systemd_unitdir}/system/abcd.service ${D}${systemd_unitdir}/system/multi-user.target.wants/abcd.service
      ln -sf ${systemd_unitdir}/system/abcd.service ${D}${systemd_unitdir}/system/ffbm.target.wants/abcd.service
 fi

我已经像上面一样安装了一个示例守护进程“abcd.service”,但在目标上,我看到它被列为 root。如果我选中“ps -ax | grep abcd”,那么它会显示我不想要的 root。 知道如何将其更改为非 root 用户吗?

解决方法

编辑 systemd 单元文件以使用 User=DynamicUser= 指令:https://www.freedesktop.org/software/systemd/man/systemd.exec.html?_sm_au_=iVVHkLwvwFJL8SMPL321jK0f1JH33#User=DynamicUser 指令可能更简单,因为您不必弄清楚如何在 Yocto 中创建新用户(也许这实际上很容易,但我不知道如何做到这一点)。