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
5 Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
7 diff --git a/src/rabbit.erl b/src/rabbit.erl
8 index a86fd97..32ff240 100644
11 @@ -280,120 +280,8 @@ broker_start() ->
12 Plugins = rabbit_plugins:setup(),
13 ToBeLoaded = Plugins ++ ?APPS,
14 start_apps(ToBeLoaded),
16 ok = log_broker_started(rabbit_plugins:active()).
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
23 - case sd_notify_ready() of
25 - io:format(standard_error, "systemd READY notification failed, beware of timeouts~n", []);
31 - case {os:type(), os:getenv("NOTIFY_SOCKET")} of
34 - {_, [_|_]} -> %% Non-empty NOTIFY_SOCKET, give it a try
35 - sd_notify_legacy() orelse sd_notify_socat();
41 - "READY=1\nSTATUS=Initialized\nMAINPID=" ++ os:getpid() ++ "\n".
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()),
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
57 -%% - systemd-notify(1) is unstable for non-root users
58 -%% - erlang doesn't support unix domain sockets.
60 -%% Some details on how we ended with such a solution:
61 -%% https://github.com/rabbitmq/rabbitmq-server/issues/664
63 - case sd_current_unit() of
65 - io:format(standard_error, "systemd unit for activation check: \"~s\"~n", [Unit]),
66 - sd_notify_socat(Unit);
71 -socat_socket_arg("@" ++ AbstractUnixSocket) ->
72 - "abstract-sendto:" ++ AbstractUnixSocket;
73 -socat_socket_arg(UnixSocket) ->
74 - "unix-sendto:" ++ UnixSocket.
78 - {spawn_executable, os:find_executable("socat")},
79 - [{args, [socat_socket_arg(os:getenv("NOTIFY_SOCKET")), "STDIO"]},
82 -sd_notify_socat(Unit) ->
83 - case sd_open_port() of
85 - io:format(standard_error, "Failed to start socat ~p~n", [Exit]),
88 - Port ! {self(), {command, sd_notify_data()}},
89 - Result = sd_wait_activation(Port, Unit),
95 - case catch re:run(os:cmd("systemctl status " ++ os:getpid()), "([-.@0-9a-zA-Z]+)", [unicode, {capture, all_but_first, list}]) of
104 -sd_wait_activation(Port, Unit) ->
105 - case os:find_executable("systemctl") of
107 - io:format(standard_error, "'systemctl' unavailable, falling back to sleep~n", []),
111 - sd_wait_activation(Port, Unit, 10)
114 -sd_wait_activation(_, _, 0) ->
115 - io:format(standard_error, "Service still in 'activating' state, bailing out~n", []),
117 -sd_wait_activation(Port, Unit, AttemptsLeft) ->
118 - case os:cmd("systemctl show --property=ActiveState " ++ Unit) of
119 - "ActiveState=activating\n" ->
121 - sd_wait_activation(Port, Unit, AttemptsLeft - 1);
122 - "ActiveState=" ++ _ ->
125 - io:format(standard_error, "Unexpected status from systemd ~p~n", [Err]),
129 start_it(StartFun) ->
130 Marker = spawn_link(fun() -> receive stop -> ok end end),
131 case catch register(rabbit_boot, Marker) of