Device decommissioning, states and unreachable network

Hello,

How can one check the device state via cli?

Asking this because I’ve hit a strange state where the device is decommissioned on my hosted.mender.io panel and then rebooted.

Upon booting it hit the network error (raspbian):

journalctl -f -u mender
-- Logs begin at Thu 2016-11-03 17:16:43 GMT. --
Apr 15 07:40:20 raspberrypi mender[315]: time="2019-04-15T07:40:20+01:00" level=info msg="State transition: error [Error] -> idle [Idle]" module=mender
Apr 15 07:40:20 raspberrypi mender[315]: level=error msg="Error receiving scheduled update data: update check request failed: Get https://hosted.mender.io/api/devices/v1/deployments/device/deployments/next?artifact_name=2018-11-13-raspbian-zicher&device_type=raspberrypi3: dial tcp: lookup hosted.mender.io on <ip>:53: dial udp <ip>:53: connect: network is unreachable" module=mender
Apr 15 07:40:20 raspberrypi mender[315]: time="2019-04-15T07:40:20+01:00" level=info msg="authorization data present and valid" module=mender
Apr 15 07:40:20 raspberrypi mender[315]: time="2019-04-15T07:40:20+01:00" level=info msg="State transition: idle [Idle] -> check-wait [Idle]" module=mender
Apr 15 07:40:20 raspberrypi mender[315]: level=error msg="update check failed: transient error: update check request failed: Get https://hosted.mender.io/api/devices/v1/deployments/device/deployments/next?artifact_name=2018-11-13-raspbian-zicher&device_type=raspberrypi3: dial tcp: lookup hosted.mender.io on <ip>:53: dial udp <ip>:53: connect: network is unreachable" module=state
Apr 15 07:40:20 raspberrypi mender[315]: level=info msg="State transition: update-check [Sync] -> error [Error]" module=mender
Apr 15 07:40:20 raspberrypi mender[315]: level=info msg="handling error state, current error: transient error: update check request failed: Get https://hosted.mender.io/api/devices/v1/deployments/device/deployments/next?artifact_name=2018-11-13-raspbian-zicher&device_type=raspberrypi3: dial tcp: lookup hosted.mender.io on <ip>:53: dial udp <ip>:53: connect: network is unreachable" module=state
Apr 15 07:40:20 raspberrypi mender[315]: level=info msg="State transition: error [Error] -> idle [Idle]" module=mender
Apr 15 07:40:20 raspberrypi mender[315]: level=info msg="authorization data present and valid" module=mender
Apr 15 07:40:20 raspberrypi mender[315]: level=info msg="State transition: idle [Idle] -> check-wait [Idle]" module=mender

The device needed to wait for 30mins (UpdatePollIntervalSeconds) to send a new pending device auth request. It uses a mender (stable) image made from a golden image of raspbian (stable) with mender-convert.

What I’m interested in is what state is safe to use to perform application configuration (auth to 3rd party systems, app config fetching to memory/tmp store…). I suppose some Idle or Sync state? I need to perform such operations only if the device is authorized on mender and in ready state.

Thanks in advance!

The network error is because the Mender client is started before there is any available network. You can probably get around this using some systemd logic.

What I’m interested in is what state is safe to use to perform application configuration (auth to 3rd party systems, app config fetching to memory/tmp store…). I suppose some Idle or Sync state? I need to perform such operations only if the device is authorized on mender and in ready state.

I am not sure I follow what you want to do. The Mender states are only interesting during an update sequence and you can hook in to the different states using state-scripts,

https://docs.mender.io/1.7/artifacts/state-scripts

I guess Sync_Enter hook might also check for network before trying to connect, right?

What I want to do is to start connecting to external systems only after mender-client says the auth is okay on mender. I use mender as the first point of authentication and base all subsequent actions (not related to mender) after mender connection is right.

In example, I don’t want to connect to anything if mender-client didn’t pass the onboarding process (when it’s in pending state). Is there something on the filesystem from where I could get some info about it (except journalctl)?

There are some state files written into /data/mender that could possibly be used but that would be error prone since it’s not explicitly intended for this usage. You could use the server API to check the device state but that’s obviously a fairly heavy-weight solution.