# How to delay an update?

**URL:** <https://hub.mender.io/t/how-to-delay-an-update/4150>\
**Category:** General Discussions\
**Tags:** yocto\
**Created:** [October 5, 2021, 12:43am UTC](https://hub.mender.io/t/how-to-delay-an-update/4150 "2021-10-05T00:43:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![marizonne.villafranc](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@marizonne.villafranc](https://hub.mender.io/u/marizonne.villafranc)\
**Post date:** [October 5, 2021, 12:43am UTC](https://hub.mender.io/t/how-to-delay-an-update/4150/1 "2021-10-05T00:43:12Z")

</div>

Hi,

After downloading, the software is updated immediately. But, I am tasked to check if the ECU is currently at IDLE state before updating the software. Is there a way for me to delay the update even though the artifact is already downloaded? Which part of the mender codes I can put the checking of the ECU’s state?

Please advise. Thank you!

Kind regards,  
Marizonne

---

<div class="post-metadata">

**Author:** ![kacf](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/kacf/32/146_2.png) [@kacf](https://hub.mender.io/u/kacf)\
**Post date:** [October 5, 2021, 6:09am UTC](https://hub.mender.io/t/how-to-delay-an-update/4150/2 "2021-10-05T06:09:33Z")

</div>

You should look into [state scripts](https://docs.mender.io/development/artifact-creation/state-scripts). You can pause inside the scripts at certain points. Be aware of [the script timeout](https://docs.mender.io/development/artifact-creation/state-scripts#script-timeout) though.

For more advanced usage, you can also look into the [Update Management API](https://docs.mender.io/development/device-side-api/io.mender.update1), where the update can be controlled programmatically over DBus.

---

<div class="post-metadata">

**Author:** ![marizonne.villafranc](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@marizonne.villafranc](https://hub.mender.io/u/marizonne.villafranc)\
**Post date:** [October 29, 2021, 10:53am UTC](https://hub.mender.io/t/how-to-delay-an-update/4150/3 "2021-10-29T10:53:48Z")

</div>

Hi @kacf ! Thank you for your reply.

I created the following Download\_Enter\_00 script. It is called but the state does not transition to the next state even after the subscribe\_secc function exits. Downloading status is stuck at 69%. Am I missing something?

```auto
#!/bin/sh

echo "$(mender -show-artifact): $(basename "$0") was called!" >&2

# This script subscribes to a MQTT topic using mosquitto_sub.
# On each message received, you can execute whatever you want.

# 14 = FW_UpdateSECC
# 5 = FW_UpdateNeeded_SECC

function publish_secc()
{
	echo "$(mender -show-artifact): $(basename "$0") - publishing FW_UpdateNeeded_SECC" >&2
	while true
	do
		mosquitto_pub -h localhost -t 'FW_UpdateSECC' -m "{\"FW_UpdateNeeded\":5}"
		echo "{ FW_UpdateNeeded:5 }"
	done	
}

function subscribe_secc()
{
	echo "$(mender -show-artifact): $(basename "$0") - waiting for FW_Command = 14" >&2
	mosquitto_sub -h localhost -t 'FW_CommandSECC' | while read -r payload
	do
		# Here is the callback to execute whenever you receive a message:
		fwCmd=$(echo "Rx MQTT: ${payload}" | grep -o -E '[0-9]+')		
		if [$fwCmd -eq 14]
		then
			kill -9 $(cat /mnt/hero-secc/userdata/publish_secc.pid)
			break
		else
			echo "$(mender -show-artifact): $(basename "$0") - FW_Command = ${fwCmd}" >&2
		fi
	done
}

publish_secc &
echo $! > /mnt/hero-secc/userdata/publish_secc.pid

subscribe_secc

exit 0

```

---

<div class="post-metadata">

**Author:** ![kacf](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/kacf/32/146_2.png) [@kacf](https://hub.mender.io/u/kacf)\
**Post date:** [November 1, 2021, 7:48am UTC](https://hub.mender.io/t/how-to-delay-an-update/4150/4 "2021-11-01T07:48:27Z")

</div>

Even though it exits, are you sure all sub processes have also exited, including the background execution and all `mosquitto_sub` processes? State scripts are executed in their own process group, so I think all sub processes have to exit, not just the mother process.

---

<div class="post-metadata">

**Author:** ![marizonne.villafranc](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@marizonne.villafranc](https://hub.mender.io/u/marizonne.villafranc)\
**Post date:** [November 3, 2021, 2:45am UTC](https://hub.mender.io/t/how-to-delay-an-update/4150/5 "2021-11-03T02:45:47Z")

</div>

Thanks @kacf ! mosquitto\_sub is not killed. Everything works fine now. Thanks!
