Message ID | 20211122020804.535891-5-troglobit@gmail.com |
---|---|
State | Changes Requested |
Headers | show |
Series | package/inadyn: bump version, script refactor, etc. | expand |
Hello Joachim, On Mon, 22 Nov 2021 03:08:03 +0100 Joachim Wiberg <troglobit@gmail.com> wrote: > This patch is a complete rewrite of the start script, reducing code > duplication by using a helper cmd() function and adding support for: > > - INADYN_ARGS that can be overridden from /etc/default/inadyn > - reload command that sends SIGHUP > > Signed-off-by: Joachim Wiberg <troglobit@gmail.com> Actually, for init script, we are now trying to use a common style and construction for all, based on package/busybox/S01syslogd. We don't want each init script of each package to be its own creative work of art, but instead we prefer consistency. It would actually be good to document this in the Buildroot manual. Could you try to rework your init script according to package/busybox/S01syslogd ? Thanks! Thomas
Hi Thomas! On 12/4/21 11:15 PM, Thomas Petazzoni wrote: > On Mon, 22 Nov 2021 03:08:03 +0100 > Joachim Wiberg <troglobit@gmail.com> wrote: >> This patch is a complete rewrite of the start script, reducing code >> duplication by using a helper cmd() function and adding support for: >> [snip] > Actually, for init script, we are now trying to use a common style and > construction for all, based on package/busybox/S01syslogd. Ah, I was actually wondering about that, couldn't find any info on it though. > We don't want each init script of each package to be its own creative > work of art, but instead we prefer consistency. Understandable. That's good policy actually. > It would actually be good to document this in the Buildroot manual. I'll see if I can whip something up :) > Could you try to rework your init script according to > package/busybox/S01syslogd ? Sure, no problem! Best regards /Joachim
diff --git a/package/inadyn/S70inadyn b/package/inadyn/S70inadyn old mode 100644 new mode 100755 index ca7b414678..1eab33b5fc --- a/package/inadyn/S70inadyn +++ b/package/inadyn/S70inadyn @@ -1,44 +1,57 @@ #!/bin/sh # -# Start & stop the inadyn client -# +# Note: must be explicitly enabled by adding ENABLED="yes" +# to /etc/default/inadyn, which also can be used to +# override the default INADYN_ARGS -CONFIG=/etc/inadyn.conf +NAME="inadyn" +INADYN_ARGS="-s" +PIDFILE="/var/run/$NAME.pid" -# check if CONFIG exists, print message & exit if it doesn't -[ ! -f $CONFIG ] && ( echo "The config file "$CONFIG" is missing...exiting now." && exit 2 ) +# shellcheck source=/dev/null +[ -r "/etc/default/$NAME" ] && . "/etc/default/$NAME" -# Allow a few customizations from a config file. Especially inadyn -# must be explicitly enabled by adding ENABLED="yes" in this file. -test -r /etc/default/inadyn && . /etc/default/inadyn +cmd() +{ + if [ "$ENABLED" != "yes" ]; then + echo "SKIPPED" + exit 0 + fi + start-stop-daemon -q -p "$PIDFILE" -x "/usr/sbin/$NAME" "$@" + status=$? + if [ $status -eq 0 ]; then + echo "OK" + else + echo "FAIL" + fi + return $status +} case "$1" in - start) - printf "Starting inadyn: " - if test "${ENABLED}" != "yes" ; then - echo "SKIPPED" - exit 0 - fi - start-stop-daemon -b -q -S -p /var/run/inadyn.pid -x /usr/sbin/inadyn - [ $? = 0 ] && echo "OK" || echo "FAIL" - ;; - stop) - printf "Stopping inadyn: " - if test "${ENABLED}" != "yes" ; then - echo "SKIPPED" - exit 0 - fi - start-stop-daemon -q -K -p /var/run/inadyn.pid -x /usr/sbin/inadyn - [ $? = 0 ] && echo "OK" || echo "FAIL" - rm -f /var/run/inadyn.pid - ;; - restart) - "$0" stop - "$0" start - ;; - *) - echo "Usage: $0 {start|stop|restart}" - exit 1 -esac + start) + printf 'Starting %s: ' "$NAME" + # shellcheck disable=SC2086 # we need the word splitting + cmd -S -- $INADYN_ARGS + ;; + + stop) + printf 'Stopping %s: ' "$NAME" + cmd -K + rm -f "$PIDFILE" + ;; -exit $? + restart) + $0 stop + sleep 1 + $0 start + ;; + + reload) + printf 'Reloading %s: ' "$NAME" + cmd -K -s HUP + ;; + + *) + echo "Usage: $0 {start|stop|restart|reload}" + exit 1 +esac
This patch is a complete rewrite of the start script, reducing code duplication by using a helper cmd() function and adding support for: - INADYN_ARGS that can be overridden from /etc/default/inadyn - reload command that sends SIGHUP Signed-off-by: Joachim Wiberg <troglobit@gmail.com> --- package/inadyn/S70inadyn | 85 +++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 36 deletions(-) mode change 100644 => 100755 package/inadyn/S70inadyn