Rclone mount on start up not working with systemd

What is the problem you are having with rclone?

I have created a rclone shell script to mount my google drive and it works perfectly, however when I set it up and run it with systemctl it does not work. It says mounted, but when I click on the mounted file it says endpoint is missing

Run the command 'rclone version' and share the full output of the command.

rclone v1.67.0

  • os/version: endeavouros (64 bit)
  • os/kernel: 6.10.1-arch1-1 (x86_64)
  • os/type: linux
  • os/arch: amd64
  • go/version: go1.22.4
  • go/linking: static
  • go/tags: none

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)

/home/ivan/scripts/RscloneGdrive.sh

#!/bin/bash
/usr/bin/rclone mount gdrive: /home/ivan/Google\ Drive/ --daemon --config /home/ivan/.config/rclone/rclone.conf --allow-non-empty --log-level DEBUG --log-file /tmp/rclone.log

then in /etc/systemd/system/Gdrive.service

[Unit]
Description=Rclone Google Drive Mount
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=ivan
Group=ivan
ExecStart=/home/ivan/scripts/RcloneGdrive.sh
Restart=on-failure
RestartSec=30

[Install]
WantedBy=multi-user.target

Please run 'rclone config redacted' and share the full output. If you get command not found, please make sure to update rclone.

[gdrive]
type = drive
scope = drive
token = XXX
team_drive = 

A log from the command that you were trying to run with the -vv flag

2024/07/27 16:27:31 DEBUG : rclone: Version "v1.67.0" starting with parameters ["/usr/bin/rclone" "mount" "gdrive:" "/home/ivan/Google Drive/" "--daemon" "--config" "/home/ivan/.config/rclone/rclone.conf" "--allow-non-empty" "--log-level" "DEBUG" "--log-file" "/tmp/rclone.log"]
2024/07/27 16:27:31 DEBUG : Creating backend with remote "gdrive:"
2024/07/27 16:27:31 DEBUG : Using config file from "/home/ivan/.config/rclone/rclone.conf"
2024/07/27 16:27:31 DEBUG : gdrive: Loaded invalid token from config file - ignoring
2024/07/27 16:27:31 DEBUG : Saving config "token" in section "gdrive" of the config file
2024/07/27 16:27:31 DEBUG : gdrive: Saved new token in config file
2024/07/27 16:27:31 DEBUG : Google drive root '': 'root_folder_id = REDACTED - save this in the config to speed up startup
2024/07/27 16:27:31 DEBUG : rclone: Version "v1.67.0" starting with parameters ["/usr/bin/rclone" "mount" "gdrive:" "/home/ivan/Google Drive/" "--daemon" "--config" "/home/ivan/.config/rclone/rclone.conf" "--allow-non-empty" "--log-level" "DEBUG" "--log-file" "/tmp/rclone.log"]
2024/07/27 16:27:31 DEBUG : Creating backend with remote "gdrive:"
2024/07/27 16:27:31 DEBUG : Using config file from "/home/ivan/.config/rclone/rclone.conf"
2024/07/27 16:27:32 DEBUG : Google drive root '': 'root_folder_id = REDACTED - save this in the config to speed up startup
2024/07/27 16:27:32 DEBUG : Google drive root '': Mounting on "/home/ivan/Google Drive/"
2024/07/27 16:27:32 DEBUG : : Root: 
2024/07/27 16:27:32 DEBUG : : >Root: node=/, err=<nil>
2024/07/27 16:27:32 DEBUG : /: Lookup: name=".Trash"
2024/07/27 16:27:32 DEBUG : rclone: Version "v1.67.0" finishing with parameters ["/usr/bin/rclone" "mount" "gdrive:" "/home/ivan/Google Drive/" "--daemon" "--config" "/home/ivan/.config/rclone/rclone.conf" "--allow-non-empty" "--log-level" "DEBUG" "--log-file" "/tmp/rclone.log"]
2024/07/27 16:27:32 INFO  : Signal received: terminated
2024/07/27 16:27:32 ERROR : /home/ivan/Google Drive/: Failed to unmount: exit status 1: fusermount3: failed to unmount /home/ivan/Google Drive: Device or resource busy
2024/07/27 16:27:32 INFO  : Exiting...

I've done systemctl daemon-reload and systemctl start GDrive.service, but nothing works. I've unmounted before running these two command and I have also restarted the entire PC. The only solution I've seen that works is putting the script into /etc/profile.d, but I've read it's not a good solution because running su will run the script again or smth like that?

P.S. new to linux

Highly likely that it runs too early - before for example network subsystem is fully initialised. Missing DNS was something I saw few times.

Simple solution it to add some delay, e.g.:

[Service]
ExecStartPre=/bin/sleep 30

If you only need this mount after user ivan logs in you could also make this service only run after login. Google "how to" for your OS as it differs in details.

1 Like

Same exact issue when sleeping for 30, log is exactly the same so won't be repasting it. I tried making sure it's not network drivers so that's why I added

After=network-online.target
Wants=network-online.target

But it still doesn't work.

I really don't care if it starts with user login. I'll probably delete those lines as I realistically need it to be loaded on log in menu that's why I have WantedBy=multi-user.target at the end

Thanks for the tips though, I've going at it for the last 3h+ tbh. I already have it working by placing it in /etc/profile.d but it irks me it's not the most "ideal" solution

Must be something simple missing or wrong. It works without any issue for myself on multiple computers.

Does it work when you are logged in? When you start this service later?

1 Like

I think I got it.

remove this from your mount command. Restart your computer (or kill any remaining rclone mounts manually) and all should work.

systemd demonizes it anyway so "double" daemon can lead to weird results.

1 Like

Even when I manually start it with systemctl start GDrive.service it still doesn't work. So I really doubt it's because it is starting before another critical service. The shell script works perfectly fine, even when I restart my pc and it autostarts from /etc/profile.d so I really have no clue what the issue is, as systemctl is correctly picking up the location and command of the script

That was it! Can't believe I've been beating my head against the wall when --daemon was the issue.

Also removed the sleep 30 and the logging from the script and it still works perfectly!
Thank you!

1 Like

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