Skip to content

Instantly share code, notes, and snippets.

@Gyarbij
Created November 29, 2023 17:08
Show Gist options
  • Save Gyarbij/e75e6b7841bb2e71f4459f0bb8a3b6a4 to your computer and use it in GitHub Desktop.
Save Gyarbij/e75e6b7841bb2e71f4459f0bb8a3b6a4 to your computer and use it in GitHub Desktop.
Steps and example RClone systemd with mounted OneDrive for use with Plex en Jellyfin and other similar use-cases. Replace 'nano' with vi or your editor of choice if not on distro with nano included or because you like misery... your kinks are yours :)

CHANGE LEGEND: (you MUST replace these in the service file)

  • USERNAME = your actual username e.g. gyarbij
  • I recommend changing odrive.service to the name of eache drive if you have multiple mount points.
  • If you already have rclone mounts check Step #2 then skip to Step #4 and place your mount point at #MOUNT

Steps for RClone systemd to autostart on boot

  1. Install fusermount (if not already installed)
sudo apt install fuse3
  1. Allow non-root users to mount filesystems
sudo nano /etc/fuse.conf

Uncomment (remove the) # from the line: allow_other

  1. Make the requisite directories for mount and cache.
sudo mkdir /mnt/rclonecache

or do all directories at once. You will need to chown regardless.

sudo mkdir /mnt/{odrive,rclonecache}
sudo chown -R USERNAME:USERNAME /mnt/{odrive,rclonecache}
  1. Create the service(s):
sudo nano /etc/systemd/system/odrive.service
  1. Copy the below BASIC example to the service file created/opened above:
[Unit]
Description=RClone Service
Wants=network-online.target
After=network-online.target
AssertPathIsDirectory=/mnt/odrive

[Service]
Type=notify
Environment=RCLONE_CONFIG=/home/USERNAME/.config/rclone/rclone.conf #check USERNMAE
RestartSec=10
ExecStart=/usr/bin/rclone mount odm: /mnt/odm \
   --allow-other \
   --allow-non-empty \
   --dir-cache-time 5000h \
   --cache-dir=/mnt/rclonecache \
   --volname odrive \
   --vfs-cache-mode full \
   --vfs-cache-max-size 10G \
   --vfs-cache-poll-interval 1m \
   --buffer-size 512M \
   --dir-cache-time 72d \
   --umask 002 \
   --vfs-read-chunk-size 250M \
   --vfs-read-chunk-size-limit off

ExecStop=/bin/fusermount -uz /mnt/odrive #MOUNT
Restart=on-failure
User=USERNAME #change
Group=USERNAME #change

[Install]
WantedBy=multi-user.target
  1. Save and then exit the file
ctrl+o | ctrl+x
  1. Run the follwoing commands in order to enable and then start the service:
sudo systemctl daemon-reload
sudo systemctl enable odrive
sudo systemctl start odrive
  1. To see if the service is running:
systemctl status odrive
  1. To see if the drive is mounted run:
df -H
  1. Reboot and repeat step 7 for a final sanity check!

  2. Prevent Docker from starting before mounts:

sudo systemctl edit docker.service
[Service]
#ExecStartPre=/bin/sleep 30
RequiresMountsFor=/mnt/odrive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment