# Blocking Entry to Sync state until certain network interface is active

**URL:** <https://hub.mender.io/t/blocking-entry-to-sync-state-until-certain-network-interface-is-active/2958>\
**Category:** General Discussions\
**Created:** [December 9, 2020, 12:42am UTC](https://hub.mender.io/t/blocking-entry-to-sync-state-until-certain-network-interface-is-active/2958 "2020-12-09T00:42:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![martind](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@martind](https://hub.mender.io/u/martind)\
**Post date:** [December 9, 2020, 12:42am UTC](https://hub.mender.io/t/blocking-entry-to-sync-state-until-certain-network-interface-is-active/2958/1 "2020-12-09T00:42:36Z")

</div>

Hi,

I have mender client installed as part of a system image and I now want to develop some state scripts. My first state script is to block entering Sync state until a cellular network interface is active. My device has Wifi and cellular but Wifi is only for dev / debug. I use NetworkManager so I use a connection profile state as proxy for the network interface. Here is my script Idle\_Exit\_01\_cell\_active. I have confirmed the script works on it’s own and permissions are correct

```auto
pi@raspberrypi:~ $ ls -l /etc/mender/scripts/
total 4
-rwxr-xr-x 1 root root 822 Dec 9 00:05 Idle_Exit_01_cell_active

```

```auto
#!/bin/sh
#Check and print the state of the service i.e. argus

#Mender Return values
RETRY_LATER=21
OK=0

#Mender States, given arbitrary values by 
IDLE=0
SYNC=1
DOWNLOAD=2
ARTIFACT_INSTALL=3
ARTIFACT_REBOOT=4
ARTIFACT_COMMIT=5
ARTIFACT_ROLLBACK=6
ARTIFACT_ROLLBACK_REBOOT=7
ARTIFACT_FAILURE=8

ENTER=0
EXIT=1

echo ${IDLE} ${ENTER} > /home/pi/mender-scripts-test/mender_state.log

log() {
    echo "mender:$*" >&2
}

log "$(basename "$0") state script running"

CELL_CONNECTION_STATE=$(nmcli -g GENERAL.STATE con show cellular)
if [-z "${CELL_CONNECTION_STATE}"];
then
	log "Returning ${RETRY_LATER} from script"	
	exit ${RETRY_LATER} 
elif ["${CELL_CONNECTION_STATE}" = "activated"];
then
	log "Returning ${OK} from script"
	exit ${OK}
else
	log "Returning ${RETRY_LATER} from script"	
	exit ${RETRY_LATER} 
	
fi		

```

1. Since I did not include state scripts when I made my image where do I put rootfs scripts (Idle, Sync and Download) in the file system. I have copied them to /etc/mender/scripts after stop the mender-client service. There could be bugs in my script but I don’t think it is running as I see hosted mender report the device is connecting every few seconds
2. Is Idle Exit a good place to block the mender client from checking in. My other thought was Sync Enter but I don’t see a difference between them.

My application is using the directory update module so I’m hoping I can test and develop all my state scripts before including them in the rootfs. Artifacts will of course have to be built into my updates with mender-artifact.

Thanks!!

---

<div class="post-metadata">

**Author:** ![mirzak](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mirzak/32/2056_2.png) [@mirzak](https://hub.mender.io/u/mirzak)\
**Post date:** [December 9, 2020, 8:57am UTC](https://hub.mender.io/t/blocking-entry-to-sync-state-until-certain-network-interface-is-active/2958/2 "2020-12-09T08:57:52Z")

</div>

Hi @martind, can you share the Mender client log? Think this should reveal what is going on.

E.g `journalctl -a -f -u mender-client`

---

<div class="post-metadata">

**Author:** ![martind](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@martind](https://hub.mender.io/u/martind)\
**Post date:** [December 9, 2020, 5:12pm UTC](https://hub.mender.io/t/blocking-entry-to-sync-state-until-certain-network-interface-is-active/2958/3 "2020-12-09T17:12:06Z")

</div>

Here you go @mirzak

```auto
pi@raspberrypi:~ $ sudo systemctl restart mender-client
pi@raspberrypi:~ $ sudo journalctl -a -f -u mender-client
-- Logs begin at Mon 2020-11-30 21:38:27 GMT. --
Dec 09 17:08:40 raspberrypi systemd[1]: Stopped Mender OTA update service.
Dec 09 17:08:40 raspberrypi systemd[1]: Started Mender OTA update service.
Dec 09 17:08:40 raspberrypi mender[1193]: time="2020-12-09T17:08:40Z" level=info msg="Loaded configuration file: /var/lib/mender/mender.conf" module=config
Dec 09 17:08:40 raspberrypi mender[1193]: time="2020-12-09T17:08:40Z" level=info msg="Loaded configuration file: /etc/mender/mender.conf" module=config
Dec 09 17:08:41 raspberrypi mender[1193]: time="2020-12-09T17:08:41Z" level=info msg="Mender running on partition: /dev/mmcblk0p2" module=cli
Dec 09 17:08:41 raspberrypi mender[1193]: time="2020-12-09T17:08:41Z" level=info msg="State transition: init [none] -> init [none]" module=mender
Dec 09 17:08:41 raspberrypi mender[1193]: time="2020-12-09T17:08:41Z" level=info msg="State transition: init [none] -> idle [Idle]" module=mender
Dec 09 17:08:41 raspberrypi mender[1193]: time="2020-12-09T17:08:41Z" level=info msg="authorization data present and valid" module=mender
Dec 09 17:08:41 raspberrypi mender[1193]: time="2020-12-09T17:08:41Z" level=info msg="State transition: idle [Idle] -> check-wait [Idle]" module=mender
Dec 09 17:08:41 raspberrypi mender[1193]: time="2020-12-09T17:08:41Z" level=info msg="State transition: check-wait [Idle] -> inventory-update [Sync]" module=mender
Dec 09 17:08:43 raspberrypi mender[1193]: time="2020-12-09T17:08:43Z" level=info msg="State transition: inventory-update [Sync] -> check-wait [Idle]" module=mender
Dec 09 17:08:43 raspberrypi mender[1193]: time="2020-12-09T17:08:43Z" level=info msg="State transition: check-wait [Idle] -> update-check [Sync]" module=mender
Dec 09 17:08:43 raspberrypi mender[1193]: time="2020-12-09T17:08:43Z" level=info msg="State transition: update-check [Sync] -> check-wait [Idle]" module=mender
Dec 09 17:08:51 raspberrypi mender[1193]: time="2020-12-09T17:08:51Z" level=info msg="State transition: check-wait [Idle] -> inventory-update [Sync]" module=mender
Dec 09 17:08:51 raspberrypi mender[1193]: time="2020-12-09T17:08:51Z" level=info msg="State transition: inventory-update [Sync] -> check-wait [Idle]" module=mender
Dec 09 17:08:53 raspberrypi mender[1193]: time="2020-12-09T17:08:53Z" level=info msg="State transition: check-wait [Idle] -> update-check [Sync]" module=mender
Dec 09 17:08:53 raspberrypi mender[1193]: time="2020-12-09T17:08:53Z" level=info msg="State transition: update-check [Sync] -> check-wait [Idle]" module=mender

```

---

<div class="post-metadata">

**Author:** ![martind](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@martind](https://hub.mender.io/u/martind)\
**Post date:** [December 9, 2020, 6:58pm UTC](https://hub.mender.io/t/blocking-entry-to-sync-state-until-certain-network-interface-is-active/2958/4 "2020-12-09T18:58:40Z")

</div>

I found I made a mistake in naming my script. It should be Idle\_ **Leave** NOT Idle\_ **Exit**

Also I encountered the same issue as [`version` of state-scripts in /etc/mender](https://hub.mender.io/t/version-of-state-scripts-in-etc-mender/894) when I tried to run my scripts. If the version file does not exist in your /etc/mender/scripts directory you have to create one and write **3** into the file. I used mender-convert to make my image and this file was not present. I found **version** file in /data/mender/scripts but it was empty.
