Auto mount remote in BG (Mac)

Just want to know how can i run a .command file in background during macOS log in without terminal being opened. i have a rclone_mount.command file which would run the mount command by opening terminal and not in bg. Is what im trying to achieve possible? Used automator to run shell script but rclone command not found error.

My mount command:

rclone mount --daemon --allow-other --vfs-read-chunk-size 32M --vfs-cache-max-size 10G --poll-interval 15m --vfs-cache-mode full --tpslimit 10 --tpslimit-burst 0 --cache-dir /Users/ishaanrathod/rclone/cache --disable About GDrive: /Users/ishaanrathod/rclone/GDrive

Yeap it is perfectly achievable using launchd framework.

Here some basic tutorial:

and here some rclone mount example (you can google for more)

while executing "sudo launchctl load -w /Library/LaunchDaemons/com.gdrive.plist", i get the error:
Load failed: 5: Input/output error
Try running launchctl bootstrap as root for richer errors.

capture errors from launchd - look at " Redirecting input and output: StandardInPath StandardOutPath StandardErrorPath" in manual I sent.

This is not rclone problem though but rather how to use launchd...

I recommend to use program:

https://www.soma-zone.com/LaunchControl/

or otherwise you have to learn command line.

If it is all too complicated then try to use Shortcuts - they support shell commands too.

alright i tried to fix it through launch control, complicated but i fixed it, but still gives the SAME error and launch control aint giving me any more suggestions, will try shortcuts

For rclone mount I would also use user daemon instead of system daemon. So job plist would be in ~/Library/LaunchDaemons instead of /Library/LaunchDaemons. This way you run it as your user and not root.

I have not working example at the moment with me but hopefully now you have enough info to experiment and make it work:) I did in the past many times - it requires a bit of reading but as soon as you grasp overall concept it is easy.

If you are familiar with Linux then launchd is equivalent of systemd

For shortcuts I see that somebody provides some examples:

https://www.reddit.com/r/shortcuts/comments/17hfye8/shortcuts_for_serving_one_drive_google_drive_and/

not exactly rclone mount but should give you idea how to do it. The concept will be exactly the same.

tried this and ran without sudo, basically "launchctl load -w ~/Library/LaunchAgents/com.gdrive.plist", works.
but while running "launchctl start -w ~/Library/LaunchAgents/com.gdrive.plist", error:

Job returned error code 1
Unfortunately there is no way of knowing what this code
means, as a programmer can choose arbitrary exit codes
if he wants. Maybe the user manual of the program
contains a list of all exit codes with an explanation.
Otherwise ask the author about the meaning of the error
code.
If you are lucky the program uses standard exit codes. In
this case the description could be:
errno.h: Operation not permitted. An attempt was made
to perform an operation limited to processes with
appropriate privileges or to the owner of a file or other
resources.

capture rclone mount debul log - it will tell you what is going on

--log-file /path/to/rclone.log -vv

And for shortcuts maybe somebody on this forum has it working and can share with you - this would be handy for others too:)

Or when you make it then you can share as well.

got shortcuts working but i dont know what it is exactly. Like the "localhost" is mounted instead of "fuse-t" and i do not know if it follows these arguments:
rclone mount --daemon --allow-other --vfs-read-chunk-size 32M --vfs-cache-max-size 10G --poll-interval 15m --vfs-cache-mode full --tpslimit 10 --tpslimit-burst 0 --cache-dir /Users/ishaanrathod/rclone/cache --disable About GDrive: /Users/ishaanrathod/rclone/GDrive

because i didnt insert it anywhere nor does it ask for it

These are only examples. You have to adapt them to your needs.

It looks like they run rclone serve webdav and mount locally so not exactly rclone mount

The reason I sent them is to show you how to run rclone commands in shortcuts. Also it was first hit on google:) You can try more research - maybe there are better examples.

Here you are the simplest possible shortcut which runs rclone mount:

It is very basic and easily can be made better - but it is good start.

And then:

https://www.reddit.com/r/shortcuts/comments/qhqkfn/is_there_a_way_to_run_a_particular_shortcut_in/

haha yes was just going to comment this way. Just paste your mount command in a shell script in shortcuts, add it to dock, open at login, remove from dock (saves as application in launchpad) and DONE, works like a charm. Thank you so much!

1 Like

Add --daemon to your rclone mount command - this way shortcut mounts the drive and terminates. Otherwise is always ruunning

This is a very valuable information, i did not exactly know the reason of using daemon but used it anyways, now i understand why. Thank you :slight_smile:

okay we have a problem, when the shortcut is run automatically at login when i restart my computer, shortcut gives error:

2024/02/08 17:50:31 Failed to create file system for "GDrive:":couldn't find root directory ID:Get "https://www.googleapis.com/drive/v3/files/rootalt=json&fields=id&prettyPrint=false&supportsAllDrives=true":dial tcp: lookup www.googleapis.com: no such host

when i try to run it again, it works, do you understand whats goin on?

Most likely network is not ready at very early login sequence. Maybe DNS service no ready yet etc.

Proper solution would be to add network detection logic to mounting sctipt and e.g. wait until network is working or abandoning if not in specified time. But I have no time now for any complex solutions:)

Dirty and easy is just to add sleep 30 before your mount command. I think it does not require explanation.

sleep 30; rclone mount....

Time is in seconds - so you can experiment what works for you.

Let me know if it works - I will add it to the guide:) Or add yourself as a comment.

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