Monday, January 29, 2024

[SOLVED] cron can't see systemctl --user services

Issue

I have a user cronjob I setup with:

$ crontab -e
*/5 * * * * systemctl --user is-active test.service >> ~/test.txt

But for some reason the service is always displayed as offline when executed with cron, but not when I manually execute:

systemctl --user is-active test.service

Is this some kind of permission issue or how could I otherwise test that a service is still running periodically.


Solution

For someone who have that same problem.

XDG_RUNTIME_DIR=/run/user/$(id -u) systemctl --user is-active test.service

is working.



Answered By - Paweł Paradowski
Answer Checked By - Terry (WPSolving Volunteer)