Systemd Mount failed at ExecStartPre=/usr/bin/test -d ${MOUNT_DIR} (code=exited, status=1/FAILURE)

What is the problem you are having with rclone?

Hi,
I followed this wiki to mount my google drive in ubuntu.
I run the command rclone lsd gd: and can get a listing of my top directories. (gd is my remote name)

I mount it by issuing the command systemctl --user start rclone@gd.
I get following message:
Job for rclone@gd.service failed because the control process exited with error code. See "systemctl --user status rclone@gd.service" and "journalctl -xe" for details.
I run the command systemctl --user status rclone@gd.service | cat to dump details(some personal information and non-English text are removed.)

● rclone@gd.service - RClone mount of users remote gd using filesystem permissions
   Loaded: loaded (/etc/systemd/user/rclone@.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since 2021-02-12 09:12:49 CST; 3min 58s ago
     Docs: http://rclone.org/docs/
  Process: 2533 ExecStartPre=/usr/bin/test -d ${MOUNT_DIR} (code=exited, status=1/FAILURE)
  Process: 2532 ExecStartPre=/usr/bin/test -x /usr/bin/rclone (code=exited, status=0/SUCCESS)

   12 09:12:49 systemd[1351]: Starting RClone mount of users remote gd using filesystem permissions...
   12 09:12:49 systemd[1351]: rclone@gd.service: Control process exited, code=exited status=1
   12 09:12:49 systemd[1351]: Failed to start RClone mount of users remote gd using filesystem permissions.
   12 09:12:49 systemd[1351]: rclone@gd.service: Unit entered failed state.
   12 09:12:49 systemd[1351]: rclone@gd.service: Failed with result 'exit-code'.

I have no idea how to fix the failure: ExecStartPre=/usr/bin/test -d ${MOUNT_DIR} (code=exited, status=1/FAILURE)

I also tried to add write permission of mounted folder.
sudo chmod 755 ~/gd
But it is not working and get the same error.

Here is my rclone@.service (modified from this wiki )

[Unit]
Description=RClone mount of users remote %i using filesystem permissions
Documentation=http://rclone.org/docs/
After=network-online.target


[Service]
Type=notify
#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"
#TODO: figure out default for the following parameter
Environment=RCLONE_MOUNT_DAEMON_TIMEOUT="UNKNOWN_DEFAULT"
Environment=RCLONE_MOUNT_DIR_CACHE_TIME="60m"
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"
#TODO: figure out default for the following parameter
Environment=RCLONE_MOUNT_VOLNAME="UNKNOWN_DEFAULT"

#Overwrite default environment settings with settings from the file if present
EnvironmentFile=-%h/.config/rclone/%i.env

#Check that rclone is installed
ExecStartPre=/usr/bin/test -x /usr/bin/rclone

#Check the mount directory
ExecStartPre=/usr/bin/test -d "${MOUNT_DIR}"
ExecStartPre=/usr/bin/test -w "${MOUNT_DIR}"
#TODO: Add test for MOUNT_DIR being empty -> ExecStartPre=/usr/bin/test -z "$(ls -A "${MOUNT_DIR}")"

#Check the rclone configuration file
ExecStartPre=/usr/bin/test -f "${RCLONE_CONF}"
ExecStartPre=/usr/bin/test -r "${RCLONE_CONF}"
#TODO: add test that the remote is configured for the rclone configuration

#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 \
            --cache-info-age=60m \
            --attr-timeout="${RCLONE_MOUNT_ATTR_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}" \
            "${REMOTE_NAME}:${REMOTE_PATH}" "${MOUNT_DIR}"

#Unmount rclone fs
ExecStop=/bin/fusermount -u "${MOUNT_DIR}"

#Restart info
Restart=on-success
RestartSec=10

[Install]
WantedBy=default.target

What is your rclone version (output from rclone version)

rclone v1.54.0
- os/arch: linux/386
- go version: go1.15.7

Which OS you are using and how many bits (eg Windows 7, 64 bit)

unbuntu 16.04 LTS

Which cloud storage system are you using? (eg Google Drive)

Google Drive

The command you were trying to run (eg rclone copy /tmp remote:tmp)

systemctl --user start rclone@gd

The rclone config contents with secrets removed.

jk@ubuntu:~$ cat ~/.config/rclone/rclone.conf
[gd]
type = drive
client_id = xxx
client_secret = yyy
scope = drive
token = {"access_token":zzz}

A log from the command with the -vv flag

Paste  log here

Thanks for seeing my question and looking forward to reply.

hello and welcome to the forum,

here at the forum, this is the goto guide for systemd, written by @Animosity022.
https://github.com/animosity22/homescripts/blob/master/systemd/rclone.service

this does nothing, based on your config, these are for the depreciated cache storage system.

https://rclone.org/cache/
--cache-chunk-path
--cache-db-path
--cache-writes
--cache-workers
--cache-tmp-upload-path
--cache-info-age

This means the mount directory doesn't exist. You need to mkdir it first.

Thanks for your reply.
I followed this example to create the "gd" folder.

jk@jk:~$ sudo mkdir ~/gd
jk@jk:~$ ls
Desktop    Downloads         gd     Pictures  Templates
Documents  examples.desktop  Music  Public    Videos
jk@jk:~$ sudo mkdir ~/gd
mkdir: cannot create directory ‘/home/jk/gd’: File exists

The 'gd' folder has been created, but it is still not working with the same error.

systemctl --user start rclone@gd
systemctl --user start rclone@gd
Job for rclone@gd.service failed because the control process exited with error code. See "systemctl --user status rclone@gd.service" and "journalctl -xe" for details.

I saw the service file at this line.
Environment=MOUNT_DIR="%h/%i"
Is MOUNT_DIR = /home/jk/gd? (user name = jk)
If yes, I supposed I have created the folder.
If no, where do I have to create the folder?
Thanks

You don't want to create it as root, create it as you. So do

sudo rmdir ~/gd
mkdir ~/gd

What did journalctl -xe say?

Thanks for reply.

Here is the dump, but I didn't find any clue.

   13 20:50:33 jk-jk systemd[1114]: Reloading.
   13 20:50:38 jk-jk systemd[1114]: Starting RClone mount of users remote gd using filesystem permissions...
-- Subject: Unit UNIT has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit UNIT has begun starting up.
   13 20:50:38 jk-jk systemd[1114]: rclone@gd.service: Control process exited, code=exited status=1
   13 20:50:38 jk-jk systemd[1114]: Failed to start RClone mount of users remote gd using filesystem permissions.
-- Subject: Unit UNIT has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit UNIT has failed.
-- 
-- The result is failed.
   13 20:50:38 jk-jk systemd[1114]: rclone@gd.service: Unit entered failed state.
   13 20:50:38 jk-jk systemd[1114]: rclone@gd.service: Failed with result 'exit-code'.

Finally, I found the root cause.
There are some typos in this line:
Environment=MOUNT_DIR="%h/%i".
Must be modified like this
Environment=MOUNT_DIR=%h/%i
There is no double quotes " on both sides of %h/%i
Besides, I correct other typos in this file and the file can be run at startup.
Here is my modified file via sudo cat /etc/systemd/user/rclone@.service to dump.

[Unit]
Description=RClone mount of users remote %i using filesystem permissions
Documentation=http://rclone.org/docs/
After=network-online.target

[Service]
Type=notify
#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"
#TODO: figure out default for the following parameter
Environment=RCLONE_MOUNT_DAEMON_TIMEOUT="UNKNOWN_DEFAULT"
Environment=RCLONE_MOUNT_DIR_CACHE_TIME=60m
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=writes
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"
#TODO: figure out default for the following parameter
Environment=RCLONE_MOUNT_VOLNAME="UNKNOWN_DEFAULT"

#Overwrite default environment settings with settings from the file if present
EnvironmentFile=-%h/.config/rclone/%i.env

#Check that rclone is installed
ExecStartPre=/usr/bin/test -x /usr/bin/rclone

#Check the mount directory
ExecStartPre=/usr/bin/test -d "${MOUNT_DIR}"
ExecStartPre=/usr/bin/test -w "${MOUNT_DIR}"
#TODO: Add test for MOUNT_DIR being empty -> ExecStartPre=/usr/bin/test -z "$(ls -A "${MOUNT_DIR}")"

#Check the rclone configuration file
ExecStartPre=/usr/bin/test -f "${RCLONE_CONF}"
ExecStartPre=/usr/bin/test -r "${RCLONE_CONF}"
#TODO: add test that the remote is configured for the rclone configuration

#Mount rclone fs
ExecStart=/usr/bin/rclone mount \
            "${REMOTE_NAME}:" "${MOUNT_DIR}" \
            --config="${RCLONE_CONF}" \
            --allow-other \
            --allow-non-empty \
            --vfs-cache-mode="${RCLONE_MOUNT_VFS_CACHE_MODE}" 
#            --default-permissions \
#            --cache-tmp-upload-path="${RCLONE_TEMP_DIR}/upload" \
#            --cache-chunk-path="${RCLONE_TEMP_DIR}/chunks" \
#            --dir-cache-time="${RCLONE_MOUNT_DIR_CACHE_TIME}" 
#            --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 \
#            --cache-info-age=60m \
#            --attr-timeout="${RCLONE_MOUNT_ATTR_TIMEOUT}" \
#            --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-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}" \

#Unmount rclone fs
ExecStop=/bin/fusermount -u "${MOUNT_DIR}"

#Restart info
Restart=on-success
RestartSec=10

[Install]
WantedBy=default.target

Another key typo is this
"${REMOTE_NAME}:${REMOTE_PATH}" "${MOUNT_DIR}"
I remote ${REMOTE_PATH}, which is \, between "${REMOTE_NAME}:" "${MOUNT_DIR}"

The modified line like this:
"${REMOTE_NAME}:" "${MOUNT_DIR}" \
It is working to mount my remote drive!

I learned how to debug these variable. It will be good to print these variables into a file and see is it the same as I think.
Here is my debug file

[Unit]
Description=Debug RClone Service
After=network-online.target

[Service]
Type=notify
KillMode=none
#Environment=MOUNT_DIR="%h/%i" this line failed at ExecStartPre=/usr/bin/test -d "${MOUNT_DIR}"
Environment=MOUNT_DIR=%h/%i
Environment=RCLONE_CONF=%h"/.config/rclone/rclone.conf"

ExecStartPre = /bin/sh -c 'echo "[`date -u +%Y-%%m-%dT%T.%3NZ`] rclone Starting print variables: [%h]-[%i]-[${MOUNT_DIR}]-[${RCLONE_CONF}]" >> /home/jk/rcloneDebug.txt'
ExecStartPre=/usr/bin/test -d "${MOUNT_DIR}"

ExecStart=/usr/bin/rclone mount gd: /home/jk/gd \
--allow-other \
--dir-cache-time 60m

#Unmount rclone fs
ExecStop=/bin/fusermount -u /home/jk/gd

#Restart info
Restart=on-success
RestartSec=10

[Install]
WantedBy=multi-user.target

I did not test all commands yet. It can be some typos in these marked commands. Hope someone can test them in the future.

Thank you all for a lot of support. :smile:

I use a much simpler systemd config like this which works fine for my purposes - adjust the command for your own preferences.

This command provides the mount that https://beta.rclone.org is served from

# Rclone mount on boot ( service file template - add aditional rclone parameters )
# Copy file to: /etc/systemd/system
# Set remote name, path to mount and User,Group
# Register new service by typing:
# sudo systemctl daemon-reload
# sudo systemctl enable rclone-mount.service
# systemctl start rclone-mount.service
# systemctl enable NetworkManager-wait-online.service
# Usage:
# To unmount drive use
# systemctl stop rclone-mount.service
# To mount use:
# systemctl start rclone-mount.service

[Unit]
Description=rclone mount
Documentation=http://rclone.org/docs/
After=network-online.target

[Service]
Type=notify
User=www-data
Group=www-data
ExecStart=/usr/bin/rclone mount -v --read-only --config /home/www-data/.rclone.conf --cache-dir /home/www-data/.cache/rclone --dir-cache-time 1m --vfs-cache-mode full --vfs-cache-max-age 168h --allow-non-empty --allow-other --use-mmap=true --vfs-cache-max-size 30G --rc memstore:beta-rclone-org /mnt/beta.rclone.org
ExecStop=/bin/fusermount -uz /mnt/beta.rclone.org
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

Thank you. The template is much simpler for me.
I will adjust the template for my purpose.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.