I have installed a OneDrive client onedrive v2.4.22-1+np1 (https://github.com/abraunegg/onedrive) on an Ubuntu server (Ubuntu 22.04.1) which is running on a Raspberry Pi 4.
After installation I have started the service via
systemctl --user enable onedrive
systemctl --user start onedrive
Synchronization with OneDrive works as expected as long as I'm logged in. When I leave the system alone it stops synchronization after some time. There is another service running on the system which relies on the synchronization. This service works still fine but produces outdated results due to lacking synchronization and the results are not visible in the cloud.
When I login into the server on the Raspberry via SSH and get the service status via systemctl --user status onedrive
right after login, I can see that the onedrive client started just after my login while it should have been running continuously without my login:
Dec 14 12:45:27 raspi-server onedrive[19550]: Configuration file successfully loaded
Dec 14 12:45:27 raspi-server onedrive[19550]: Notification (dbus) server not available, disabling
Dec 14 12:45:28 raspi-server onedrive[19550]: Configuring Global Azure AD Endpoints
Dec 14 12:45:29 raspi-server onedrive[19550]: Initializing the Synchronization Engine ...
Dec 14 12:45:29 raspi-server onedrive[19550]: Initializing monitor ...
Dec 14 12:45:29 raspi-server onedrive[19550]: OneDrive monitor interval (seconds): 300
Dec 14 12:45:29 raspi-server onedrive[19550]: Starting a sync with OneDrive
According to the documentation at https://github.com/abraunegg/onedrive/blob/master/docs/USAGE.md#how-to-run-a-user-systemd-service-at-boot-without-user-login I should install the service using commands systemctl --user enable onedrive
and systemctl --user start onedrive
, but with su - root
first. I get an authentification error using su - root
. If I do it without elevated rights, the synchronisation works but stops when I'm not logged in. If I use sudo systemctl --user enable onedrive
instead of using su - root
, I get the error message Failed to connect to bus: $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined (consider using --machine=<user>@.host --user to connect to bus of other user)
. The linked documentation deals with a similar error message, and for Ubuntu on Raspberry Pi the first step according to the documentation is "Create a symbolic link from /home/root/.config/onedrive pointing to /root/.config/onedrive/". But I have neither a directory /home/root/ nor /root/.config/, so I'm stuck here.
I don't know how to figure out what's wrong with my service configuration. How can I make the onedrive service to work continuously?
Edit:
The missing piece was the terminal command
loginctl enable-linger <your_user_name>
which I took from the accepted answer point 4. With this, it now works like a charm.