user service autostart


Joel Winarske
 

How does one enable a user service for a specific user at postinst?

User service in question is located in ${system_user_unitdir}.

Seems the problem is related to determining what user, which makes sense why this combo is not allowed: "systemctl --user --root=..."

I'm figuring this run as root?  Is there a way to have it run for a specific user?
systemd_postinst_ontarget () {
if [ "${SYSTEMD_AUTO_ENABLE}" = "enable" ]; then
for service in ${FLUTTER_USER_SERVICE_ESCAPED}; do
systemctl --user enable "$service"
systemctl --user start "$service"
done
fi
}

Thanks,
Joel


Joel Winarske
 

Like maybe simply:

systemd_postinst_ontarget () {
if [ "${SYSTEMD_AUTO_ENABLE}" = "enable" ]; then
for service in ${FLUTTER_USER_SERVICE_ESCAPED}; do
 su <desired user>
systemctl --user enable "$service"
systemctl --user start "$service"
done
fi
}


On Thu, Jul 28, 2022 at 8:00 PM Joel Winarske via lists.yoctoproject.org <joel.winarske=gmail.com@...> wrote:
How does one enable a user service for a specific user at postinst?

User service in question is located in ${system_user_unitdir}.

Seems the problem is related to determining what user, which makes sense why this combo is not allowed: "systemctl --user --root=..."

I'm figuring this run as root?  Is there a way to have it run for a specific user?
systemd_postinst_ontarget () {
if [ "${SYSTEMD_AUTO_ENABLE}" = "enable" ]; then
for service in ${FLUTTER_USER_SERVICE_ESCAPED}; do
systemctl --user enable "$service"
systemctl --user start "$service"
done
fi
}

Thanks,
Joel