Skip to content

Commit e478ec9

Browse files
authored
Merge pull request #73 from grisp/sylane/reboot-callback
Add reboot callback
2 parents a6dcd71 + 9941444 commit e478ec9

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/grisp_connect.app.src

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
{ws_request_timeout, 5_000},
2525
{ws_ping_timeout, 60_000},
2626
{ws_max_retries, infinity},
27+
{reboot_cb, undefined},
2728
{allow_expired_certs, false},
2829
% Must be writable and match the cacertfile in ssl_dist_opts.rel
2930
{board_certificate, "/etc/board.pem"},

src/grisp_connect_client.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ handle_common(cast, {notify, _Method, _Type, _Params}, _State, _Data) ->
267267
% We ignore notifications sent while disconnected
268268
keep_state_and_data;
269269
handle_common(info, reboot, _, _) ->
270-
init:stop(),
270+
grisp_connect_utils:reboot(),
271271
keep_state_and_data;
272272
handle_common(info, {'EXIT', Conn, Reason}, _State, Data = #data{conn = Conn}) ->
273273
RealReason = case Reason of

src/grisp_connect_utils.erl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
% API functions
77
-export([using_grisp_netman/0]).
8+
-export([reboot/0]).
89
-export([retry_delay/1]).
910
-export([check_inet_ipv4/0]).
1011

@@ -15,6 +16,19 @@ using_grisp_netman() ->
1516
RunningApps = application:which_applications(),
1617
lists:keymember(grisp_netman, 1, RunningApps).
1718

19+
reboot() ->
20+
case application:get_env(grisp_connect, reboot_cb) of
21+
undefined ->
22+
init:stop();
23+
{ok, undefined} ->
24+
init:stop();
25+
{ok, {Module, Function}}
26+
when is_atom(Module), is_atom(Function) ->
27+
Module:Function();
28+
{ok, Value} ->
29+
error({invalid_env, reboot_cb, Value})
30+
end.
31+
1832
check_inet_ipv4() ->
1933
case get_ip_of_valid_interfaces() of
2034
{ok, {IP1, _, _, _} = IP} when IP1 =/= 127 -> {ok, IP};

0 commit comments

Comments
 (0)