From 146c1e2c5d12f478e4dbf35c5a675f05a793f5b7 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Wed, 6 Oct 2021 14:44:19 -0400 Subject: [PATCH] 16347: Skip journald logging if systemd-cat is not installed. Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- lib/crunchrun/background.go | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/crunchrun/background.go b/lib/crunchrun/background.go index 07f8f5b885..8a919bc5e2 100644 --- a/lib/crunchrun/background.go +++ b/lib/crunchrun/background.go @@ -77,20 +77,24 @@ func detach(uuid string, prog string, args []string, stdin io.Reader, stdout io. // invoked as "/path/to/crunch-run" execargs = append([]string{prog}, execargs...) } - execargs = append([]string{ - // Here, if the inner systemd-cat can't exec - // crunch-run, it writes an error message to stderr, - // and the outer systemd-cat writes it to the journal - // where the operator has a chance to discover it. (If - // we only used one systemd-cat command, it would be - // up to us to report the error -- but we are going to - // detach and exit, not wait for something to appear - // on stderr.) Note these systemd-cat calls don't - // result in additional processes -- they just connect - // stderr/stdout to sockets and call exec(). - "systemd-cat", "--identifier=crunch-run", - "systemd-cat", "--identifier=crunch-run", - }, execargs...) + if _, err := exec.LookPath("systemd-cat"); err == nil { + execargs = append([]string{ + // Here, if the inner systemd-cat can't exec + // crunch-run, it writes an error message to + // stderr, and the outer systemd-cat writes it + // to the journal where the operator has a + // chance to discover it. (If we only used one + // systemd-cat command, it would be up to us + // to report the error -- but we are going to + // detach and exit, not wait for something to + // appear on stderr.) Note these systemd-cat + // calls don't result in additional processes + // -- they just connect stderr/stdout to + // sockets and call exec(). + "systemd-cat", "--identifier=crunch-run", + "systemd-cat", "--identifier=crunch-run", + }, execargs...) + } cmd := exec.Command(execargs[0], execargs[1:]...) // Child inherits lockfile. -- 2.39.5