Skip to content

Instantly share code, notes, and snippets.

@gmag11
Last active March 27, 2024 04:01
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save gmag11/dc139ffd6a8ca8b622e98ca6422f8d79 to your computer and use it in GitHub Desktop.
Save gmag11/dc139ffd6a8ca8b622e98ca6422f8d79 to your computer and use it in GitHub Desktop.
Mount multiple RClone remotes on boot with a single SystemD forking service definition
# Rclone mount on boot
# Copy file to: /etc/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
@juandpineiro
Copy link

juandpineiro commented Nov 5, 2022

Saludos!

Bueno leyendo los pasos que has seguido para tratar de que los montajes se realicen luego de un periodo de tiempo, pareciera que está todo en orden.

Una vez que modificaste los servicios, ejecutaste el comando sudo systemctl daemon-reload ? Para que systemd utilice los servicios modificados.

Otra cosa que podría ayudar es añadir la siguiente linea:

[Unit]
After=network.target

Es decir, la linea After=network.target justo después de [Unit] para que el servicio solo se ejecute una vez haya conexión de red. Esto debería eliminar la necesidad de sleep. De nuevo al hacer las modificaciones en los archivos, ejecuta sudo systemclt daemon-reload.

@moha20051985
Copy link

moha20051985 commented Nov 7, 2022

Saludos!

Bueno leyendo los pasos que has seguido para tratar de que los montajes se realicen luego de un periodo de tiempo, pareciera que está todo en orden.

Una vez que modificaste los servicios, ejecutaste el comando sudo systemctl daemon-reload ? Para que systemd utilice los servicios modificados.

Otra cosa que podría ayudar es añadir la siguiente linea:

[Unit]
After=network.target

Es decir, la linea After=network.target justo después de [Unit] para que el servicio solo se ejecute una vez haya conexión de red. Esto debería eliminar la necesidad de sleep. De nuevo al hacer las modificaciones en los archivos, ejecuta sudo systemclt daemon-reload.

Gracias por la ayuda, si ya recarge el daemon antes de de enable. sobre lo de After=network.target , ya esta metido en la cabecera. De todas maneras os paso mi montaje, por si hubiera algo raro...

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

[Service]
User=root
Group=root
Restart=on-failure
ExecStartPre=/bin/sleep 5
ExecStart=/usr/bin/rclone mount %i: /%i --allow-other --vfs-cache-mode writes --buffer-size 256M --dir-cache-time 72h --drive-chunk-size 32M --fast-list --log-file /home/Rclone_logs/rclone_debug.log --vfs-read-chunk-size 128M --vfs-read-chunk-size-limit off
ExecStop=/bin/fusermount -uz /%i

[Install]
WantedBy=multi-user.target

Saludos y gracias de nuevo

@ADOBApps
Copy link

ADOBApps commented Mar 2, 2023

Buenas noches, vengo a compartirles la configuración con la que logré montar el servicio, seguí todas las intrucciones sin embargo no me funcionaba, (cabe resaltar que esto lo llevé a cabo en una antigua computadora con Lubuntu 18.04.5). Siguiendo las instrucciones lograba montar las unidades sin embargo el sistema de archivos no reconocía los "mountpoint" como carpetas y no era posible acceder a estos. Tras horas de busqueda, recordé que la función experimental rclone gui web había logrado montar las unidades sin problema, fui y revicé usando la documentación y logré llegar a esto

`[Unit]
Description=rclone FUSE mount for %i
#Wants=network-online.target
After=network-online.target

[Service]
Type=notify
TimeoutStopSec=60
Environment=GOMAXPROCS=2

User=root
Group=root

ExecStart=/usr/bin/rclone mount remote_drive: /media/SharedFiles/Gdrive_workstation
--config /home/user/.config/rclone/rclone.conf
--use-mmap
--poll-interval=15s
--vfs-cache-mode full
--tpslimit 10
--vfs-write-back 5000000000s
--vfs-cache-max-age 3600000000000
--vfs-cache-poll-interval 60000000000
--async-read
--attr-timeout 1000000000
--max-read-ahead 131072
--noappledouble
--umask 2
--uid 1000
--file-perms 666
--dir-perms 777
--gid 1000
--dir-cache-time 300000000000
--vfs-read-chunk-size 134217728
--allow-root
--allow-other
--default-permissions

ExecStop=/bin/fusermount -uz /media/SharedFiles/Gdrive_workstation

[Install]
WantedBy=multi-user.target
`

@ADOBApps
Copy link

ADOBApps commented Mar 2, 2023

Buenas noches, vengo a compartirles la configuración con la que logré montar el servicio, seguí todas las intrucciones sin embargo no me funcionaba, (cabe resaltar que esto lo llevé a cabo en una antigua computadora con Lubuntu 18.04.5). Siguiendo las instrucciones lograba montar las unidades sin embargo el sistema de archivos no reconocía los "mountpoint" como carpetas y no era posible acceder a estos. Tras horas de busqueda, recordé que la función experimental rclone gui web había logrado montar las unidades sin problema, fui y revicé usando la documentación y logré llegar a esto

`[Unit] Description=rclone FUSE mount for %i #Wants=network-online.target After=network-online.target

[Service] Type=notify TimeoutStopSec=60 Environment=GOMAXPROCS=2

User=root Group=root

ExecStart=/usr/bin/rclone mount remote_drive: /media/SharedFiles/Gdrive_workstation --config /home/user/.config/rclone/rclone.conf --use-mmap --poll-interval=15s --vfs-cache-mode full --tpslimit 10 --vfs-write-back 5000000000s --vfs-cache-max-age 3600000000000 --vfs-cache-poll-interval 60000000000 --async-read --attr-timeout 1000000000 --max-read-ahead 131072 --noappledouble --umask 2 --uid 1000 --file-perms 666 --dir-perms 777 --gid 1000 --dir-cache-time 300000000000 --vfs-read-chunk-size 134217728 --allow-root --allow-other --default-permissions

ExecStop=/bin/fusermount -uz /media/SharedFiles/Gdrive_workstation

[Install] WantedBy=multi-user.target `

@ADOBApps
Copy link

ADOBApps commented Mar 3, 2023

Buenas noches, vengo a compartirles la configuración con la que logré montar el servicio, seguí todas las intrucciones sin embargo no me funcionaba, (cabe resaltar que esto lo llevé a cabo en una antigua computadora con Lubuntu 18.04.5). Siguiendo las instrucciones lograba montar las unidades sin embargo el sistema de archivos no reconocía los "mountpoint" como carpetas y no era posible acceder a estos. Tras horas de busqueda, recordé que la función experimental rclone gui web había logrado montar las unidades sin problema, fui y revicé usando la documentación y logré llegar a esto

`[Unit] Description=rclone FUSE mount for %i #Wants=network-online.target After=network-online.target

[Service] Type=notify TimeoutStopSec=60 Environment=GOMAXPROCS=2

User=root Group=root

ExecStart=/usr/bin/rclone mount remote_drive: /media/SharedFiles/Gdrive_workstation --config /home/user/.config/rclone/rclone.conf --use-mmap --poll-interval=15s --vfs-cache-mode full --tpslimit 10 --vfs-write-back 5000000000s --vfs-cache-max-age 3600000000000 --vfs-cache-poll-interval 60000000000 --async-read --attr-timeout 1000000000 --max-read-ahead 131072 --noappledouble --umask 2 --uid 1000 --file-perms 666 --dir-perms 777 --gid 1000 --dir-cache-time 300000000000 --vfs-read-chunk-size 134217728 --allow-root --allow-other --default-permissions

ExecStop=/bin/fusermount -uz /media/SharedFiles/Gdrive_workstation

[Install] WantedBy=multi-user.target `

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