Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rclone systemd user service

rclone systemd service

Preparation

This service will use the same remote name you specified when using rclone config create. If you haven't done that yet, do so now.

Next, create the mountpoint for your remote. The service uses the location ~/mnt/<remote> by default.

mkdir ~/mnt/dropbox

The --allow-other option is required in order to work in many desktop environments. This flag must be enabled by adding user_allow_other to /etc/fuse.conf.

Adding the service

Save the rclone@.service file in ~/.config/systemd/user/ Make sure you include the @. This is required to work.

As your normal user, run:

systemctl --user daemon-reload

Using the service

You can now start/enable each remote by using rclone@<remote>

systemctl --user enable rclone@dropbox
systemctl --user start rclone@dropbox
# User service for Rclone mounting
#
# Place in ~/.config/systemd/user/
# File must include the '@' (ex rclone@.service)
# As your normal user, run
# systemctl --user daemon-reload
# You can now start/enable each remote by using rclone@<remote>
# systemctl --user enable rclone@dropbox
# systemctl --user start rclone@dropbox
[Unit]
Description=rclone: Remote FUSE filesystem for cloud storage config %i
Documentation=man:rclone(1)
After=network-online.target
Wants=network-online.target
AssertPathIsDirectory=%h/mnt/%i
[Service]
Type=notify
ExecStart= \
/usr/bin/rclone mount \
--config=%h/.config/rclone/rclone.conf \
--vfs-cache-mode writes \
--vfs-cache-max-size 100M \
--log-level INFO \
--log-file /tmp/rclone-%i.log \
--umask 022 \
--allow-other \
%i: %h/mnt/%i
ExecStop=/bin/fusermount -u %h/mnt/%i
[Install]
WantedBy=default.target
@kabili207
Copy link
Author

kabili207 commented May 22, 2020

Due to security limitations caused by cgroups, --allow-other is required in order actually access the mount (not even root could read it on my machine). Setting --umask 022 is used to restore the expected permissions.

@Christopher-Hayes
Copy link

Christopher-Hayes commented Jan 23, 2021

FYI, for anyone else. The --allow-other flag was giving me an error because it was expecting a configuration in another file. I ended up removing the flag to get it working.

mount helper error: fusermount: option allow_other only allowed if 'user_allow_other' is set in /etc/fuse.conf

Also, if you get an assertion error Assertion failed on job for, it means you need to create the directory that the mount will use in the format ~/mnt/<name of RClone script>.

Thanks for this script, it's working great!

@akhiljalagam
Copy link

akhiljalagam commented Dec 7, 2021

NOTICE: --fast-list does nothing on a mount

@aureq
Copy link

aureq commented Dec 26, 2021

The service can be further protected with MemoryDenyWriteExecute=true if placed in the [Service] section.

@craggles17
Copy link

craggles17 commented Feb 17, 2022

Would -vfs-cache-mode writes not work better?

--allow-other Failed for me too @Christopher-Hayes

@stuie1952
Copy link

stuie1952 commented Feb 22, 2022

I am stuck on "Failed to start rclone: Remote FUSE filesystem for cloud storage config filename

Any help appreciated. This app is just what I need :-)

Also i do not understand what "config %i is doing in the Description.

@stuie1952
Copy link

stuie1952 commented Feb 23, 2022

solution was as simple as "modprobe fuse". i wish all my problems were solved so simply.

next step is to get the fuse filesystem to work with dolphin. i get the feeling this is not going to be simple ...

@stuie1952
Copy link

stuie1952 commented Feb 24, 2022

I am on a roll today :-)

The option "--allow-other " has given me access to the files in dolphin. however first i had to enable "--allow-other" in /etc/fuse.conf

I hope this helps others too.

@kabili207
Copy link
Author

kabili207 commented Feb 24, 2022

I've added a quick README since many people get tripped up on the --allow-other flag. (I've been using it for so long, I forgot it's not a default setting)

@jonaharagon
Copy link

jonaharagon commented Feb 25, 2022

MemoryDenyWriteExecute=true didn't allow the service to start in a very difficult-to-diagnose way on CentOS 8 Stream (systemd 239 (239-58.el8)), removing it worked.

Thanks for this!

@lilws
Copy link

lilws commented Feb 27, 2022

Hi, I came from googling around and still can't find out how to run multiple rclone shell script in bash as systemd. I can run the service when calling systemd. But it won't run at boot.

@stuie1952
Copy link

stuie1952 commented Feb 28, 2022

You need to enable the service for it to start at boot.

Just replace start with enable in systemctl

@xqft
Copy link

xqft commented Mar 1, 2022

I get mount helper error: fusermount: mount failed: Operation not permitted :/

@stuie1952
Copy link

stuie1952 commented Mar 2, 2022

Did you 'modprobe fuse '

@stuie1952
Copy link

stuie1952 commented Mar 2, 2022

The --allow-other option is required in order to work in many desktop environments. This flag must be enabled by adding user_allow_other to /etc/fuse.conf.

@xqft
Copy link

xqft commented Mar 2, 2022

Yep I did both

@xqft
Copy link

xqft commented Mar 7, 2022

Removing MemoryDenyWriteExecute=true solved my problem.

@kabili207
Copy link
Author

kabili207 commented Mar 7, 2022

Removing MemoryDenyWriteExecute=true solved my problem.

I've removed this since it seems many people are having this issue

@stuie1952
Copy link

stuie1952 commented Mar 7, 2022

here is my script. it works for me.
cheers

[Unit]

Description=rclone: Remote FUSE filesystem for cloud storage config %i

Documentation=man:rclone(1)

After=network-online.target

Wants=network-online.target

AssertPathIsDirectory=%h/cloud/

[Service]

Type=notify

ExecStartPre=/bin/mkdir -p %h/cloud/%i

ExecStart= \

/usr/bin/rclone mount \

--config=%h/.config/rclone/rclone.conf \

--allow-non-empty \

--vfs-cache-mode writes \

--vfs-cache-max-size 100M \

--dir-cache-time 72h \

--vfs-read-chunk-size-limit 128M \

--vfs-read-chunk-size-limit off \

--log-level DEBUG \

--log-file /tmp/rclone-%i.log \

--umask 022 \

--allow-other \

%i: %h/cloud/%i

ExecStop=/bin/fusermount -uz %h/cloud/%i

ExecStop=/bin/rmdir %h/cloud/%i

[Install]

WantedBy=default.target

@lilws
Copy link

lilws commented Mar 7, 2022

Thanks, since last time too busy at work so I can't return here. On that date, I moved the service to different install target and it works. I do this on xpenology DSM 7.0.1. And the install location is multi-user.target, I've just moved it into syno-high-priority... and it works. But then I must figured how to run this service after synology mounted all HDDs, if not, rclone will complain it can't find the location to mount.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment