# Wait for network connection before uploading status report

**URL:** <https://hub.mender.io/t/wait-for-network-connection-before-uploading-status-report/2497>\
**Category:** General Discussions\
**Created:** [September 25, 2020, 6:03pm UTC](https://hub.mender.io/t/wait-for-network-connection-before-uploading-status-report/2497 "2020-09-25T18:03:54Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![amorgan](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/amorgan/32/778_2.png) [@amorgan](https://hub.mender.io/u/amorgan)\
**Post date:** [September 25, 2020, 6:03pm UTC](https://hub.mender.io/t/wait-for-network-connection-before-uploading-status-report/2497/1 "2020-09-25T18:03:54Z")

</div>

Hi there,

I’m looking for a way for the mender client on a device to wait for a network connection (or timeout) before trying to update the status report. The situation that prompted this came from forcing a shut down of the device while it was downloading an update. This generated the following logs:

```auto
2020-09-25 16:33:50 +0000 UTC info: Running Mender client version: 2.3.0
2020-09-25 16:33:51 +0000 UTC info: State transition: update-fetch [Download_Enter] -> update-store [Download_Enter]
2020-09-25 16:33:51 +0000 UTC info: No public key was provided for authenticating the artifact
2020-09-25 16:33:51 +0000 UTC info: Update Module path "/usr/share/mender/modules/v3" could not be opened (open /usr/share/mender/modules/v3: no such file or directory). Update modules will not be available
2020-09-25 16:33:51 +0000 UTC info: Opening device "/dev/mmcblk0p2" for writing
2020-09-25 16:33:51 +0000 UTC info: Native sector size of block device /dev/mmcblk0p2 is 512 bytes. Mender will write in chunks of 1048576 bytes
2020-09-25 16:35:46 +0000 UTC info: Running Mender client version: 2.3.0
2020-09-25 16:35:46 +0000 UTC error: Mender shut down in state: update-store
2020-09-25 16:35:46 +0000 UTC info: Update Module path "/usr/share/mender/modules/v3" could not be opened (open /usr/share/mender/modules/v3: no such file or directory). Update modules will not be available
2020-09-25 16:35:46 +0000 UTC info: State transition: init [none] -> cleanup [Error]
2020-09-25 16:35:46 +0000 UTC info: State transition: cleanup [Error] -> update-status-report [none]
2020-09-25 16:35:46 +0000 UTC error: Failed to report status: Put "https://hosted.mender.io/api/devices/v1/deployments/device/deployments/: dial tcp: lookup hosted.mender.io on [::1]:53: server misbehaving
2020-09-25 16:35:46 +0000 UTC error: error reporting update status: reporting status failed: Put "https://hosted.mender.io/api/devices/v1/deployments/device/deployments/": dial tcp: lookup hosted.mender.io on [::1]:53: server misbehaving
2020-09-25 16:35:46 +0000 UTC error: Failed to send status to server: transient error: reporting status failed: Put "https://hosted.mender.io/api/devices/v1/deployments/device/deployments/": dial tcp: lookup hosted.mender.io on [::1]:53: server misbehaving
2020-09-25 16:35:46 +0000 UTC info: State transition: update-status-report [none] -> update-retry-report [none]
2020-09-25 16:39:02 +0000 UTC info: State transition: update-retry-report [none] -> update-status-report [none]

```

I’ve looked for a state script option, but did not find one that runs in this situation. Any help or information is appreciated.  
Thanks!

---

<div class="post-metadata">

**Author:** ![drewmoseley](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/drewmoseley/32/47_2.png) [@drewmoseley](https://hub.mender.io/u/drewmoseley)\
**Post date:** [September 28, 2020, 3:45pm UTC](https://hub.mender.io/t/wait-for-network-connection-before-uploading-status-report/2497/2 "2020-09-28T15:45:53Z")

</div>

There is a Yocto example here: [https://github.com/mendersoftware/meta-mender/tree/master/meta-mender-core/recipes-mender/mender-wait-for-timesync](https://github.com/mendersoftware/meta-mender/tree/master/meta-mender-core/recipes-mender/mender-wait-for-timesync)

Drew

---

<div class="post-metadata">

**Author:** ![drewmoseley](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/drewmoseley/32/47_2.png) [@drewmoseley](https://hub.mender.io/u/drewmoseley)\
**Post date:** [September 28, 2020, 3:46pm UTC](https://hub.mender.io/t/wait-for-network-connection-before-uploading-status-report/2497/3 "2020-09-28T15:46:59Z")

</div>

Sorry, I should clarify, that script waits for time sync to complete but you could simply check if you can ping a specific IP address or something instead.

Drew

---

<div class="post-metadata">

**Author:** ![amorgan](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/amorgan/32/778_2.png) [@amorgan](https://hub.mender.io/u/amorgan)\
**Post date:** [September 28, 2020, 5:21pm UTC](https://hub.mender.io/t/wait-for-network-connection-before-uploading-status-report/2497/4 "2020-09-28T17:21:40Z")

</div>

Hi Drew,

Thanks for the reply! I have a script to check network connectivity, but I’m more looking for a type of state script that runs in this situation. For example, I’ve tried using it as the `Download_Error` state script to no avail. To my understanding, the example you linked would not run in this situation since the script was set as an `ArtifactCommit_Enter` script. I think what I would ideally be looking for is a state script that runs during one of these transitions from the above logs:

```auto
2020-09-25 16:35:46 +0000 UTC info: State transition: init [none] -> cleanup [Error]
2020-09-25 16:35:46 +0000 UTC info: State transition: cleanup [Error] -> update-status-report [none]

```

Does something like that exist? Sorry for any confusion. Thanks!

---

<div class="post-metadata">

**Author:** ![drewmoseley](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/drewmoseley/32/47_2.png) [@drewmoseley](https://hub.mender.io/u/drewmoseley)\
**Post date:** [September 28, 2020, 6:56pm UTC](https://hub.mender.io/t/wait-for-network-connection-before-uploading-status-report/2497/5 "2020-09-28T18:56:13Z")

</div>

Hi @amorgan you probably want a Sync\_Enter state script as that runs prior to any communication with the server.

---

<div class="post-metadata">

**Author:** ![amorgan](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/amorgan/32/778_2.png) [@amorgan](https://hub.mender.io/u/amorgan)\
**Post date:** [September 28, 2020, 8:09pm UTC](https://hub.mender.io/t/wait-for-network-connection-before-uploading-status-report/2497/6 "2020-09-28T20:09:45Z")

</div>

I see that `Sync_Enter` is a common place for network checks [here](https://docs.mender.io/2.3/artifacts/state-scripts#enable-network-connectivity), but I don’t see anything there that suggests it will run when a download has already started. Also wouldn’t the deployment log say something about being in a `Sync` state if it were happening?

---

<div class="post-metadata">

**Author:** ![drewmoseley](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/drewmoseley/32/47_2.png) [@drewmoseley](https://hub.mender.io/u/drewmoseley)\
**Post date:** [September 29, 2020, 2:05pm UTC](https://hub.mender.io/t/wait-for-network-connection-before-uploading-status-report/2497/7 "2020-09-29T14:05:01Z")

</div>

No we don’t explicitly log that.

I don’t understand what you are trying to accomplish. It seems to me that you had a deployment in progress but then rebooted the device before it completed. On the next boot, the Mender client will detect this and using the standard Sync state connect with the server and upload the report. The only way to delay that is to use the Sync\_Enter state script.

Drew

---

<div class="post-metadata">

**Author:** ![amorgan](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/amorgan/32/778_2.png) [@amorgan](https://hub.mender.io/u/amorgan)\
**Post date:** [September 29, 2020, 4:49pm UTC](https://hub.mender.io/t/wait-for-network-connection-before-uploading-status-report/2497/8 "2020-09-29T16:49:26Z")

</div>

I think you get what I’m trying to accomplish based on what you say. I want to delay the attempt to upload the report because it seems like mender is trying to upload the report before our devices networking is on and working.

For what you suggest, I’ve tried recreating the same situation with a Sync\_Enter state script logging to an external file when it is run to check when is running. The script works as expected for normal check-ins, but it does not seem to be run after the reboot. Is there a better way to tell if it’s being run? Or do you have any other ideas to try? Thanks!

---

<div class="post-metadata">

**Author:** ![drewmoseley](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/drewmoseley/32/47_2.png) [@drewmoseley](https://hub.mender.io/u/drewmoseley)\
**Post date:** [September 29, 2020, 6:31pm UTC](https://hub.mender.io/t/wait-for-network-connection-before-uploading-status-report/2497/9 "2020-09-29T18:31:10Z")

</div>

I would have it log to a file in /tmp so you can see whether it is doing anything or not.

---

<div class="post-metadata">

**Author:** ![amorgan](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/amorgan/32/778_2.png) [@amorgan](https://hub.mender.io/u/amorgan)\
**Post date:** [September 29, 2020, 7:08pm UTC](https://hub.mender.io/t/wait-for-network-connection-before-uploading-status-report/2497/10 "2020-09-29T19:08:15Z")

</div>

Ok I tried this a couple times. After starting the update, I emptied the file before forcing the reboot. The file remained empty the entire time while mender was trying to update the status. I feel pretty confident the Sync\_Enter script is not running in this situation. Any other ideas? Thanks!

---

<div class="post-metadata">

**Author:** ![drewmoseley](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/drewmoseley/32/47_2.png) [@drewmoseley](https://hub.mender.io/u/drewmoseley)\
**Post date:** [September 30, 2020, 4:49pm UTC](https://hub.mender.io/t/wait-for-network-connection-before-uploading-status-report/2497/11 "2020-09-30T16:49:52Z")

</div>

Can you provide the output from the following?

```
$ sudo ls -l /etc/mender/scripts/
$ sudo journalctl -u mender-client
```

---

<div class="post-metadata">

**Author:** ![amorgan](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/amorgan/32/778_2.png) [@amorgan](https://hub.mender.io/u/amorgan)\
**Post date:** [October 1, 2020, 4:09pm UTC](https://hub.mender.io/t/wait-for-network-connection-before-uploading-status-report/2497/12 "2020-10-01T16:09:19Z")

</div>

Sure.  
scripts:

```auto
~# ls -l /etc/mender/scripts/
-rwxr-xr-x 1 root root 2000 Mar 9 2018 Download_Enter_10
-rwxr-xr-x 1 root root 321 Mar 9 2018 Idle_Enter_10
-rwxr-xr-x 1 root root 650 Sep 29 18:53 Sync_Enter_09_connection_check
-rwxr-xr-x 1 root root 667 Mar 9 2018 Sync_Enter_10
-rw-r--r-- 1 root root 1 Mar 9 2018 version

```

journal:

```auto
Oct 01 15:59:05 luci-som-imx8 systemd[1]: Started Mender OTA update service.
Oct 01 15:59:06 luci-som-imx8 mender[634]: time="2020-10-01T15:59:06Z" level=info msg="Loaded configuration file: /var/lib/mender/mender.conf"
Oct 01 15:59:06 luci-som-imx8 mender[634]: time="2020-10-01T15:59:06Z" level=info msg="Loaded configuration file: /etc/mender/mender.conf"
Oct 01 15:59:06 luci-som-imx8 mender[634]: time="2020-10-01T15:59:06Z" level=info msg="Mender running on partition: /dev/mmcblk0p2"
Oct 01 15:59:06 luci-som-imx8 mender[634]: time="2020-10-01T15:59:06Z" level=info msg="State transition: init [none] -> init [none]"
Oct 01 15:59:06 luci-som-imx8 mender[634]: time="2020-10-01T15:59:06Z" level=info msg="State transition: init [none] -> idle [Idle]"
Oct 01 15:59:06 luci-som-imx8 mender[634]: time="2020-10-01T15:59:06Z" level=info msg="authorization data present and valid"
Oct 01 15:59:06 luci-som-imx8 mender[634]: time="2020-10-01T15:59:06Z" level=info msg="State transition: idle [Idle] -> check-wait [Idle]"
Oct 01 15:59:06 luci-som-imx8 mender[634]: time="2020-10-01T15:59:06Z" level=info msg="State transition: check-wait [Idle] -> inventory-update [Sync]"
Oct 01 15:59:06 luci-som-imx8 mender[634]: time="2020-10-01T15:59:06Z" level=info msg="Collected output (stderr) while running script /etc/mender/scripts/Sync_Enter_09_connection_check\nwge>
Oct 01 15:59:06 luci-som-imx8 mender[634]: time="2020-10-01T15:59:06Z" level=info msg="statescript: Sync_Enter_09_connection_check requested a retry"
Oct 01 15:59:40 luci-som-imx8 mender[634]: time="2020-10-01T15:59:40Z" level=info msg="State transition: inventory-update [Sync] -> check-wait [Idle]"
Oct 01 15:59:40 luci-som-imx8 mender[634]: time="2020-10-01T15:59:40Z" level=info msg="State transition: check-wait [Idle] -> update-check [Sync]"
Oct 01 16:01:43 luci-som-imx8 mender[634]: time="2020-10-01T16:01:43Z" level=info msg="Correct request for getting image from: https://s3.amazonaws.com/hosted-mender-artifacts/5b5219ba3bc50>
Oct 01 16:01:43 luci-som-imx8 mender[634]: time="2020-10-01T16:01:43Z" level=info msg="State transition: update-check [Sync] -> update-fetch [Download_Enter]"
Oct 01 16:01:47 luci-som-imx8 mender[634]: time="2020-10-01T16:01:47Z" level=info msg="Running Mender client version: 2.3.0"
Oct 01 16:01:49 luci-som-imx8 mender[634]: time="2020-10-01T16:01:49Z" level=info msg="State transition: update-fetch [Download_Enter] -> update-store [Download_Enter]"
Oct 01 16:01:50 luci-som-imx8 mender[634]: time="2020-10-01T16:01:50Z" level=info msg="No public key was provided for authenticating the artifact"
Oct 01 16:01:50 luci-som-imx8 mender[634]: time="2020-10-01T16:01:50Z" level=info msg="Update Module path \"/usr/share/mender/modules/v3\" could not be opened (open /usr/share/mender/module>
Oct 01 16:01:50 luci-som-imx8 mender[634]: time="2020-10-01T16:01:50Z" level=info msg="Opening device \"/dev/mmcblk0p3\" for writing"
Oct 01 16:01:50 luci-som-imx8 mender[634]: time="2020-10-01T16:01:50Z" level=info msg="Native sector size of block device /dev/mmcblk0p3 is 512 bytes. Mender will write in chunks of 1048576>
-- Reboot --
Oct 01 16:02:15 luci-som-imx8 systemd[1]: Started Mender OTA update service.
Oct 01 16:02:16 luci-som-imx8 mender[656]: time="2020-10-01T16:02:16Z" level=info msg="Loaded configuration file: /var/lib/mender/mender.conf"
Oct 01 16:02:16 luci-som-imx8 mender[656]: time="2020-10-01T16:02:16Z" level=info msg="Loaded configuration file: /etc/mender/mender.conf"
Oct 01 16:02:16 luci-som-imx8 mender[656]: time="2020-10-01T16:02:16Z" level=info msg="Mender running on partition: /dev/mmcblk0p2"
Oct 01 16:02:16 luci-som-imx8 mender[656]: time="2020-10-01T16:02:16Z" level=info msg="State transition: init [none] -> init [none]"
Oct 01 16:02:16 luci-som-imx8 mender[656]: time="2020-10-01T16:02:16Z" level=info msg="Handling loaded state: update-store"
Oct 01 16:02:16 luci-som-imx8 mender[656]: time="2020-10-01T16:02:16Z" level=info msg="Running Mender client version: 2.3.0"
Oct 01 16:02:16 luci-som-imx8 mender[656]: time="2020-10-01T16:02:16Z" level=error msg="Mender shut down in state: update-store"
Oct 01 16:02:16 luci-som-imx8 mender[656]: time="2020-10-01T16:02:16Z" level=info msg="Update Module path \"/usr/share/mender/modules/v3\" could not be opened (open /usr/share/mender/module>
Oct 01 16:02:16 luci-som-imx8 mender[656]: time="2020-10-01T16:02:16Z" level=info msg="State transition: init [none] -> cleanup [Error]"
Oct 01 16:02:16 luci-som-imx8 mender[656]: time="2020-10-01T16:02:16Z" level=info msg="State transition: cleanup [Error] -> update-status-report [none]"
Oct 01 16:02:16 luci-som-imx8 mender[656]: time="2020-10-01T16:02:16Z" level=error msg="Failed to report status: Put \"https://hosted.mender.io/api/devices/v1/deployments/device/deployments>
Oct 01 16:02:16 luci-som-imx8 mender[656]: time="2020-10-01T16:02:16Z" level=error msg="error reporting update status: reporting status failed: Put \"https://hosted.mender.io/api/devices/v1>
Oct 01 16:02:16 luci-som-imx8 mender[656]: time="2020-10-01T16:02:16Z" level=error msg="Failed to send status to server: transient error: reporting status failed: Put \"https://hosted.mende>
Oct 01 16:02:16 luci-som-imx8 mender[656]: time="2020-10-01T16:02:16Z" level=info msg="State transition: update-status-report [none] -> update-retry-report [none]"

```

---

<div class="post-metadata">

**Author:** ![drewmoseley](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/drewmoseley/32/47_2.png) [@drewmoseley](https://hub.mender.io/u/drewmoseley)\
**Post date:** [October 1, 2020, 5:56pm UTC](https://hub.mender.io/t/wait-for-network-connection-before-uploading-status-report/2497/13 "2020-10-01T17:56:07Z")

</div>

Hmm. I’m not sure what to suggest next. @kacf do you have any suggestions?  
Drew
