Detecting whether container was started "at boot" within the container

We need to monitor the “boot” time between when the power is plugged into the device and when our application is ready for use. We only want to measure during normal use cycles not during updates as that will add noise to our measurements.

The normal use cycle for our devices is to be turned on by applying power, be active for 10-40 minutes, and then be turned off by pulling the power. In these cycles reading the value of uptime when our application is ready will give the desired result.

In “abnormal” use cycles, such as updating the application, reading the value of uptime will add noise to our measurements. We are looking for a solution to deterministically detect whether the container was started at boot or at some later point in time.

We could detect this by comparing the uptime (of the host) to when the first process was started (e.g. stat /proc/1/cmdline). However, we would prefer a solution that does not depend on time as we cannot control how long the device is on during either normal or abnormal use.

Hi @mhe_lorenz,

Have you tried mining the output of dmesg for the event(s) you’re looking for? Also, enabling DEBUG=1 in your environment variables for the device can give you more detailed logging, which is viewable from the balenaCloud dashboard via Release -> latest Succeeded entry -> Build Logs --> service. You can also view logs from the command line with balena logs <device UUID>.

John