Rclone mount on startup with systemd

You need to give it a path to a config file with --config /path/to/config.file

Not sure what user that you’ll be starting it as, maybe you should make an rclone user to do this or do it under your own user. You do that by putting User=XXX in the [Service] section I think.

Isn’t there the necessary –config parameter?

i added a user, now the error log is down to

● rclonemount.service - rclonemount
   Loaded: loaded (/etc/systemd/system/rclonemount.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2016-12-02 15:49:02 CET; 2h 11min ago
 Main PID: 1235 (code=exited, status=1/FAILURE)

Dec 02 15:49:01 qp systemd[1]: Started rclonemount.
Dec 02 15:49:02 qp rclone[1235]: 2016/12/02 15:49:02 Failed to create file system for "gdriveencrypted:": failed to make remote "remotegdrive:encrypted" to wrap: couldn't read info about Drive: Get https://www.googleapis.com/drive/v2/about?alt=json: Post https://accounts.google.com/o/oauth2/token: dial tcp: lookup accounts.google.com on [::1]:53: read udp [::1]:55031->[::1]:53: read: connection refused
Dec 02 15:49:02 qp systemd[1]: rclonemount.service: Main process exited, code=exited, status=1/FAILURE
Dec 02 15:49:02 qp systemd[1]: rclonemount.service: Unit entered failed state.
Dec 02 15:49:02 qp systemd[1]: rclonemount.service: Failed with result 'exit-code'.

If I execute the same command rclone mount gdriveencrypted: /media/gdrivemount/ --config /root/.rclone.conf --allow-other --no-modtime --dir-cache-time 60m in a terminal, the mount works, so the google token should work.

Yes… Interesting that it complained about it. Must be something to do with the environment of systemd.

That looks like it is having trouble speaking to the name resolver - the udp reads on port 53. Not sure why that should be. It is trying to connect to [::1]:53 which is localhost port 53 in IPv6 speak. Are you running a nameserver on localhost?

not that I know of?

I also tried a fstab mount like described in this post https://github.com/ncw/rclone/issues/727#issuecomment-247061268. I get no errors but also no mount.

@mistermin were you able to fix this and automount via systemd ?

No, I didn’t get the automount with systemd working.

I have a pretty dumb workaround: I started a tmux session and mounted the drive there. It doesnt autostart after a boot but at least it stays mounted even when i close the ssh connection to the server.

If anyone has a better, working alternative, please comment :wink:

ok, I got it working

I was able to start it manually so my suspicion was that is was a timing issue. In your config there is a parameter TimeoutStartSec=10, but that isn’t doing what you expect it would do.
Configures the time to wait for start-up. If a daemon service does not signal start-up completion within the configured time, the service will be considered failed and will be shut down again

So it is not waiting 10 seconds, but it is considered failed when not started within 10 seconds

With systemd-analyze plot > plot.svg (image file can be opened in browser) I analyzed the systemd startup order and noticed that my rclonemount.service was very short after the network. so I pushed it back by making it depended of multi-user.target.
That seemed to do the trick

Still a bit dirty though I think, maybe the rclone mount command could get a wait command-line parameter before the actual mount is created

My systemd file rclonemount.service


ExecStart=/home/misteriks/Projects/Proj1/bin/rclone mount eacd: /home/misteriks/acd --config /home/misteriks/.rclone.conf --allow-other --max-read-ahead 200M --dir-cache-time 5m --acd-templink-threshold 0 --bwlimit 0 --checkers 32 --low-level-retries 1 --quiet --stats 0 --timeout 30s
ExecStop=fusermount -u /home/misteriks/acd


1 Like

I’d love a bit for the docs about this, either as a PR or an email!

I believe the most important bits are in my post. Anything specific you are looking for?

Some text I can drop in the mount docs would be perfect!

Make sure you have service enabled : https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/
systemctl enable systemd-networkd-wait-online.service

Then After=network-online.target will work

1 Like

Thank you so much for this. This is what worked for me using LibreELEC (Krypton).


ExecStartPre=/bin/mkdir -p /storage/remote
ExecStart=/storage/.config/rclone/rclone mount acd: /storage/remote --config /storage/.config/rclone/rclone.conf --checkers 16 --dir-cache-time 30m --quiet --read-only
ExecStop=/usr/bin/fusermount -u /storage/remote


Save it as: /storage/.config/system.d/rclonemount.service


How is it working on libreelec?

Sorry to bring back this subject but if we create a new user what permission it need to mount the remote on /mnt/***** ?

I can start the service by using systemctl start but it didn’t start at reboot :


ExecStart=/usr/sbin/rclone mount --config /home/user/.config/rclone/rclone.conf --allow-non-empty --allow-other --read-only --buffer-size 1G --timeout 5s --contimeout 5s --acd-templink-threshold 0 -v …
ExecStop=/bin/fusermount -u /mnt/encrypt


1 Like

This is the easiest way to daemonize a process from an SSH terminal and/or from a shell script:

( rclone mount --<options> <src> <dst> &)&

It will immediately echo back that the process has completed, but the backgrounded sub-shell will continue even when you log out. You can verify by logging out and then back in:

ps -e | grep rclone

The parent process with be pid 1, just as if you had started it from systemd.

If you want to start on boot, add this to crontab:

@reboot ( /path/to/rclone mount --<options> <src> <dst> &)&


I just use the @reboot in cron as doing the network.online never worked for me. I didn’t care to spend much time to troubleshoot it.

> felix@plex:~/scripts$ crontab -l | grep media_mount
> @reboot /home/felix/scripts/media_mount
> felix@plex:~/scripts$ cat media_mount
> # Mount GD Fuse
> #/usr/bin/google-drive-ocamlfuse /GD -o allow_other,auto_cache -headless -debug >> /home/felix/.gdfuse/default/mount.log 2>&1 &
> /usr/bin/google-drive-ocamlfuse /GD -o allow_other,auto_cache -verbose >> /home/felix/.gdfuse/default/mount.log 2>&1 &
> sleep 2

> # Mount the 3 Directories via rclone for the encrypt
> /usr/bin/rclone mount \
> --allow-other \
> --default-permissions \
> --uid 1000 \
> --gid 1000 \
> --umask 002 \
> --acd-templink-threshold 0 \
> --buffer-size 100M \
> --syslog \
> --stats 1m \
> -v \
> media: /media &

> # Wait a sec
> sleep 2
> /usr/bin/unionfs-fuse -o cow,allow_other,direct_io,auto_cache,sync_read /local/movies=RW:/media/Movies=RO /Movies
> /usr/bin/unionfs-fuse -o cow,allow_other,direct_io,auto_cache,sync_read /local/tv=RW:/media/TV=RO /TV

> # Prime the directories
> sleep 2
> cd /Movies
> ls -alR | wc -l
> cd /TV
> ls -alR | wc -l

I just a run a checker ever 5 minutes to validate nothing is bad. Little clunky but it does what it needs to do:

*/5 * * * * /home/felix/scripts/check_GD
felix@plex:~/scripts$ cat check_GD
if grep -qs '/local' /proc/mounts; then
	sleep 1
	echo "It's not mounted." | mail -s "/local not mounted" me@gmail.com
	exit 1

if grep -qs '/GD' /proc/mounts; then
    	#echo "It's mounted."

	if [[ -r $FILE && -w $FILE ]]
		#All is good
		#echo "File exists and is writeable"
		echo "/GD is not writeable" | mail -s "/GD not writeable" me@gmail.com
        	sleep 10
    	echo "It's not mounted." | mail -s "/GD not mounted" me@gmail.com
	sleep 10

I also would recommend setting the –syslog parameter. On my raspberry pi fuse claims that in the /etc.fuse.conf the user_allow_other option needs to be enabled if you use –allow-other parameter. And maybe you get some more output there.

Also use the -vv parameter for debug logging.

If you use the -vv flag, rclone will produce Error, Notice, Info and Debug messages.

I have some problems too mounting the drive with rclone on startup. When I start the service manually sudo systemctl start mount-rclone.service the drive mounts successfully. But at startup I got errors in the systemlog. Guess it’s because the wlan is not up at this time. Need to check in the next days.

Any news on this topic?

I am trying to do the same and since you said it needs to wait for the wifi, I did it like @misteriks in this topic and wait for multi-user.target. However, this is my error message in the logs:

2017/09/09 09:31:08 Failed to create file system for “onedrive:/”: failed to get root: Get https:// api.onedrive .com/v1.0/drive/root:/: Post https:// login.live. com/oauth20_token.srf: dial tcp: lookup login. live .com on [::1]:53: read udp [::1]:43541->[::1]:53: read: connection refused

(I had to separate the links in the log line above, new users are only allowed two links per post :stuck_out_tongue:)

And my systemd file looks like this now:


ExecStartPre=/bin/mkdir -p /home/pcmciakai/OneDrive
ExecStart=/usr/bin/rclone mount onedrive: /home/pcmciakai/OneDrive --config /home/pcmciakai/.config/rclone/rclone.conf --low-level-retries 1 --quiet --stats 0 --timeout 30s
ExecStop=/usr/bin/fusermount -u /home/pcmciakai/OneDrive
ExecStopPost=/bin/rmdir /home/pcmciakai/OneDrive


All the examples above have one issue: if the mount is currently busy, rclone will exit with nonzero status, fuser will not unmount and the directory will stay busy, trying to access it will result in a 'transport not connected' error. I won't speculate on who's job is to gracefully handle this, for the systemd to do it you need a ExecStop script:

exec 1>&2
# next line sends SIGTERM to any process accessing the mounted filesystem:
fuser -Mk -SIGTERM -m "$@"
while :;
    if fuser -m "$@";
        echo "Mount $@ is busy, waiting..."; sleep 1
        fusermount -u "$@"; exit 0


The script expects a mount point as its argument. It will send SIGTERM to any process that's accessing the mount (it's optional, can be commented out) and then waits for it to become free. If you comment out the SIGTERM sending line the service will endlessly wait until the mount becomes free.

A sample user service I used it with:

Description=Sample service for mounting a cloud storage with rclone

ExecStart=/usr/bin/rclone mount RemoteName: /path/to/mountpoint  --cache-dir "$XDG_RUNTIME_DIR" --vfs-cache-mode full --vfs-cache-max-size 262144 --umask 077
ExecStop=/path/to/the/script/above /path/to/mountpoint


p.s. If you need an rclone mount for use only when you're logged in, use systemd user service make things so much easier.

1 Like