From 0715e8f45e7e58b5f02b9d9cddd852d29861de14 Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Fri, 2 Feb 2018 13:00:51 -0800 Subject: [PATCH] Find systemd unit via ps Also terminate systemctl args with `--` in case the unit name starts with a dash Fixes #1187 --- src/rabbit.erl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/rabbit.erl b/src/rabbit.erl index 745ba4631d90..37b33bd8a466 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -401,7 +401,8 @@ sd_notify_socat(Unit) -> 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 + CmdOut = os:cmd("ps -o unit= -p " ++ os:getpid()), + case catch re:run(CmdOut, "([-.@0-9a-zA-Z]+)", [unicode, {capture, all_but_first, list}]) of {'EXIT', _} -> error; {match, [Unit]} -> @@ -424,7 +425,7 @@ 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 + case os:cmd("systemctl show --property=ActiveState -- '" ++ Unit ++ "'") of "ActiveState=activating\n" -> timer:sleep(1000), sd_wait_activation(Port, Unit, AttemptsLeft - 1);