/home/runner/work/textgroup/textgroup/_build/test/cover/ct/textgroup_app.html

1 %%% Textgroup server.
2 %%%
3 %%% Copyright (c) 2022 Holger Weiss <holger@zedat.fu-berlin.de>.
4 %%% All rights reserved.
5 %%%
6 %%% Licensed under the Apache License, Version 2.0 (the "License");
7 %%% you may not use this file except in compliance with the License.
8 %%% You may obtain a copy of the License at
9 %%%
10 %%% http://www.apache.org/licenses/LICENSE-2.0
11 %%%
12 %%% Unless required by applicable law or agreed to in writing, software
13 %%% distributed under the License is distributed on an "AS IS" BASIS,
14 %%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 %%% See the License for the specific language governing permissions and
16 %%% limitations under the License.
17
18 -module(textgroup_app).
19 -behaviour(application).
20 -export([start/2,
21 prep_stop/1,
22 stop/1,
23 config_change/3]).
24
25 -include_lib("kernel/include/logger.hrl").
26
27 %% API.
28
29 -spec start(application:start_type(), any()) -> {ok, pid()} | {error, term()}.
30 start(_StartType, _StartArgs) ->
31 1 ?LOG_NOTICE("Starting Textgroup ~s on Erlang/OTP ~s (ERTS ~s)",
32 [version(),
33 erlang:system_info(otp_release),
34
:-(
erlang:system_info(version)]),
35 1 case textgroup_sup:start_link() of
36 {ok, _PID} = Result ->
37 1 ok = textgroup_systemd:ready(),
38 1 Result;
39 {error, _Reason} = Err ->
40
:-(
Err
41 end.
42
43 -spec prep_stop(term()) -> term().
44 prep_stop(State) ->
45 1 ok = textgroup_systemd:stopping(),
46 1 State.
47
48 -spec stop(term()) -> ok.
49 stop(_State) ->
50 1 ?LOG_NOTICE("Stopping Textgroup ~s on Erlang/OTP ~s (ERTS ~s)",
51 [version(),
52 erlang:system_info(otp_release),
53
:-(
erlang:system_info(version)]),
54 1 ok.
55
56 -spec config_change([{atom(), term()}], [{atom(), term()}], [atom()]) -> ok.
57 config_change(Changed, _New, _Removed) ->
58 1 ok = textgroup_systemd:reloading(),
59 1 ReopenSocket = lists:any(fun({Key, _Val}) ->
60 1 lists:member(Key, [port, pool_size])
61 end, Changed),
62 1 case ReopenSocket of
63 true ->
64 1 ok = restart_acceptors();
65 false ->
66
:-(
ok
67 end,
68 1 ok = textgroup_systemd:ready().
69
70 %% Internal functions.
71
72 -spec restart_acceptors() -> ok.
73 restart_acceptors() ->
74 1 ok = supervisor:terminate_child(textgroup_sup, textgroup_acceptor_sup),
75 1 {ok, _PID} = supervisor:restart_child(textgroup_sup,
76 textgroup_acceptor_sup),
77 1 ok.
78
79 -spec version() -> binary().
80 version() ->
81 2 {ok, Version} = application:get_key(vsn),
82 2 unicode:characters_to_binary(Version).
Line Hits Source