Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mount multiple RClone remotes on boot with a single SystemD forking service definition
# Rclone mount on boot
# Copy file to: /lib/systemd/system
# You need to create a remote on RClone and a folder on your disk, both with same name <rclone-remote>
# This example uses /cloud/ folder as origin to mount all remotes, change it to your needs
# This example use a linux user named rclone. Create it or adapt it to your needs. Rclone will get config from that user's home folder
# Register new service by typing:
# sudo systemctl daemon-reload
# Do the next one for every remote you want to load on boot
# sudo systemctl enable rclone-mount@<rclone-remote>.service
# systemctl start rclone-mount@<rclone-remote>.service
# Usage:
# To unmount drive use
# systemctl stop rclone-mount@<rclone-remote>.service
# To mount use:
# systemctl start rclone-mount@<rclone-remote>.service
# To disable mount on boot use:
# systemctl disable rclone-mount@<rclone-remote>.service
[Unit]
Description=rclone FUSE mount for %i
Documentation=http://rclone.org/docs/
After=network-online.target externo.mount # This is only needed if you use an external USB hard drive in order to wait for it to be mounted
# Mount point in my system is on a USB drive, don't ask why :))), that's why I have to wait for it to get mounted
Requires=externo.mount
[Service]
#Type=forking
# This example use a linux user named rclone. Create it or adapt it to your needs. Rclone will get config from that user's home folder
User=rclone
Group=rclone
# This example uses /cloud/ folder as origin to mount all remotes, change it to your needs
# --vfs-cache-mode full activates cache for writting and reading. Check RClone documentation
ExecStart=/usr/bin/rclone mount %i: /cloud/%i --vfs-cache-mode full -v --allow-other
ExecStop=/bin/fusermount -uz /cloud/%i
[Install]
#Wants=network-online.target
#Alias=rclone-rs
#RequiredBy=
WantedBy=multi-user.target
@gmag11

This comment has been minimized.

Copy link
Owner Author

@gmag11 gmag11 commented Jun 7, 2019

Con el parámetro --vfs-cache-mode full que va en la llamada a rclone se comporta muchísimo más estable. Cuando escribes un fichero primero lo sube a la caché y después a la nube, pero durante el proceso el archivo estará bloqueado.

Hay que tener paciencia. No sirve para usarlo como almacenamiento normal pero es muy cómodo para enviar archivos en bloque
--allow-other permite acceder al almacenamiento al resto de usuarios, incluido www-data para usarlo, por ejemplo, con NextCloud.

@esturniolo

This comment has been minimized.

Copy link

@esturniolo esturniolo commented Nov 18, 2019

Hola. Encontré tu comentario googleando.
Te ha dado problemas realizar mas de un mountpoint con rclone? Cuántos has llegado a montar en un mismo sistema?
Mi idea es hacerlo con 4 o 5 para que accedan diferentes usuarios por Nextcloud.
Un usuario = un mountpoint de rclone.

@gmag11

This comment has been minimized.

Copy link
Owner Author

@gmag11 gmag11 commented Nov 29, 2019

Tengo más de diez nobes montadas. Cada punto de motaje puede tener usuario diferente. Lo importante es que el punto de montaje se llame igual que la entrada en rclone

@esturniolo

This comment has been minimized.

Copy link

@esturniolo esturniolo commented Nov 29, 2019

Muchas gracias!

@adriaurora

This comment has been minimized.

Copy link

@adriaurora adriaurora commented Mar 26, 2020

¡Muchas gracias por estas líneas!

@mytvpro

This comment has been minimized.

Copy link

@mytvpro mytvpro commented Apr 21, 2020

hi i seem to be misundestanding something. i have multiple remotes mounted in different places. this will only work if they are mount in same dir? should i create a separate service file for each dir then? i have multiple mounts in one dir, one mount in another, and another mount in another. should i create 3 services?

@mytvpro

This comment has been minimized.

Copy link

@mytvpro mytvpro commented Apr 21, 2020

sometimes my mount fails. where df no longer shows the mount point. then i re-mount it and its fine. not sure why this happens. can anything be done in service file to correct a failed mount? or should i perhaps edit the service to unmount before it mounts and then reload the service once a day or something as preventive measure?

---edit perhaps this is from me using & instead of nohup or even --daemon i will stray the latter first

@mytvpro

This comment has been minimized.

Copy link

@mytvpro mytvpro commented Apr 21, 2020

is there advantage to Type = forking? why is the line commented?
from rclone.org:

systemd When running rclone mount as a systemd service, it is possible to use Type=notify. In this case the service will enter the started state after the mountpoint has been successfully set up. Units having the rclone mount service specified as a requirement will see all files and folders immediately in this mode.

should Type = notify be used?

@gmag11

This comment has been minimized.

Copy link
Owner Author

@gmag11 gmag11 commented Apr 25, 2020

hi i seem to be misundestanding something. i have multiple remotes mounted in different places. this will only work if they are mount in same dir? should i create a separate service file for each dir then? i have multiple mounts in one dir, one mount in another, and another mount in another. should i create 3 services?

I have every mount inside /cloud/ directory. You have to create folder first. For instance, if you like to mount Google Drive you can follow these steps, after copying service file onto /lib/systemd/system/:

  1. Create a folder on /cloud/. For instance GDrive_user
  2. Create a rclone configuration named the same. GDrive_user
  3. Use systemctl to start mount: sudo systemctl enable rclone-mount@GDrive_user`
  4. Check mount status with: sudo service rclone-mount@GDrive_user status`
  5. You should be able to list files with ls /cloud/GDrive_user
  6. You can enable mount with: sudo service rclone-mount@GDrive_user startand stop it withsudo service rclone-mount@GDrive_user stop

Notice that I'm using a user called rclone. You can change it with yours here

@gmag11

This comment has been minimized.

Copy link
Owner Author

@gmag11 gmag11 commented Apr 25, 2020

is there advantage to Type = forking? why is the line commented?
from rclone.org:

systemd When running rclone mount as a systemd service, it is possible to use Type=notify. In this case the service will enter the started state after the mountpoint has been successfully set up. Units having the rclone mount service specified as a requirement will see all files and folders immediately in this mode.

should Type = notify be used?

I did not notice that, thank you. Please share your findings about that here and propose an edit if you like

@bmaehr

This comment has been minimized.

Copy link

@bmaehr bmaehr commented Apr 26, 2020

aptitude install rclone fuse

# Rclone mount on boot
# Register new service by typing:
# sudo systemctl daemon-reload
# Do the next one for every remote you want to load on boot
# sudo systemctl enable rclone-mount@<rclone-remote>.service
# systemctl start rclone-mount@<rclone-remote>.service
# Usage:
# To unmount drive use
# systemctl stop rclone-mount@<rclone-remote>.service
# To mount use:
# systemctl start rclone-mount@<rclone-remote>.service
# To disable mount on boot use:
# systemctl disable rclone-mount@<rclone-remote>.service


[Unit]
Description=rclone fuse mount for %i
Documentation=https://gist.github.com/gmag11/dc139ffd6a8ca8b622e98ca6422f8d79
AssertPathIsDirectory=/mnt/%i
After=network-online.target

[Service]
# Type=forking
# User=rclone
# Group=rclone
ExecStart=/usr/bin/rclone mount %i: /mnt/%i --vfs-cache-mode full -v --allow-other 
ExecStop=/bin/fusermount -uz /mnt/%i
# --vfs-cache-mode full activates cache for writting and reading. Check RClone documentation

[Install]
#Wants=network-online.target
#Alias=rclone-rs
#RequiredBy=
WantedBy=multi-user.target
@Zarrapo

This comment has been minimized.

Copy link

@Zarrapo Zarrapo commented Oct 26, 2021

¿Cual es la razon por la que se usa /lib/systemd/system en lugar de /etc/systemd/system para el servicio?

@Zarrapo

This comment has been minimized.

Copy link

@Zarrapo Zarrapo commented Oct 26, 2021

Como a mi me ha costado entenderlo, he procurado facilitar el camino a otros neofitos como yo en el systemd

# Service: rclone-mount@.service

# Documentation:
# https://rclone.org/docs/
# https://gist.github.com/gmag11/dc139ffd6a8ca8b622e98ca6422f8d79

# Rclone mount on boot
# Copy file to: /lib/systemd/system/rclone-mount@.service

# You need to create a remote on RClone and a folder on your disk, both with same name <rclone-remote>
# This example uses /mnt folder as origin to mount all remotes
# 	Example rclone.conf
#	[onedrive-principal]
#	type = onedrive
#	token = {"access_token":"TrCQA8B ...  E$","expiry":"2026-10-27T17:08:31.897968077+02:00"}
#	drive_id = 1dd31928XXXXXXXX
#	drive_type = personal
#	[onedrive-secundario]
#	type = onedrive
#	token = {"access_token":"TrCQA8B ...  E$","expiry":"2026-10-27T17:08:31.897968077+02:00"}
#	drive_id = 6731928XXXXXXXX
#	drive_type = personal

# 	Example folders
#	/mnt/onedrive-principal
#	/mnt/onedrive-secundario

# Register new service by typing:
# 	$ sudo systemctl daemon-reload
# Do the next one for every remote you want to load on boot
# 	$ sudo systemctl enable rclone-mount@<rclone-remote>.service
# 	$ sudo systemctl start rclone-mount@<rclone-remote>.service
# Do the next one for test
#	$ sudo systemctl status rclone-mount@<rclone-remote>.service

# Usage:
# To unmount drive use
# 	$ sudo systemctl stop rclone-mount@<rclone-remote>.service
# To mount use:
# 	$ sudo systemctl start rclone-mount@<rclone-remote>.service
# To disable mount on boot use:
# 	$ systemctl disable rclone-mount@<rclone-remote>.service
# To do Test
# 	$ rclone mount <rclone-remote>: /mnt/<rclone-remote> --vfs-cache-mode full -v --allow-other --daemon
#	$ ls /mnt/<rclone-remote>
#	$ fusermount -u /mnt/<rclone-remote>

# Nota: El parametro %i se cargara con el valor <rclone-remote>.service en la llamada de systemctl

[Unit]
Description=rclone fuse mount for %i
Documentation=https://gist.github.com/gmag11/dc139ffd6a8ca8b622e98ca6422f8d79
AssertPathIsDirectory=/mnt/%i
After=network.target network-online.target

[Service]
User=german # Es que me llamo German tambien ;), no es coba
Group=german
Restart=on-failure
ExecStart=/usr/bin/rclone mount %i: /mnt/%i --vfs-cache-mode full -v --allow-other --no-modtime
ExecStop=/bin/fusermount -uz /mnt/%i

[Install]
WantedBy=multi-user.target
@gmag11

This comment has been minimized.

Copy link
Owner Author

@gmag11 gmag11 commented Nov 22, 2021

Como a mi me ha costado entenderlo, he procurado facilitar el camino a otros neofitos como yo en el systemd

# Service: rclone-mount@.service

# Documentation:
# https://rclone.org/docs/
# https://gist.github.com/gmag11/dc139ffd6a8ca8b622e98ca6422f8d79

# Rclone mount on boot
# Copy file to: /lib/systemd/system/rclone-mount@.service

# You need to create a remote on RClone and a folder on your disk, both with same name <rclone-remote>
# This example uses /mnt folder as origin to mount all remotes
# 	Example rclone.conf
#	[onedrive-principal]
#	type = onedrive
#	token = {"access_token":"TrCQA8B ...  E$","expiry":"2026-10-27T17:08:31.897968077+02:00"}
#	drive_id = 1dd31928XXXXXXXX
#	drive_type = personal
#	[onedrive-secundario]
#	type = onedrive
#	token = {"access_token":"TrCQA8B ...  E$","expiry":"2026-10-27T17:08:31.897968077+02:00"}
#	drive_id = 6731928XXXXXXXX
#	drive_type = personal

# 	Example folders
#	/mnt/onedrive-principal
#	/mnt/onedrive-secundario

# Register new service by typing:
# 	$ sudo systemctl daemon-reload
# Do the next one for every remote you want to load on boot
# 	$ sudo systemctl enable rclone-mount@<rclone-remote>.service
# 	$ sudo systemctl start rclone-mount@<rclone-remote>.service
# Do the next one for test
#	$ sudo systemctl status rclone-mount@<rclone-remote>.service

# Usage:
# To unmount drive use
# 	$ sudo systemctl stop rclone-mount@<rclone-remote>.service
# To mount use:
# 	$ sudo systemctl start rclone-mount@<rclone-remote>.service
# To disable mount on boot use:
# 	$ systemctl disable rclone-mount@<rclone-remote>.service
# To do Test
# 	$ rclone mount <rclone-remote>: /mnt/<rclone-remote> --vfs-cache-mode full -v --allow-other --daemon
#	$ ls /mnt/<rclone-remote>
#	$ fusermount -u /mnt/<rclone-remote>

# Nota: El parametro %i se cargara con el valor <rclone-remote>.service en la llamada de systemctl

[Unit]
Description=rclone fuse mount for %i
Documentation=https://gist.github.com/gmag11/dc139ffd6a8ca8b622e98ca6422f8d79
AssertPathIsDirectory=/mnt/%i
After=network.target network-online.target

[Service]
User=german # Es que me llamo German tambien ;), no es coba
Group=german
Restart=on-failure
ExecStart=/usr/bin/rclone mount %i: /mnt/%i --vfs-cache-mode full -v --allow-other --no-modtime
ExecStop=/bin/fusermount -uz /mnt/%i

[Install]
WantedBy=multi-user.target

Genial. Muchas gracias! Tocayo

@gmag11

This comment has been minimized.

Copy link
Owner Author

@gmag11 gmag11 commented Nov 22, 2021

¿Cual es la razon por la que se usa /lib/systemd/system en lugar de /etc/systemd/system para el servicio?

Seguramente es igual. Quizá incluso sea más correcto usar /etc

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