All of lore.kernel.org
 help / color / mirror / Atom feed
From: Carlos Santos <casantos@datacom.com.br>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH v2 5/8] sysklogd: update S01logging
Date: Fri, 28 Sep 2018 23:50:03 -0300	[thread overview]
Message-ID: <20180929025006.8296-5-casantos@datacom.com.br> (raw)
In-Reply-To: <20180929025006.8296-1-casantos@datacom.com.br>

Reformat and fix syslogd/klogd startup script for better quality and
code style:

- Implement start, stop, restart and reload as functions, like in other
  S01logging scripts, using start-stop-daemon.
- Indent with tabs, not spaces.
- Detect and report start/stop errors (previous version ignored them and
  always reported OK).
- Support a configuration file at /etc/default (an example file will be
  added in forthcomming patch).
- Support a configuration variable that completely disables the service
  and issues a warning message on any invocation.
- Do not kill syslogd in "reload". Send a SIGHUP signal, instructing it
  to perform a re-initialization. Also do not kill klogd. Send a signal
  (default 0, which does nothing). Users can configure this signal in
  /etc/default/logging to either SIGUSR1 or SIGUSR2.

Signed-off-by: Carlos Santos <casantos@datacom.com.br>
---
Changes v1->v2
- Implement suggestions made by Arnout Vandecappelle
---
 package/sysklogd/S01logging | 90 ++++++++++++++++++++++++++++---------
 1 file changed, 70 insertions(+), 20 deletions(-)

diff --git a/package/sysklogd/S01logging b/package/sysklogd/S01logging
index 1cbfe869fa..44af1f9f41 100644
--- a/package/sysklogd/S01logging
+++ b/package/sysklogd/S01logging
@@ -1,25 +1,75 @@
 #!/bin/sh
 
-case "$1" in
-	start)
-		printf "Starting logging: "
-		/sbin/syslogd -m 0
-		/sbin/klogd
+DAEMON="sysklogd"
+SPIDFILE="/var/run/syslogd.pid"
+KPIDFILE="/var/run/klogd.pid"
+
+SYSLOGD_ARGS="-m 0"
+KLOGD_ARGS=""
+KLOGD_RELOAD="0"
+ENABLED="yes"
+
+# shellcheck source=/dev/null
+[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON"
+
+if [ "$ENABLED" != "yes" ]; then
+	printf '%s is disabled\n' "$DAEMON"
+	exit 0
+fi
+
+start() {
+	printf 'Starting %s: ' "$DAEMON"
+	status=0
+	# shellcheck disable=SC2086 # we need the word splitting
+	start-stop-daemon -S -q -p "$SPIDFILE" -x /sbin/syslogd -- $SYSLOGD_ARGS || status=$?
+	start-stop-daemon -S -q -p "$KPIDFILE" -x /sbin/klogd -- $KLOGD_ARGS || status=$?
+	if [ "$status" -eq 0 ]; then
+		echo "OK"
+	else
+		echo "FAIL"
+	fi
+	return "$status"
+}
+
+stop() {
+	printf 'Stopping %s: ' "$DAEMON"
+	status=0
+	start-stop-daemon -K -q -p "$SPIDFILE" || status=$?
+	start-stop-daemon -K -q -p "$KPIDFILE" || status=$?
+	if [ "$status" -eq 0 ]; then
 		echo "OK"
-		;;
-	stop)
-		printf "Stopping logging: "
-		[ -f /var/run/klogd.pid ] && kill `cat /var/run/klogd.pid`
-		[ -f /var/run/syslogd.pid ] && kill `cat /var/run/syslogd.pid`
+	else
+		echo "FAIL"
+	fi
+	return "$status"
+}
+
+restart() {
+	stop
+	sleep 1
+	start
+}
+
+# SIGHUP makes syslogd reload its configuration
+# SIGUSR1 makes klogd reload kernel module symbols
+# SIGUSR2 makes klogd reload static kernel symbols and kernel module symbols
+reload() {
+	printf 'Reloading %s: ' "$DAEMON"
+	status=0
+	start-stop-daemon -K -s HUP -q -p "$SPIDFILE" || status=$?
+	start-stop-daemon -K -s "$KLOGD_RELOAD" -q -p "$KPIDFILE" || status=$?
+	if [ "$status" -eq 0 ]; then
 		echo "OK"
-		;;
-	restart|reload)
-		$0 stop
-		$0 start
-		;;
-	*)
-		echo "Usage: $0 {start|stop|restart}"
-		exit 1
-esac
+	else
+		echo "FAIL"
+	fi
+	return "$status"
+}
 
-exit $?
+case "$1" in
+        start|stop|restart|reload)
+                "$1";;
+        *)
+                echo "Usage: $0 {start|stop|restart|reload}"
+                exit 1
+esac
-- 
2.17.1

  parent reply	other threads:[~2018-09-29  2:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-29  2:49 [Buildroot] [PATCH v2 1/8] busybox: update S01logging Carlos Santos
2018-09-29  2:50 ` [Buildroot] [PATCH v2 2/8] busybox: add logging configuration file Carlos Santos
2018-10-01 13:12   ` Matthew Weber
2018-09-29  2:50 ` [Buildroot] [PATCH v2 3/8] rsyslog: update S01logging Carlos Santos
2018-09-29  2:50 ` [Buildroot] [PATCH v2 4/8] rsyslog: add logging configuration file Carlos Santos
2018-09-29  2:50 ` Carlos Santos [this message]
2018-09-29  2:50 ` [Buildroot] [PATCH v2 6/8] sysklogd: " Carlos Santos
2018-09-29  2:50 ` [Buildroot] [PATCH v2 7/8] syslog-ng: update S01logging Carlos Santos
2018-09-29  3:11   ` Chris Packham
2018-09-29  2:50 ` [Buildroot] [PATCH v2 8/8] syslog-ng: add logging configuration file Carlos Santos
2018-09-29  3:14   ` Chris Packham
2018-10-01 13:00 ` [Buildroot] [PATCH v2 1/8] busybox: update S01logging Matthew Weber

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180929025006.8296-5-casantos@datacom.com.br \
    --to=casantos@datacom.com.br \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.