From e38f6a1fe67efb031c325ea87f11c0bccd09453f Mon Sep 17 00:00:00 2001 From: f Date: Sat, 4 Jun 2022 16:48:38 -0300 Subject: [PATCH 1/5] syslogize a wrapper for sending output to syslog when the program doesn't support it. if adds syslogging support to daemonize as well. --- syslogize.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 syslogize.sh diff --git a/syslogize.sh b/syslogize.sh new file mode 100755 index 0000000..97060ff --- /dev/null +++ b/syslogize.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# A wrapper for programs that can't write to syslog. Output and error +# are sent to syslog. +# +# Use LOGGER environment variable to pass options to `logger`. They'll +# probably be system-dependent, so handle with care. +# +# Usage: +# +# LOGGER="-t program" syslogize program -o -p --tions argu ments +# +# daemonize syslogize program + +if test $# -eq 0 ; then + grep "^#" $0 | grep -v /bin/sh | sed -re "s/^#\s*//" >&2 + + exit 1 +fi + +$@ 2>&1 | logger ${LOGGER} From 9f2673b4e19aa7cf11fad6021f009376f77ff968 Mon Sep 17 00:00:00 2001 From: f Date: Sat, 4 Jun 2022 16:53:04 -0300 Subject: [PATCH 2/5] daemonize requires the full path --- syslogize.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syslogize.sh b/syslogize.sh index 97060ff..074c29f 100755 --- a/syslogize.sh +++ b/syslogize.sh @@ -9,7 +9,7 @@ # # LOGGER="-t program" syslogize program -o -p --tions argu ments # -# daemonize syslogize program +# daemonize /usr/local/bin/syslogize program if test $# -eq 0 ; then grep "^#" $0 | grep -v /bin/sh | sed -re "s/^#\s*//" >&2 From 94583cdcca610d73f979c5b5812b772fbabcf6b1 Mon Sep 17 00:00:00 2001 From: f Date: Sat, 4 Jun 2022 16:53:38 -0300 Subject: [PATCH 3/5] add to container --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index dbcab97..138b508 100644 --- a/Dockerfile +++ b/Dockerfile @@ -34,6 +34,7 @@ RUN install -dm 2750 -o root -g root /var/lib/monit COPY --from=build /etc/monitrc /etc/monitrc COPY ./nsupdate.sh /usr/local/bin/nsupdate COPY ./whatsmyip6.sh /usr/local/bin/whatsmyip6 +COPY ./syslogize.sh /usr/local/bin/syslogize COPY ./zeroconf.sh /usr/local/bin/zeroconf COPY ./zeroconf.conf /etc/zeroconf.conf From af44e95be9f717df60458206dba51a369f10883d Mon Sep 17 00:00:00 2001 From: f Date: Sat, 4 Jun 2022 17:38:44 -0300 Subject: [PATCH 4/5] propagate signals send signals received by syslogize to the wrapped program. this way we can treat syslogize as we treated the program itself. --- syslogize.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/syslogize.sh b/syslogize.sh index 074c29f..21f28fe 100755 --- a/syslogize.sh +++ b/syslogize.sh @@ -17,4 +17,15 @@ if test $# -eq 0 ; then exit 1 fi -$@ 2>&1 | logger ${LOGGER} +propagate_signal () { + logger ${LOGGER} "Received $1 signal" + jobs -p | xargs kill -$1 +} + +for signal in HUP INT QUIT USR1 USR2 TERM; do + trap "propagate_signal ${signal}" ${signal} +done + +$@ 2>&1 | logger ${LOGGER} & + +wait $! From 75df2530e34fa47cc3ca7141ade909e9082eb030 Mon Sep 17 00:00:00 2001 From: f Date: Sat, 4 Jun 2022 17:40:00 -0300 Subject: [PATCH 5/5] tag with the program name by default --- syslogize.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/syslogize.sh b/syslogize.sh index 21f28fe..aa4cfdf 100755 --- a/syslogize.sh +++ b/syslogize.sh @@ -17,6 +17,8 @@ if test $# -eq 0 ; then exit 1 fi +LOGGER="${LOGGER:--t $1}" + propagate_signal () { logger ${LOGGER} "Received $1 signal" jobs -p | xargs kill -$1