# Scripting: How to tell when \`ipfs daemon\` is ready?

**URL:** <https://discuss.ipfs.tech/t/scripting-how-to-tell-when-ipfs-daemon-is-ready/19312>\
**Category:** Help\
**Created:** [May 12, 2025, 1:05pm UTC](https://discuss.ipfs.tech/t/scripting-how-to-tell-when-ipfs-daemon-is-ready/19312 "2025-05-12T13:05:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![meermanr](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/meermanr/32/7280_2.png) [@meermanr](https://discuss.ipfs.tech/u/meermanr)\
**Post date:** [May 12, 2025, 1:05pm UTC](https://discuss.ipfs.tech/t/scripting-how-to-tell-when-ipfs-daemon-is-ready/19312/1 "2025-05-12T13:05:48Z")

</div>

I’m using a private IPFS swarm to push out OS updates to some lab equipment. IPFS is not usually running, so my update script has to launch `ipfs daemon` and then `ipfs pin add ...` the data I want to get.

Since `ipfs daemon` runs in the foreground, I have a challenge finding out when IPFS is ready to accept commands. I’m essentially doing this:

```auto
#!/bin/bash
ipfs daemon --enable-gc & # backgrounded
ipfs pin add $CID

```

Since the daemon takes some time to start-up, the `ipfs pin` command fails. Sure, I could add a sleep, but that’s a hack.

Is there a way to make `ipfs pin` block until it succeeds, or some other means to wait for the daemon to be ready?

I tried the following, but it doesn’t work unless I remove the redirects:

```auto
#!/bin/bash
ipfs daemon --enable-gc & # backgrounded

until ipfs stats bitswap &>/dev/null
do
  sleep 1
done

ipfs pin add $CID

```

If I remove the `&>/dev/null` redirect it seems to work, but of course it outputs some lines to the screen. Especially when the daemon is starting up and the lock is held.

---

<div class="post-metadata">

**Author:** ![hector](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/hector/32/178_2.png) [@hector](https://discuss.ipfs.tech/u/hector)\
**Post date:** [May 12, 2025, 2:06pm UTC](https://discuss.ipfs.tech/t/scripting-how-to-tell-when-ipfs-daemon-is-ready/19312/2 "2025-05-12T14:06:32Z")

</div>

Does your system use systemd? If yes, Kubo should notify systemd when it is ready and you can use that to launch your own code.

Otherwise your approach is fine, and I am not sure why it doesn’t work, but you can certainly refactor the loop into something like:

```auto
(pseudocode)
until $status == 0
do
  ipfs version &> /dev/null
  status=$?
  sleep 1
done

```

and see if that helps.

Or you can test for the `.ipfs/api` file to appear in place and hold requests until then.

---

<div class="post-metadata">

**Author:** ![meermanr](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/meermanr/32/7280_2.png) [@meermanr](https://discuss.ipfs.tech/u/meermanr)\
**Post date:** [May 12, 2025, 2:49pm UTC](https://discuss.ipfs.tech/t/scripting-how-to-tell-when-ipfs-daemon-is-ready/19312/3 "2025-05-12T14:49:00Z")

</div>

Thanks, using `ipfs version` as the sentinal is neat, and I got it working (some silly bash stuff got in my way).

I didn’t know about `.ipfs/api`, that’s handy thanks.
