Hey All,
I recently spent some time figuring out how to get an rclone mount up and running VIA systemd. Maybe you are already beyond this point, but wanted to provide my example if not (also open to any issues you find with it!). It is a templated user systemd service, so any user can use it and you can easily create mounts for all of your remotes without changing any of the systemd service file.
I will include the service file at the bottom of my post, and an explanation here.
First, lets get the service installed. Lets say that you save the file to /etc/systemd/user/rclone@.service
(note, the "@" at the end of the name of the service is what makes the service a templated service). After saving the file to the file system, be sure to issue the command to tell systemd to look for the new/changed service files with systemctl --user daemon-reload
.
Next, we will go over the prerequisites for using the systemd mount. First off, you have to already have your remote configured via rclone. For this example, i am going to assume the remote you have configured is called "dropbox-personal". If you can run the command rclone lsd dropbox-personal:
and get a listing of your top directories, then your remote is configured already. You will also need an empty directory, for which you have write permissions, where you will mount your remote. The service file's default location for this mount would be ~/dropbox-personal
(based on the remote name). The service file also assumes a default rclone configuration file location of ~/.config/rclone/rclone.conf
. The service file also assumes other defaults based on the rclone mount
documentation. All of these defaults can be overridden in the file ~/.config/dropbox-personal.env
. Overriding defaults and other advanced configurations will be discussed after the service file
Now that we have checked the prerequisites, it is time to mount your remote. you can mount it by issuing the command systemctl --user start rclone@dropbox-personal
. Then, once you are sure it is working, you can enable it so that it occurs at login with the following command systemctl --user enable rclone@dropbox-personal
.
Note: The script I am providing includes the --allow-other
and --default-permissions
parameters. Without --allow-other
, no one other than your user can access the mount. This may or may not be desirable. Removing it will not stop the mount from working, only change who can access it. The --default-permissions
parameter makes the mounted files respect the file permissions set on the file system and is only useful when used with --allow-other
. If --default-permissions
is not set when --allow-other
is set, then anyone can do anything (read, write, execute) regardless of what the file permissions are set to.
#To use this, /etc/fuse.conf must have the user_allow_other option set
[Unit]
Description=RClone mount of users remote %i using filesystem permissions
[Service]
Type=simple
#Set up environment
Environment=REMOTE_NAME="%i"
Environment=REMOTE_PATH="/"
Environment=MOUNT_DIR="%h/%i"
Environment=RCLONE_CONF="%h/.config/rclone/rclone.conf"
Environment=RCLONE_TEMP_DIR="/tmp/rclone/%u/%i"
#Default arguments for rclone mount. Can be overridden in the environment file
Environment=RCLONE_MOUNT_ATTR_TIMEOUT="1s"
# Environment=RCLONE_MOUNT_DAEMON_TIMEOUT="UNKNOWN_DEFULT"
Environment=RCLONE_MOUNT_DIR_CACHE_TIME="5m0s"
Environment=RCLONE_MOUNT_DIR_PERMS="0777"
Environment=RCLONE_MOUNT_FILE_PERMS="0666"
Environment=RCLONE_MOUNT_GID="%G"
Environment=RCLONE_MOUNT_MAX_READ_AHEAD="128k"
Environment=RCLONE_MOUNT_POLL_INTERVAL="1m0s"
Environment=RCLONE_MOUNT_UID="%U"
Environment=RCLONE_MOUNT_UMASK="022"
Environment=RCLONE_MOUNT_VFS_CACHE_MAX_AGE="1h0m0s"
Environment=RCLONE_MOUNT_VFS_CACHE_MAX_SIZE="off"
Environment=RCLONE_MOUNT_VFS_CACHE_MODE="off"
Environment=RCLONE_MOUNT_VFS_CACHE_POLL_INTERVAL="1m0s"
Environment=RCLONE_MOUNT_VFS_READ_CHUNK_SIZE="128M"
Environment=RCLONE_MOUNT_VFS_READ_CHUNK_SIZE_LIMIT="off"
# Environment=RCLONE_MOUNT_VOLNAME="UNKNOWN_DEFULT"
#Overwrite default environment settings with settings from the file if present
EnvironmentFile=-%h/.config/%i.env
#Use ExecStartPre to run conditions to make sure mount can occur
ExecStartPre=/usr/bin/test -x /usr/bin/rclone
ExecStartPre=/usr/bin/test -d "${MOUNT_DIR}"
ExecStartPre=/usr/bin/test -w "${MOUNT_DIR}"
#JMLTODO: Add test for directory being empty
ExecStartPre=/usr/bin/test -f "${RCLONE_CONF}"
ExecStartPre=/usr/bin/test -r "${RCLONE_CONF}"
#JMLTODO: Can't use pipe, need to do this another way
# ExecCondition=/usr/bin/rclone listremotes --config="${RCLONE_CONF}" | /usr/bin/grep -q "^${REMOTE_NAME}:$"
#Mount rclone fs
ExecStart=/usr/bin/rclone mount \
--config="${RCLONE_CONF}" \
--allow-other \
--default-permissions \
--cache-tmp-upload-path="${RCLONE_TEMP_DIR}/upload" \
--cache-chunk-path="${RCLONE_TEMP_DIR}/chunks" \
--cache-workers=8 \
--cache-writes \
--cache-dir="${RCLONE_TEMP_DIR}/vfs" \
--cache-db-path="${RCLONE_TEMP_DIR}/db" \
--no-modtime \
--drive-use-trash \
--stats=0 \
--checkers=16 \
--bwlimit=40M \
--dir-cache-time=60m \
--cache-info-age=60m \
--attr-timeout="${RCLONE_MOUNT_ATTR_TIMEOUT}" \
# --daemon-timeout="${RCLONE_MOUNT_DAEMON_TIMEOUT}" \
--dir-cache-time="${RCLONE_MOUNT_DIR_CACHE_TIME}" \
--dir-perms="${RCLONE_MOUNT_DIR_PERMS}" \
--file-perms="${RCLONE_MOUNT_FILE_PERMS}" \
--gid="${RCLONE_MOUNT_GID}" \
--max-read-ahead="${RCLONE_MOUNT_MAX_READ_AHEAD}" \
--poll-interval="${RCLONE_MOUNT_POLL_INTERVAL}" \
--uid="${RCLONE_MOUNT_UID}" \
--umask="${RCLONE_MOUNT_UMASK}" \
--vfs-cache-max-age="${RCLONE_MOUNT_VFS_CACHE_MAX_AGE}" \
--vfs-cache-max-size="${RCLONE_MOUNT_VFS_CACHE_MAX_SIZE}" \
--vfs-cache-mode="${RCLONE_MOUNT_VFS_CACHE_MODE}" \
--vfs-cache-poll-interval="${RCLONE_MOUNT_VFS_CACHE_POLL_INTERVAL}" \
--vfs-read-chunk-size="${RCLONE_MOUNT_VFS_READ_CHUNK_SIZE}" \
--vfs-read-chunk-size-limit="${RCLONE_MOUNT_VFS_READ_CHUNK_SIZE_LIMIT}" \
# --volname="${RCLONE_MOUNT_VOLNAME}"
"${REMOTE_NAME}:${REMOTE_PATH}" "${MOUNT_DIR}"
#Unmount rclone fs
ExecStop=/bin/fusermount -u "${MOUNT_DIR}"
#Restsart info
Restart=on-success
RestartSec=10
[Install]
WantedBy=default.target
Advanced usage:
Any of the service file environment variables (Environment=...
) can be overriden in a environment file. If you invoke the service as rclone@foobar
, then the override file would be ~/.config/foobar.env
. Below are some samples of what can be done with the override file. Please note that this file can contain any combination of variable specifications, it does not have to match the following examples.
The most common overrides I can see being used would be to override the rclone configuration location, the mount point, and/or the remote path to mount. To do that, I could create the following file
#~/.config/foobar.env
MOUNT_DIR=/mnt/some_custom_mount_point_dir
RCLONE_CONF=~/.rclone/rclone.conf
REMOTE_PATH=/some/directory/in/remote
The above file would modify the rclone@foobar
service so that the remote named foobar would be mounted at /mnt/some_custom_mount_point_dir
, using a rclone configuration file located at ~/.rclone/rclone.conf
, where the remote mounts everything under /some/directory/in/remote
.
You can also use this override functionality to mount the same remote multiple times. This could be useful if you want to mount a personal share, but it also contains configuration files you want to mount somewhere else on your system.
#~/.config/foobar-ddclient.env
REMOTE_NAME=foobar
MOUNT_DIR=/etc/ddclient
REMOTE_PATH=/configurations/ddclient
RCLONE_MOUNT_UID=0
RCLONE_MOUNT_GID=0
This would use the foobar remote, mount it at /etc/ddclient
, owned by the user and group root, starting at the remote directory /configurations/ddclient
. You can then issue the commands systemctl --user start rclone@foobar
and systemctl --user start rclone@foobar-ddclient
to mount the foobar remote with all default options, but then also mount the configured custom configured foobar remote.
Sorry for the long post, but hopefully this is helpful!
This is my first foray into rclone, but I see it as promising! As a side note, I'd love to see this service (or some iteration of it/better option), included in rclone in the future to help out others trying to achieve this same thing!
Edit 1+2: Fixed bugs with the service file