# Waiting until an rclone mount is ready

**URL:** <https://forum.rclone.org/t/waiting-until-an-rclone-mount-is-ready/20084>\
**Category:** Help and Support\
**Created:** [October 29, 2020, 10:15am UTC](https://forum.rclone.org/t/waiting-until-an-rclone-mount-is-ready/20084 "2020-10-29T10:15:09Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Foster](https://forum.rclone.org/user_avatar/forum.rclone.org/chris_foster/32/7659_2.png) [@Chris\_Foster](https://forum.rclone.org/u/Chris_Foster)\
**Post date:** [October 29, 2020, 10:15am UTC](https://forum.rclone.org/t/waiting-until-an-rclone-mount-is-ready/20084/1 "2020-10-29T10:15:09Z")

</div>

Hi! I'm trying to use `rclone mount` as part of a larger system, where I'd first like to mount a remote, then start using it immediately from some other code.

The problem I'm facing is that after starting `rclone` in the background, the mount point takes some unknown amount of time to initialize. In the meantime I need to wait before running any code which depends on the mount being available.

The problem is knowing how long to wait; ideally we'd wait for an event from `rclone` and there would be an OS-independent way to detect when the mount point is ready. So far I've found that the systemd integration seems to be approximately the right thing; if I supply a `NOTIFY_SOCKET` and read from it with netcat:

```bash
nc -lk -U -u /some/socket/path

```

followed by running `rclone` separately:

```bash
export NOTIFY_SOCKET=/some/socket/path
rclone mount remote_name: mountpoint --read-only --vfs-cache-mode=full

```

after doing this we'll see `READY=1` come down the socket.

I'm not sure this will work on windows though, as the use of "unixgram" in the following doesn't look promising. However, it's necessary to use "unixgram" to get a UDP socket opened for systemd compatibility, as in the C system call `socket(AF_UNIX, SOCK_DGRAM, 0)`.

- [https://github.com/iguanesolutions/go-systemd/blob/9a6c6e17e01d793ec1c3cf8240edec39b71bc7e8/notify/notify\_init.go#L14](https://github.com/iguanesolutions/go-systemd/blob/9a6c6e17e01d793ec1c3cf8240edec39b71bc7e8/notify/notify_init.go#L14)
- [https://github.com/golang/go/blob/master/src/net/unixsock.go#L18](https://github.com/golang/go/blob/master/src/net/unixsock.go#L18).

It appears that connectionless UDP unix domain sockets as in the `nc` command above are a somewhat unusual thing, possibly not accessible via `libuv` which I'm using using for IO.

So what to do? In principle it seems possible to generalize the systemd stuff in a small way such that it would work on windows. Alternatively I was hoping that `rclone rc` might help out in some way, but I wasn't sure exactly how to do that. Perhaps I'll try `rclone rc mount/mount` next and hope that it blocks until the mount is ready.

### Environment

In this case I've been testing `remote_name` with a google drive remote, but I doubt the particular remote config makes much difference.

`rclone` version information:

```nohighlight
rclone v1.53.1
- os/arch: linux/amd64
- go version: go1.15

```

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [October 29, 2020, 11:07am UTC](https://forum.rclone.org/t/waiting-until-an-rclone-mount-is-ready/20084/2 "2020-10-29T11:07:27Z")

</div>

> [@Chris\_Foster](#):
>
> I'm not sure this will work on windows though, as the use of "unixgram" in the following doesn't look promising.

No it won't work on windows as the support isn't compiled in on Windows.

> [@Chris\_Foster](#):
>
> Alternatively I was hoping that `rclone rc` might help out in some way, but I wasn't sure exactly how to do that. Perhaps I'll try `rclone rc mount/mount` next and hope that it blocks until the mount is ready.

The rc call `mount/mount` will return at pretty much the same time that the notification would have been sent so I think that will work 🙂

You could use something old school like listing the mount and waiting for a file to show up. On Windows the mount point doesn't exist until after the mount so waiting until the mountpoint shows up on Windows will work.

---

<div class="post-metadata">

**Author:** ![Chris\_Foster](https://forum.rclone.org/user_avatar/forum.rclone.org/chris_foster/32/7659_2.png) [@Chris\_Foster](https://forum.rclone.org/u/Chris_Foster)\
**Post date:** [November 3, 2020, 6:56am UTC](https://forum.rclone.org/t/waiting-until-an-rclone-mount-is-ready/20084/3 "2020-11-03T06:56:39Z")

</div>

> [@ncw](#):
>
> On Windows the mount point doesn't exist until after the mount so waiting until the mountpoint shows up on Windows will work.

Thanks, out of the available options, this does seem attractively simple. For now, I've found a hack which achieves something similar on linux - simply call `stat()` on the mount point and its parent directory and compare the device numbers. If they're equal, the mount is not yet initialized. Other than needing to poll it seems like a reasonable solution.

(Further research indicates that comparing device numbers seems to be a standard trick. For example python's os.path.ismount does it this way.)

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [November 5, 2020, 9:45am UTC](https://forum.rclone.org/t/waiting-until-an-rclone-mount-is-ready/20084/4 "2020-11-05T09:45:41Z")

</div>

> [@Chris\_Foster](#):
>
> For now, I've found a hack which achieves something similar on linux - simply call `stat()` on the mount point and its parent directory and compare the device numbers. If they're equal, the mount is not yet initialized.

That is a good trick 🙂

---

<div class="post-metadata">

**Author:** ![1xe](https://forum.rclone.org/letter_avatar_proxy/v4/letter/1/8dc957/32.png) [@1xe](https://forum.rclone.org/u/1xe)\
**Post date:** [November 5, 2020, 9:50pm UTC](https://forum.rclone.org/t/waiting-until-an-rclone-mount-is-ready/20084/5 "2020-11-05T21:50:58Z")

</div>

I have

```
rclone mount "$src" "$dst" $flags
# wait for the mount to be ready
until findmnt --mountpoint "$dst" --mtab >/dev/null; do :; done

```

at the end of my `rclone mount` wrapper script. It's easy to understand and works very well. `findmnt` is part of the `util-linux` package so if you're on Linux, you probably have it installed already.

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [November 6, 2020, 4:05pm UTC](https://forum.rclone.org/t/waiting-until-an-rclone-mount-is-ready/20084/6 "2020-11-06T16:05:51Z")

</div>

> [@1xe](#):
>
> `findmnt` is part of the `util-linux` package so if you're on Linux, you probably have it installed already.

I didn't know about findmnt - nice one 🙂

---

<div class="post-metadata">

**Author:** ![Chris\_Foster](https://forum.rclone.org/user_avatar/forum.rclone.org/chris_foster/32/7659_2.png) [@Chris\_Foster](https://forum.rclone.org/u/Chris_Foster)\
**Post date:** [November 9, 2020, 11:48am UTC](https://forum.rclone.org/t/waiting-until-an-rclone-mount-is-ready/20084/7 "2020-11-09T11:48:48Z")

</div>

> [@1xe](#):
>
> `findmnt` is part of the `util-linux` package so if you're on Linux, you probably have it installed already.

Yes that's a great option and I'd use it if I was in a linux shell scripting environment. My problem was that I'm trying to use `rclone` as a data backend for a cross-platform Julia package. So I can't easily rely on external tools like `findmnt` and I'd rather avoid starting external processes in any case. So the `stat()` trick fits my particular constraints quite well.

(By the way, I made a build of `Rclone` available via the Julia package manager [GitHub - JuliaBinaryWrappers/Rclone\_jll.jl](https://github.com/JuliaBinaryWrappers/Rclone_jll.jl))

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [November 11, 2020, 5:40pm UTC](https://forum.rclone.org/t/waiting-until-an-rclone-mount-is-ready/20084/8 "2020-11-11T17:40:37Z")

</div>

> [@Chris\_Foster](#):
>
> (By the way, I made a build of `Rclone` available via the Julia package manager [GitHub - JuliaBinaryWrappers/Rclone\_jll.jl](https://github.com/JuliaBinaryWrappers/Rclone_jll.jl))

Nice! I don't quite know what that means but it looks cool 🙂

Do you want to put a link to it on [the rclone wiki](https://github.com/ncw/rclone/wiki)? Maybe on [Third Party Installers · rclone/rclone Wiki · GitHub](https://github.com/rclone/rclone/wiki/Third-Party-Installers) ?

---

<div class="post-metadata">

**Author:** ![Chris\_Foster](https://forum.rclone.org/user_avatar/forum.rclone.org/chris_foster/32/7659_2.png) [@Chris\_Foster](https://forum.rclone.org/u/Chris_Foster)\
**Post date:** [November 12, 2020, 11:21am UTC](https://forum.rclone.org/t/waiting-until-an-rclone-mount-is-ready/20084/9 "2020-11-12T11:21:13Z")

</div>

> [@ncw](#):
>
> I don't quite know what that means but it looks cool

Haha 🙂 The Julia language comes with a package manager which knows how to distribute Julia packages, but also a cross platform cross compilation system to build and distribute a wide variety of precompiled binaries. (Not difficult for `Go` of course but a trickier prospect for C++ and Fortran which many important numerical libraries relevant to Julia users tend to be written in.)

Anyway, I made a build recipe, so installing rclone in a Julia REPL on any platform is as simple as `Pkg.add("RClone_jll")`.

> [@ncw](#):
>
> Maybe on [Third Party Installers · rclone/rclone Wiki · GitHub](https://github.com/rclone/rclone/wiki/Third-Party-Installers) ?

Done!

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [November 12, 2020, 11:38am UTC](https://forum.rclone.org/t/waiting-until-an-rclone-mount-is-ready/20084/10 "2020-11-12T11:38:18Z")

</div>

> [@Chris\_Foster](#):
>
> The Julia language comes with a package manager which knows how to distribute Julia packages, but also a cross platform cross compilation system to build and distribute a wide variety of precompiled binaries. (Not difficult for `Go` of course but a trickier prospect for C++ and Fortran which many important numerical libraries relevant to Julia users tend to be written in.)

That is very clever. I thought Julia was just a language, I didn't realise it has an almost OS level package manager as well.

> [@Chris\_Foster](#):
>
> Anyway, I made a build recipe, so installing rclone in a Julia REPL on any platform is as simple as `Pkg.add("RClone_jll")`.

🙂

> [@Chris\_Foster](#):
>
> Done!

Great.

I'd like to tweet about this... If you want to compose a tweet then you can @ me and I'll retweet, or if you aren't a Twitter user I'll make something up 🙂

---

<div class="post-metadata">

**Author:** ![Chris\_Foster](https://forum.rclone.org/user_avatar/forum.rclone.org/chris_foster/32/7659_2.png) [@Chris\_Foster](https://forum.rclone.org/u/Chris_Foster)\
**Post date:** [December 7, 2020, 7:17am UTC](https://forum.rclone.org/t/waiting-until-an-rclone-mount-is-ready/20084/11 "2020-12-07T07:17:27Z")

</div>

> [@ncw](#):
>
> I'd like to tweet about this

Sorry I missed this. I don't have a twitter account, but go for it!

> it has an almost OS level package manager as well.

Yes, thinking about it like `apt/macports/chocolaty` etc etc etc is a fairly good model. It comes with a strong semver-based dependency resolver, so it's quite reliable for producing working project configurations even when packages are evolving. `Pkg.jl` is one of the good parts 🙂

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [December 7, 2020, 10:31am UTC](https://forum.rclone.org/t/waiting-until-an-rclone-mount-is-ready/20084/12 "2020-12-07T10:31:50Z")

</div>

Tweet sent: [https://twitter.com/njcw/status/1335894422203084800](https://twitter.com/njcw/status/1335894422203084800) 🙂

I have Julia on the list of language to look at when I have time.

Thank you!

---

<div class="post-metadata">

**Author:** ![system](https://forum.rclone.org/uploads/default/original/2X/3/39ad3235f6ffec76ccd0c81616bd55697b4c300d.png) [@system](https://forum.rclone.org/u/system)\
**Post date:** [February 6, 2021, 6:31am UTC](https://forum.rclone.org/t/waiting-until-an-rclone-mount-is-ready/20084/13 "2021-02-06T06:31:53Z")

</div>

Closed on February 6, 2021, 6:31am UTC

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