首页 > 解决方案 > 在 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 用户吗?

标签: yoctobitbakeyocto-recipe

解决方案


Edit the systemd unit file to use the User= or DynamicUser= directive: https://www.freedesktop.org/software/systemd/man/systemd.exec.html?_sm_au_=iVVHkLwvwFJL8SMPL321jK0f1JH33#User=. The DynamicUser directive might be easier because you won't have to figure out how to create a new user in Yocto (maybe it's actually easy but I don't know how to do it off the top of my head).


推荐阅读