When new folders are synced from onedrive to your linux, their permissions are default. For Navidrome to read the folders it needs to have permission to access the folder. Doing this for every folder whenever synced can be a hassle. Hence, this script runs as a systemd.service

You can create a system-wide service that will run regardless of whether you’re logged into the machine or not. This way, the script will always be running, even if no one is logged in.


Create a systemd service that runs regardless of the user session

Step-by-step guide:

1️⃣ Create a system-wide service for the script

Instead of using ~/.config/systemd/user/, you’ll use /etc/systemd/system/ to create a system-wide service.

First, create the service file:

sudo nano /etc/systemd/system/fix-onedrive.service

Paste the following content into the file:

[Unit]
Description=Force permissions on OneDrive Albums folder
After=network.target
 
[Service]
ExecStart=/home/ubuntu/fix-onedrive-perms-loop.sh
Restart=always
RestartSec=5
User=ubuntu
Group=ubuntu
 
[Install]
WantedBy=multi-user.target

Explanation:

  • After=network.target: Ensures it starts after network is available.

  • ExecStart: Full path to your script. (You NEED to add full path if you want it to run even if you are not ssh-ed)

  • User=ubuntu and Group=ubuntu: Ensures the service runs with your user permissions.

  • Restart=always: Restarts the service if it ever fails.


2️⃣ Reload systemd and enable the service

After saving the service file, you need to reload the systemd configuration and enable the service to start at boot.

Reload systemd to recognize the new service:

sudo systemctl daemon-reload

Enable the service to run on boot:

sudo systemctl enable fix-onedrive.service

Start the service immediately:

sudo systemctl start fix-onedrive.service

Check the service status:

sudo systemctl status fix-onedrive.service

You should see something like:

● fix-onedrive.service - Force permissions on OneDrive Albums folder
   Loaded: loaded (/etc/systemd/system/fix-onedrive.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2026-02-02 15:30:00 UTC; 1h 30min ago
   ...

3️⃣ (Optional) Verify it works without SSH

To make sure the service runs without SSH:

  1. Stop your SSH session completely.

  2. Wait a few seconds.

  3. Check if the service is still running:

sudo systemctl status fix-onedrive.service

Summary

  • The script is now running as a system-wide service (not tied to your login).

  • It will always run, even if you’re not logged in.

  • The systemd service starts on boot, so it will persist after reboots.

  • It will automatically restart if it crashes or if the VM reboots.


Back References: