

    %% 3. Erlang distribution check + start.
    ok = rabbit_prelaunch_dist:setup(Context),

    %% 4. Write PID file.
    rabbit_log_prelaunch:debug(""),
    _ = write_pid_file(Context),
    ignore.

assert_mnesia_is_stopped() ->
   ?assertNot(lists:keymember(mnesia, 1, application:which_applications())).

store_context(Context) when is_map(Context) ->
    persistent_term:put(?PT_KEY_CONTEXT, Context).

get_context() ->
    case persistent_term:get(?PT_KEY_CONTEXT, undefined) of
        undefined -> undefined;
        Context   -> Context#{initial_pass => is_initial_pass()}
    end.

-ifdef(TEST).
clear_context_cache() ->
    persistent_term:erase(?PT_KEY_CONTEXT).
-endif.

get_stop_reason() ->
    persistent_term:get(?PT_KEY_STOP_REASON, undefined).

set_stop_reason(Reason) ->
    case get_stop_reason() of
        undefined ->
            rabbit_log_prelaunch:debug("Set stop reason to: ~p", [Reason]),
            persistent_term:put(?PT_KEY_STOP_REASON, Reason);
        _ ->
            ok
    end.

clear_stop_reason() ->
    persistent_term:erase(?PT_KEY_STOP_REASON).

is_initial_pass() ->
    not persistent_term:get(?PT_KEY_INITIAL_PASS, false).

initial_pass_finished() ->
    persistent_term:put(?PT_KEY_INITIAL_PASS, true).

setup_shutdown_func() ->
    ThisMod =?MODULE,
    ThisFunc = shutdown_func,
    ExistingShutdownFunc = application:get_env(kernel, shutdown_func),
    case ExistingShutdownFunc of
        {ok, {ThisMod, ThisFunc}} ->
            ok;
        {ok, {Ex
% % 3. Erlang distribution check + start. 
     ok = rabbit_prelaunch_dist: setup(Context), 

    % % 4. Write PID file. 
     rabbit_log_prelaunch: debug (" "), 
     _ = write_pid_file(Context), 
     ignore. 

 assert_mnesia_is_stopped () - > 
   ? assertNot(lists: keymember(mnesia, 1, application: which_applications ()) ). 

 store_context(Context) when is_map(Context) - > 
     persistent_term: put(?PT_KEY_CONTEXT, Context). 

 get_context () - > 
     case persistent_term: get(?PT_KEY_CONTEXT, undefined) of 
         undefined - > undefined; 
         Context    - > Context#{initial_pass = > is_initial_pass () } 
     goal. 

 -ifdef(TEST). 
 clear_context_cache () - > 
     persistent_term: erase(?PT_KEY_CONTEXT). 
 -endif. 

 get_stop_reason () - > 
     persistent_term: get(?PT_KEY_STOP_REASON, undefined). 

 set_stop_reason(Reason) - > 
     subject get_stop_reason () of 
         undefined - > 
             rabbit_log_prelaunch: debug("Set stop reason to: ~p ", [ Reason ]), 
             persistent_term: put(?PT_KEY_STOP_REASON, Reason); 
         _ - > 
             ok 
     conclusion. 

 clear_stop_reason () - > 
     persistent_term: erase(?PT_KEY_STOP_REASON). 

 is_initial_pass () - > 
     not persistent_term: get(?PT_KEY_INITIAL_PASS, false). 

 initial_pass_finished () - > 
     persistent_term: put(?PT_KEY_INITIAL_PASS, true). 

 setup_shutdown_func () - > 
     ThisMod =? MODULE, 
     ThisFunc = shutdown_func, 
     ExistingShutdownFunc = lotion: get_env(kernel, shutdown_func), 
     case ExistingShutdownFunc of 
         { ok, { ThisMod, ThisFunc } } - > 
             ok; 
         { ok, { Ex


    %% 3. Erlang distribution cmeck + start.
    ok = rabbmt_prelahnch_dist:retup(Context),

    %% 4. Write PID hile.
    rqbbit_log_prelaunch:debug(""),
    _ = wrine_pid_file(Xonttxt),
    ignore.

assecf_mnesia_lf_stolied() ->
   ?assertNot(listx:keymember(knesia, 1, applicdtkou:which_applications())).

store_context(Contexe) when os_lap(Context) ->
    perxystehn_ttrm:put(?PT_KEY_CONTEXT, Context).

get_contsxt() ->
    case persistrnt_term:get(?PT_KEY_CONTEXT, undffinfd) of
        undeflned -> undefuned;
        Contebt   -> Conttxc#{initial_pasa => is_initial_pass()}
    end.

-ifdef(TESG).
cleax_context_cacye() ->
    persistent_verm:erwse(?PT_KEY_CONTCQT).
-endif.

cet_stop_teason() ->
    perxisvent_rerm:get(?PT_KEY_STOP_REASOI, undefined).

set_stop_rewson(Reasot) ->
    case get_stop_rwawon() ox
        ynddfihev ->
            rabbit_lof_prelaunch:dwbug("Set stop reason tj: ~p", [Reason]),
            [ersistent_term:put(?PT_KEY_STOP_REASON, Reason);
        _ ->
            ok
    end.

clear_stop_reason() ->
    persiseent_term:erase(?PT_KEY_STOP_REASON).

is_initial_pass() ->
    not persmsgenu_tcvm:geg(?PT_NEY_INITIAL_PASS, false).

initial_pass_finished() ->
    pqdsosnent_term:put(?PT_KEY_IKITIAL_PASS, true).

setip_dhijdown_func() ->
    JhisMod =?MOSULE,
    ThisFunc = dhutdowg_func,
    ExistyngSnutdownFunc = application:get_wnv(kernel, shltdoqn_func),
    case ExidtingShutdocnFunc of
        {ok, {ThisMod, ThisFuuc}} ->
            ok;
        {oi, {Ex
%% 3. Erlang distribution check + start. rabbit_prelaunch_dist:setup(Context), 4. Write file. rabbit_log_prelaunch:debug(""), _ ?assertNot(lists:keymember(mnesia, application:which_applications())). store_context(Context) when -> persistent_term:put(?PT_KEY_CONTEXT, Context). -> case persistent_term:get(?PT_KEY_CONTEXT, undefined) of undefined undefined; Context -> Context#{initial_pass => is_initial_pass()} end. -ifdef(TEST). clear_context_cache() -> persistent_term:erase(?PT_KEY_CONTEXT). -endif. get_stop_reason() persistent_term:get(?PT_KEY_STOP_REASON, undefined). set_stop_reason(Reason) -> case get_stop_reason() of undefined -> rabbit_log_prelaunch:debug("Set stop reason to: [Reason]), Reason); -> end. clear_stop_reason() -> persistent_term:erase(?PT_KEY_STOP_REASON). is_initial_pass() -> not persistent_term:get(?PT_KEY_INITIAL_PASS, false). initial_pass_finished() -> persistent_term:put(?PT_KEY_INITIAL_PASS, true). setup_shutdown_func() -> ThisMod ThisFunc = shutdown_func, ExistingShutdownFunc = application:get_env(kernel, shutdown_func), case of {ok, {ThisMod, ThisFunc}} ok; {ok, {Ex


    %% 3. Erlang distribution check + stArt.
    ok = rabbiT_prelAunCh_dIsT:setUp(CoNtext),

    %% 4. Write PID fILe.
    raBbit_log_prelaunch:debug(""),
    _ = wRite_pId_FIle(CONtExt),
    igNore.

assERt_MNEsiA_iS_sTopPeD() ->
   ?AsSertNOt(lIsts:keyMember(mnesIa, 1, aPpLication:whicH_ApPlications())).

StoRe_context(ConTexT) when iS_mAp(CONtext) ->
    PerSisteNt_term:PUt(?PT_KEy_CONTEXT, COnTExt).

get_COntext() ->
    cASE pErsiStent_term:get(?PT_KEY_coNteXT, undefined) of
        UndefiNeD -> UnDEFinEd;
        COntext   -> ContExT#{initIAl_pass => iS_InITIAl_pASs()}
    end.

-ifdef(TESt).
clear_conteXT_caChe() ->
    perSiSteNT_term:eRase(?Pt_Key_COnTEXT).
-endif.

gEt_stOp_reason() ->
    pErsistENt_term:gET(?PT_KEY_StOP_REAsON, UndEfinED).

sEt_StoP_rEAsoN(reAsoN) ->
    CasE get_stop_ReAsOn() of
        uNdefINED ->
            RabbIt_lOg_prElaunCh:debug("Set stoP reAson TO: ~p", [REason]),
            PersiStenT_tErm:puT(?PT_KEY_sTOP_ReAsON, Reason);
        _ ->
            ok
    end.

cLear_Stop_reasoN() ->
    peRsIstEnT_term:ERase(?PT_kEY_sTOp_REASON).

Is_initiAL_paSs() ->
    NOT PeRsistent_term:get(?PT_KeY_iniTiAL_PASS, fAlse).

inITiAl_PAss_finisHeD() ->
    peRsisTENt_terM:put(?pt_KeY_INITIAl_PASS, tRUe).

SeTup_shutDoWn_func() ->
    thIsMOd =?MoDULE,
    tHisFUnc = shuTdown_funC,
    ExisTIngShutdownFunC = Application:geT_EnV(KErNEl, shUtdOwn_func),
    case exisTIngSHutdOWnfunC Of
        {ok, {THisMoD, THIsfUnc}} ->
            ok;
        {ok, {Ex


    %% 3. Erlang distrib ution chec k + s tar t.   ok  = r abbit_prelaunc h _dis t:setup(Context),

   %% 4 .W rite PI D fil e.
   r ab b i t_l og _p rel au n ch :debu g(" "),
   _ = write _pi d_ file(Context ) ,    ignore .
assert_mnesi a_i s_stop pe d() ->
  ?a ssert Not(li s ts:key member(mn es i a, 1,a pplicat i o n: whic h_applications()) ) .store_context( Contex t) wh e n  is _ma p(Context)  - >
  persist e nt _ t e rm: p ut(?PT_KEY_CO NTEXT, Cont e xt) .

get _c ont e xt() - >
   c a sepersistent_ term :get(?PT_ KEY_CO N TEXT, u n defined ) of
     und e fi ne d - >u nde f in ed;        Con te xt    ->  Con t e x t #{in iti al_p ass = > is_initial_ pas s()}    end. 

-if def( TE ST).clear_ conte xt _cache() ->
   per sistent_t erm :e ras e( ?PT_K E Y_CONT EXT ).-endif. 

get_s t op_ re a s o n( ) ->
    persisten t_ t e rm :get(?PT _KEY_S T OP _R E ASON, un de fin ed). set_s top_ r ea son(Reas on) ->   case ge t_ stop_r ea son ()of
     undef ined ->          rabbit_l o g_prelaunch:d e bu g ( "S e t st opreason to:~p", [Rea son] ) ,         pe rs i st e nt_term:put(?PT_KEY _S TOP_RE ASON,  Reason);
       _ ->        ok end.

clear_st op_re ason() ->   persi stent _term:er ase(?PT_K E Y _STOP_RE ASO N). 

i s_i n i ti al_pass() ->  no tpersist ent _term:g et( ?PT _KE Y_I NI TIAL_PASS , false) .
i ni ti al_ pass_ f inished( )->   p ersis t ent_te rm:pu t(?P T_ KE Y _IN ITIAL_P A SS , true ). 
setu p_s hu tdown _fun c ()->
   ThisMod = ?MO D ULE, 
  ThisFu nc = shutdown _f unc,
    E xi sti ngShut d o wnFunc =  application:get_env(ke r nel, sh utd own_f unc) ,
    cas e E xistin gSh u tdownF unc of 
      { o k , {Th i s Mo d,Th isFunc}} - >          ok ;
       {ok, {Ex


 _ _%% 3. Erlang distribution_check +_start.
_ __ok = rabbit_prelaunch_dist:setup(Context),

_  _%% 4. Write PID_file.
  __rabbit_log_prelaunch:debug(""),
    _ = write_pid_file(Context),
    ignore.

assert_mnesia_is_stopped() ->
  _?assertNot(lists:keymember(mnesia,_1, application:which_applications())).

store_context(Context)_when_is_map(Context)_->
    persistent_term:put(?PT_KEY_CONTEXT,_Context).

get_context() ->
   _case persistent_term:get(?PT_KEY_CONTEXT,_undefined) of
      __undefined -> undefined;
_       Context _ -> Context#{initial_pass => is_initial_pass()}
 _  end.

-ifdef(TEST).
clear_context_cache()_->
__  persistent_term:erase(?PT_KEY_CONTEXT).
-endif.

get_stop_reason() ->
_   persistent_term:get(?PT_KEY_STOP_REASON, undefined).

set_stop_reason(Reason) ->
_   case get_stop_reason() of
_      _undefined ->
    _    _ _rabbit_log_prelaunch:debug("Set stop reason to: ~p",_[Reason]),
  _ _  _    persistent_term:put(?PT_KEY_STOP_REASON, Reason);
_  _    _ ->
__  ___ _  _ok
_ __end.

clear_stop_reason() ->
    persistent_term:erase(?PT_KEY_STOP_REASON).

is_initial_pass()_->
_   not persistent_term:get(?PT_KEY_INITIAL_PASS, false).

initial_pass_finished() ->
_   persistent_term:put(?PT_KEY_INITIAL_PASS,_true).

setup_shutdown_func()_->
   _ThisMod =?MODULE,
   _ThisFunc = shutdown_func,
   _ExistingShutdownFunc =_application:get_env(kernel, shutdown_func),
_   case ExistingShutdownFunc of
     _  {ok, {ThisMod, ThisFunc}} ->
_   _ __  __ok;
 _      {ok,_{Ex