Revert "Revert "oran-shell-release: release image for F""
[pti/rtp.git] / meta-starlingx / meta-stx-cloud / recipes-extended / rabbitmq / files / rabbitmq-server-0001-Remove-excessive-sd_notify-code.patch
1 From: Peter Lemenkov <lemenkov@gmail.com>
2 Date: Thu, 19 May 2016 16:04:56 +0300
3 Subject: [PATCH] Remove excessive sd_notify code
4
5 Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
6
7 diff --git a/src/rabbit.erl b/src/rabbit.erl
8 index a86fd97..32ff240 100644
9 --- a/src/rabbit.erl
10 +++ b/src/rabbit.erl
11 @@ -280,120 +280,8 @@ broker_start() ->
12      Plugins = rabbit_plugins:setup(),
13      ToBeLoaded = Plugins ++ ?APPS,
14      start_apps(ToBeLoaded),
15 -    maybe_sd_notify(),
16      ok = log_broker_started(rabbit_plugins:active()).
17  
18 -%% Try to send systemd ready notification if it makes sense in the
19 -%% current environment. standard_error is used intentionally in all
20 -%% logging statements, so all this messages will end in systemd
21 -%% journal.
22 -maybe_sd_notify() ->
23 -    case sd_notify_ready() of
24 -        false ->
25 -            io:format(standard_error, "systemd READY notification failed, beware of timeouts~n", []);
26 -        _ ->
27 -            ok
28 -    end.
29 -
30 -sd_notify_ready() ->
31 -    case {os:type(), os:getenv("NOTIFY_SOCKET")} of
32 -        {{win32, _}, _} ->
33 -            true;
34 -        {_, [_|_]} -> %% Non-empty NOTIFY_SOCKET, give it a try
35 -            sd_notify_legacy() orelse sd_notify_socat();
36 -        _ ->
37 -            true
38 -    end.
39 -
40 -sd_notify_data() ->
41 -    "READY=1\nSTATUS=Initialized\nMAINPID=" ++ os:getpid() ++ "\n".
42 -
43 -sd_notify_legacy() ->
44 -    case code:load_file(sd_notify) of
45 -        {module, sd_notify} ->
46 -            SDNotify = sd_notify,
47 -            SDNotify:sd_notify(0, sd_notify_data()),
48 -            true;
49 -        {error, _} ->
50 -            false
51 -    end.
52 -
53 -%% socat(1) is the most portable way the sd_notify could be
54 -%% implemented in erlang, without introducing some NIF. Currently the
55 -%% following issues prevent us from implementing it in a more
56 -%% reasonable way:
57 -%% - systemd-notify(1) is unstable for non-root users
58 -%% - erlang doesn't support unix domain sockets.
59 -%%
60 -%% Some details on how we ended with such a solution:
61 -%%   https://github.com/rabbitmq/rabbitmq-server/issues/664
62 -sd_notify_socat() ->
63 -    case sd_current_unit() of
64 -        {ok, Unit} ->
65 -            io:format(standard_error, "systemd unit for activation check: \"~s\"~n", [Unit]),
66 -            sd_notify_socat(Unit);
67 -        _ ->
68 -            false
69 -    end.
70 -
71 -socat_socket_arg("@" ++ AbstractUnixSocket) ->
72 -    "abstract-sendto:" ++ AbstractUnixSocket;
73 -socat_socket_arg(UnixSocket) ->
74 -    "unix-sendto:" ++ UnixSocket.
75 -
76 -sd_open_port() ->
77 -    open_port(
78 -      {spawn_executable, os:find_executable("socat")},
79 -      [{args, [socat_socket_arg(os:getenv("NOTIFY_SOCKET")), "STDIO"]},
80 -       use_stdio, out]).
81 -
82 -sd_notify_socat(Unit) ->
83 -    case sd_open_port() of
84 -        {'EXIT', Exit} ->
85 -            io:format(standard_error, "Failed to start socat ~p~n", [Exit]),
86 -            false;
87 -        Port ->
88 -            Port ! {self(), {command, sd_notify_data()}},
89 -            Result = sd_wait_activation(Port, Unit),
90 -            port_close(Port),
91 -            Result
92 -    end.
93 -
94 -sd_current_unit() ->
95 -    case catch re:run(os:cmd("systemctl status " ++ os:getpid()), "([-.@0-9a-zA-Z]+)", [unicode, {capture, all_but_first, list}]) of
96 -        {'EXIT', _} ->
97 -            error;
98 -        {match, [Unit]} ->
99 -            {ok, Unit};
100 -        _ ->
101 -            error
102 -    end.
103 -
104 -sd_wait_activation(Port, Unit) ->
105 -    case os:find_executable("systemctl") of
106 -        false ->
107 -            io:format(standard_error, "'systemctl' unavailable, falling back to sleep~n", []),
108 -            timer:sleep(5000),
109 -            true;
110 -        _ ->
111 -            sd_wait_activation(Port, Unit, 10)
112 -    end.
113 -
114 -sd_wait_activation(_, _, 0) ->
115 -    io:format(standard_error, "Service still in 'activating' state, bailing out~n", []),
116 -    false;
117 -sd_wait_activation(Port, Unit, AttemptsLeft) ->
118 -    case os:cmd("systemctl show --property=ActiveState " ++ Unit) of
119 -        "ActiveState=activating\n" ->
120 -            timer:sleep(1000),
121 -            sd_wait_activation(Port, Unit, AttemptsLeft - 1);
122 -        "ActiveState=" ++ _ ->
123 -            true;
124 -        _ = Err->
125 -            io:format(standard_error, "Unexpected status from systemd ~p~n", [Err]),
126 -            false
127 -    end.
128 -
129  start_it(StartFun) ->
130      Marker = spawn_link(fun() -> receive stop -> ok end end),
131      case catch register(rabbit_boot, Marker) of