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