View Source Nerves.Runtime.Heart (nerves_runtime v0.13.2)
Functions for querying Nerves Heart and the device's watchdog
Nerves Heart integrates Erlang's
heart process with a hardware
watchdog. This makes it possible for a device to recover from a hang. The
way it works is that the Erlang runtime regularly checks that it's ok. If so,
it sends a message to heart
. Nerves heart then pets the hardware watchdog.
If messages ever stop being sent to heart
, the hardware watchdog will trip
and reboot the device. You can add additional health checks for your
application by providing a callback to :heart.set_callback/2
.
See nerves_heart for more information.
Link to this section Summary
Functions
Notify Nerves heart that initialization is complete
Return whether Nerves heart is running
Return the current Nerves Heart status
Raising version of status/0
Return whether Nerves Heart supports the v2 command/status set
Link to this section Types
Nerves Heart's current status
See nerves_heart for more information.
@type info_v1() :: %{ program_name: String.t(), program_version: Version.t(), identity: String.t(), firmware_version: non_neg_integer(), options: non_neg_integer() | [atom()], time_left: non_neg_integer(), pre_timeout: non_neg_integer(), timeout: non_neg_integer(), last_boot: :power_on | :watchdog, heartbeat_timeout: non_neg_integer() }
Nerves Heart v1.x information
@type info_v2() :: %{ program_name: String.t(), program_version: Version.t(), heartbeat_timeout: non_neg_integer(), heartbeat_time_left: non_neg_integer(), init_handshake_happened: boolean(), init_handshake_timeout: non_neg_integer(), init_handshake_time_left: non_neg_integer(), wdt_identity: String.t(), wdt_firmware_version: non_neg_integer(), wdt_last_boot: :power_on | :watchdog, wdt_options: non_neg_integer() | [atom()], wdt_pet_time_left: non_neg_integer(), wdt_pre_timeout: non_neg_integer(), wdt_timeout_left: non_neg_integer(), wdt_timeout: non_neg_integer() }
Nerves Heart v2.x information
Link to this section Functions
@spec guarded_poweroff() :: :ok | {:error, :unsupported}
@spec guarded_reboot() :: :ok | {:error, :unsupported}
@spec init_complete() :: :ok
Notify Nerves heart that initialization is complete
This can be used to ensure that the code that calls :heart.set_callback/1
gets run.
To use, add the following to your projects rel/vm.args.eex
:
## Require an initialization handshake within 15 minutes
-env HEART_INIT_TIMEOUT 900
Then call Nerves.Runtime.Heart.init_complete/0
after
:heart.set_callback/1
is called.
Supported by Nerves Heart v2.0 and later
@spec running?() :: boolean()
Return whether Nerves heart is running
If you're using a Nerves device, this always returns true
except possibly
when porting Nerves to new hardware. It is a quick sanity check.
@spec status() :: {:ok, info()} | :error
Return the current Nerves Heart status
Errors are returned when not running Nerves Heart
@spec status!() :: info()
Raising version of status/0
@spec supports_v2?() :: boolean()
Return whether Nerves Heart supports the v2 command/status set