Blocking Entry to Sync state until certain network interface is active

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

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
#!/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!!

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

Here you go @mirzak

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

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 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.

1 Like