Skip to content

Instantly share code, notes, and snippets.

@kabili207
Last active April 20, 2024 15:54
Show Gist options
  • Save kabili207/2cd2d637e5c7617411a666d8d7e97101 to your computer and use it in GitHub Desktop.
Save kabili207/2cd2d637e5c7617411a666d8d7e97101 to your computer and use it in GitHub Desktop.
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. If you aren't using a desktop environment, such as on a server, this option can be omitted.

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 --now 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 --now 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
[Service]
Type=notify
ExecStartPre=-/usr/bin/mkdir -p %h/mnt/%i
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
@icservis
Copy link

Work nicely form me for first run, but after restart, I get error nonempty directory:
024/01/15 21:35:36 mount helper error: fusermount: mountpoint is not empty
2024/01/15 21:35:36 mount helper error: fusermount: if you are sure this is safe, use the 'nonempty' mount option
2024/01/15 21:35:36 Fatal error: failed to mount FUSE fs: fusermount: exit status 1

Trying to use option nonempty, but get:
2024/01/15 21:36:50 ERROR : -o/--option not supported with this FUSE backend

Running Proxmox 8. Help appreciated. Thanks a lot

@yanisallouch
Copy link

yanisallouch commented Jan 22, 2024

Sure! Here is a better version of the text:

Hello, I'm having some trouble with the drive mounting script. When I mount the folders, they appear empty in Nautilus. I'm using two Google Drive accounts, A and B, each with two namespaces: personal and shared. The file structure is as follows:

~/drive/{account}/{namespace}

This works just fine using Rclone Browser. However, when I use the script provided above, I can mount the folders to /mnt/drive/%i, but they are empty.

@kabili207
Copy link
Author

@yanisallouch Did you make the change to /etc/fuse.conf mentioned in the preparation section? It is required for many desktop environments and will result in the "empty folder" issue you're seeing if you skip it.

@yanisallouch
Copy link

@kabili207 Yes :

# The file /etc/fuse.conf allows for the following parameters:
#
# user_allow_other - Using the allow_other mount option works fine as root, in
# order to have it work as user you need user_allow_other in /etc/fuse.conf as
# well. (This option allows users to use the allow_other option.) You need
# allow_other if you want users other than the owner to access a mounted fuse.
# This option must appear on a line by itself. There is no value, just the
# presence of the option.

user_allow_other


# mount_max = n - this option sets the maximum number of mounts.
# Currently (2014) it must be typed exactly as shown
# (with a single space before and after the equals sign).

#mount_max = 1000

@nilreml
Copy link

nilreml commented Mar 15, 2024

Thanks @kabili207 and everyone else who contributed here! Very useful indeed.

I created a small repo out of all this - if you have any objections, please let me know and I'll take it down or modify it accordingly.

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