GajuDesk/src/clutch.erl
2024-11-08 17:40:01 +09:00

71 lines
1.9 KiB
Erlang

%%% @doc
%%% Clutch
%%% @end
-module(clutch).
-vsn("0.1.0").
-behavior(application).
-author("Craig Everett <craigeverett@qpq.swiss>").
-copyright("QPQ AG <info@qpq.swiss>").
-license("GPL-3.0-or-later").
-export([ts/0]).
-export([start/2, stop/1]).
-export_type([id/0, key/0, poa/0, tx/0, ts/0]).
-include("$zx_include/zx_logger.hrl").
-include("gmc.hrl").
-type id() :: binary().
-type key() :: #key{}.
-type poa() :: #poa{}.
-type tx() :: #tx{}.
-type ts() :: integer().
ts() ->
erlang:system_time(nanosecond).
-spec start(normal, Args :: term()) -> {ok, pid()}.
%% @private
%% Called by OTP to kick things off. This is for the use of the "application" part of
%% OTP, not to be called by user code.
%%
%% NOTE:
%% The commented out second argument would come from ebin/clutch.app's 'mod'
%% section, which is difficult to define dynamically so is not used by default
%% here (if you need this, you already know how to change it).
%%
%% Optional runtime arguments passed in at start time can be obtained by calling
%% zx_daemon:argv/0 anywhere in the body of the program.
%%
%% See: http://erlang.org/doc/apps/kernel/application.html
start(normal, _Args) ->
ok =
case net_kernel:stop() of
ok ->
log(info, "SAFE: This node is running standalone.");
{error, not_found} ->
log(warning, "SAFETY: Distribution has been disabled on this node.");
{error, not_allowed} ->
ok = tell(error, "DANGER! This node is in distributed mode!"),
init:stop(1)
end,
ok = application:ensure_started(sasl),
ok = application:ensure_started(hakuzaru),
ok = application:ensure_started(zxwidgets),
gmc_sup:start_link().
-spec stop(term()) -> ok.
%% @private
%% Similar to start/2 above, this is to be called by the "application" part of OTP,
%% not client code. Causes a (hopefully graceful) shutdown of the application.
stop(_State) ->
ok.