diff --git a/src/grisp_connect.app.src b/src/grisp_connect.app.src index 75a8cd5..c99a067 100644 --- a/src/grisp_connect.app.src +++ b/src/grisp_connect.app.src @@ -24,6 +24,7 @@ {ws_request_timeout, 5_000}, {ws_ping_timeout, 60_000}, {ws_max_retries, infinity}, + {reboot_cb, undefined}, {allow_expired_certs, false}, % Must be writable and match the cacertfile in ssl_dist_opts.rel {board_certificate, "/etc/board.pem"}, diff --git a/src/grisp_connect_client.erl b/src/grisp_connect_client.erl index 5c78b92..33068ed 100644 --- a/src/grisp_connect_client.erl +++ b/src/grisp_connect_client.erl @@ -267,7 +267,7 @@ handle_common(cast, {notify, _Method, _Type, _Params}, _State, _Data) -> % We ignore notifications sent while disconnected keep_state_and_data; handle_common(info, reboot, _, _) -> - init:stop(), + grisp_connect_utils:reboot(), keep_state_and_data; handle_common(info, {'EXIT', Conn, Reason}, _State, Data = #data{conn = Conn}) -> RealReason = case Reason of diff --git a/src/grisp_connect_utils.erl b/src/grisp_connect_utils.erl index f5e98f4..31b581e 100644 --- a/src/grisp_connect_utils.erl +++ b/src/grisp_connect_utils.erl @@ -5,6 +5,7 @@ % API functions -export([using_grisp_netman/0]). +-export([reboot/0]). -export([retry_delay/1]). -export([check_inet_ipv4/0]). @@ -15,6 +16,19 @@ using_grisp_netman() -> RunningApps = application:which_applications(), lists:keymember(grisp_netman, 1, RunningApps). +reboot() -> + case application:get_env(grisp_connect, reboot_cb) of + undefined -> + init:stop(); + {ok, undefined} -> + init:stop(); + {ok, {Module, Function}} + when is_atom(Module), is_atom(Function) -> + Module:Function(); + {ok, Value} -> + error({invalid_env, reboot_cb, Value}) + end. + check_inet_ipv4() -> case get_ip_of_valid_interfaces() of {ok, {IP1, _, _, _} = IP} when IP1 =/= 127 -> {ok, IP};