diff --git a/rabbitmq-server-0001-Remove-excessive-sd_notify-code.patch b/rabbitmq-server-0001-Remove-excessive-sd_notify-code.patch new file mode 100644 index 0000000..ba3ed59 --- /dev/null +++ b/rabbitmq-server-0001-Remove-excessive-sd_notify-code.patch @@ -0,0 +1,131 @@ +From: Peter Lemenkov +Date: Thu, 19 May 2016 16:04:56 +0300 +Subject: [PATCH] Remove excessive sd_notify code + +Signed-off-by: Peter Lemenkov + +diff --git a/src/rabbit.erl b/src/rabbit.erl +index 2cc353d..8a19427 100644 +--- a/src/rabbit.erl ++++ b/src/rabbit.erl +@@ -284,120 +284,8 @@ broker_start() -> + Plugins = rabbit_plugins:setup(), + ToBeLoaded = Plugins ++ ?APPS, + start_apps(ToBeLoaded), +- maybe_sd_notify(), + ok = log_broker_started(rabbit_plugins:active()). + +-%% Try to send systemd ready notification if it makes sense in the +-%% current environment. standard_error is used intentionally in all +-%% logging statements, so all this messages will end in systemd +-%% journal. +-maybe_sd_notify() -> +- case sd_notify_ready() of +- false -> +- io:format(standard_error, "systemd READY notification failed, beware of timeouts~n", []); +- _ -> +- ok +- end. +- +-sd_notify_ready() -> +- case {os:type(), os:getenv("NOTIFY_SOCKET")} of +- {{win32, _}, _} -> +- true; +- {_, [_|_]} -> %% Non-empty NOTIFY_SOCKET, give it a try +- sd_notify_legacy() orelse sd_notify_socat(); +- _ -> +- true +- end. +- +-sd_notify_data() -> +- "READY=1\nSTATUS=Initialized\nMAINPID=" ++ os:getpid() ++ "\n". +- +-sd_notify_legacy() -> +- case code:load_file(sd_notify) of +- {module, sd_notify} -> +- SDNotify = sd_notify, +- SDNotify:sd_notify(0, sd_notify_data()), +- true; +- {error, _} -> +- false +- end. +- +-%% socat(1) is the most portable way the sd_notify could be +-%% implemented in erlang, without introducing some NIF. Currently the +-%% following issues prevent us from implementing it in a more +-%% reasonable way: +-%% - systemd-notify(1) is unstable for non-root users +-%% - erlang doesn't support unix domain sockets. +-%% +-%% Some details on how we ended with such a solution: +-%% https://github.com/rabbitmq/rabbitmq-server/issues/664 +-sd_notify_socat() -> +- case sd_current_unit() of +- {ok, Unit} -> +- io:format(standard_error, "systemd unit for activation check: \"~s\"~n", [Unit]), +- sd_notify_socat(Unit); +- _ -> +- false +- end. +- +-socat_socket_arg("@" ++ AbstractUnixSocket) -> +- "abstract-sendto:" ++ AbstractUnixSocket; +-socat_socket_arg(UnixSocket) -> +- "unix-sendto:" ++ UnixSocket. +- +-sd_open_port() -> +- open_port( +- {spawn_executable, os:find_executable("socat")}, +- [{args, [socat_socket_arg(os:getenv("NOTIFY_SOCKET")), "STDIO"]}, +- use_stdio, out]). +- +-sd_notify_socat(Unit) -> +- case sd_open_port() of +- {'EXIT', Exit} -> +- io:format(standard_error, "Failed to start socat ~p~n", [Exit]), +- false; +- Port -> +- Port ! {self(), {command, sd_notify_data()}}, +- Result = sd_wait_activation(Port, Unit), +- port_close(Port), +- Result +- end. +- +-sd_current_unit() -> +- case catch re:run(os:cmd("systemctl status " ++ os:getpid()), "([-.@0-9a-zA-Z]+)", [unicode, {capture, all_but_first, list}]) of +- {'EXIT', _} -> +- error; +- {match, [Unit]} -> +- {ok, Unit}; +- _ -> +- error +- end. +- +-sd_wait_activation(Port, Unit) -> +- case os:find_executable("systemctl") of +- false -> +- io:format(standard_error, "'systemctl' unavailable, falling back to sleep~n", []), +- timer:sleep(5000), +- true; +- _ -> +- sd_wait_activation(Port, Unit, 10) +- end. +- +-sd_wait_activation(_, _, 0) -> +- io:format(standard_error, "Service still in 'activating' state, bailing out~n", []), +- false; +-sd_wait_activation(Port, Unit, AttemptsLeft) -> +- case os:cmd("systemctl show --property=ActiveState " ++ Unit) of +- "ActiveState=activating\n" -> +- timer:sleep(1000), +- sd_wait_activation(Port, Unit, AttemptsLeft - 1); +- "ActiveState=" ++ _ -> +- true; +- _ = Err-> +- io:format(standard_error, "Unexpected status from systemd ~p~n", [Err]), +- false +- end. +- + start_it(StartFun) -> + Marker = spawn_link(fun() -> receive stop -> ok end end), + case catch register(rabbit_boot, Marker) of diff --git a/rabbitmq-server-0002-Add-systemd-notification-support.patch b/rabbitmq-server-0002-Add-systemd-notification-support.patch new file mode 100644 index 0000000..ee909d3 --- /dev/null +++ b/rabbitmq-server-0002-Add-systemd-notification-support.patch @@ -0,0 +1,21 @@ +From: John Eckersberg +Date: Wed, 18 Feb 2015 16:11:12 -0500 +Subject: [PATCH] Add systemd notification support + + +diff --git a/src/rabbit.erl b/src/rabbit.erl +index 8a19427..82e611c 100644 +--- a/src/rabbit.erl ++++ b/src/rabbit.erl +@@ -284,6 +284,11 @@ broker_start() -> + Plugins = rabbit_plugins:setup(), + ToBeLoaded = Plugins ++ ?APPS, + start_apps(ToBeLoaded), ++ case code:load_file(sd_notify) of ++ {module, sd_notify} -> SDNotify = sd_notify, ++ SDNotify:sd_notify(0, "READY=1\nSTATUS=Initialized\nMAINPID=" ++ os:getpid() ++ "\n"); ++ {error, _} -> ok ++ end, + ok = log_broker_started(rabbit_plugins:active()). + + start_it(StartFun) -> diff --git a/rabbitmq-server.spec b/rabbitmq-server.spec index c4b2f97..be7158a 100644 --- a/rabbitmq-server.spec +++ b/rabbitmq-server.spec @@ -16,6 +16,8 @@ Source2: rabbitmq-script-wrapper # curl -O https://raw.githubusercontent.com/lemenkov/rabbitmq-server/cdfc661/packaging/RPMS/Fedora/rabbitmq-server.logrotate Source3: rabbitmq-server.logrotate Source5: rabbitmq-server.tmpfiles +Patch1: rabbitmq-server-0001-Remove-excessive-sd_notify-code.patch +Patch2: rabbitmq-server-0002-Add-systemd-notification-support.patch URL: http://www.rabbitmq.com/ BuildArch: noarch BuildRequires: erlang >= %{erlang_minver}, python-simplejson, xmlto, libxslt, python, zip @@ -48,6 +50,8 @@ scalable implementation of an AMQP broker. %prep %setup -q +%patch1 -p1 +%patch2 -p1 %build