mirror of
https://git.busybox.net/buildroot.git
synced 2025-01-27 14:54:07 +08:00
sysklogd: rewrite init script
- Split it into S01syslogd and S02klogd to make every init script be called the same as the executable it starts. - Implement start, stop, restart and reload as functions, like in other init 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 /etc/default/$DAEMON configuration files. - Do not kill syslogd in "reload". Send a SIGHUP signal, instructing it to perform a re-initialization. - Do not kill klogd in "reload". Send a signal (default 0, which does nothing). Users can configure this signal in /etc/default/klogd to either SIGUSR1 or SIGUSR2. Signed-off-by: Carlos Santos <casantos@datacom.com.br> Reviewed-by: Matt Weber <matthew.weber@rockwellcollins.com> Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
This commit is contained in:
parent
5e5c2e2194
commit
b3c76a435b
@ -1,25 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
printf "Starting logging: "
|
||||
/sbin/syslogd -m 0
|
||||
/sbin/klogd
|
||||
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`
|
||||
echo "OK"
|
||||
;;
|
||||
restart|reload)
|
||||
$0 stop
|
||||
$0 start
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart}"
|
||||
exit 1
|
||||
esac
|
||||
|
||||
exit $?
|
62
package/sysklogd/S01syslogd
Normal file
62
package/sysklogd/S01syslogd
Normal file
@ -0,0 +1,62 @@
|
||||
#!/bin/sh
|
||||
|
||||
DAEMON="syslogd"
|
||||
PIDFILE="/var/run/$DAEMON.pid"
|
||||
|
||||
SYSLOGD_ARGS="-m 0"
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON"
|
||||
|
||||
start() {
|
||||
printf 'Starting %s: ' "$DAEMON"
|
||||
# shellcheck disable=SC2086 # we need the word splitting
|
||||
start-stop-daemon -S -q -p "$PIDFILE" -x "/sbin/$DAEMON" \
|
||||
-- $SYSLOGD_ARGS
|
||||
status=$?
|
||||
if [ "$status" -eq 0 ]; then
|
||||
echo "OK"
|
||||
else
|
||||
echo "FAIL"
|
||||
fi
|
||||
return "$status"
|
||||
}
|
||||
|
||||
stop() {
|
||||
printf 'Stopping %s: ' "$DAEMON"
|
||||
start-stop-daemon -K -q -p "$PIDFILE"
|
||||
status=$?
|
||||
if [ "$status" -eq 0 ]; then
|
||||
echo "OK"
|
||||
else
|
||||
echo "FAIL"
|
||||
fi
|
||||
return "$status"
|
||||
}
|
||||
|
||||
restart() {
|
||||
stop
|
||||
sleep 1
|
||||
start
|
||||
}
|
||||
|
||||
# SIGHUP makes syslogd reload its configuration
|
||||
reload() {
|
||||
printf 'Reloading %s: ' "$DAEMON"
|
||||
start-stop-daemon -K -s HUP -q -p "$PIDFILE"
|
||||
status=$?
|
||||
if [ "$status" -eq 0 ]; then
|
||||
echo "OK"
|
||||
else
|
||||
echo "FAIL"
|
||||
fi
|
||||
return "$status"
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start|stop|restart|reload)
|
||||
"$1";;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart|reload}"
|
||||
exit 1
|
||||
esac
|
65
package/sysklogd/S02klogd
Normal file
65
package/sysklogd/S02klogd
Normal file
@ -0,0 +1,65 @@
|
||||
#!/bin/sh
|
||||
|
||||
DAEMON="klogd"
|
||||
PIDFILE="/var/run/$DAEMON.pid"
|
||||
|
||||
KLOGD_ARGS=""
|
||||
|
||||
KLOGD_RELOAD="0"
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON"
|
||||
|
||||
start() {
|
||||
printf 'Starting %s: ' "$DAEMON"
|
||||
# shellcheck disable=SC2086 # we need the word splitting
|
||||
start-stop-daemon -S -q -p "$PIDFILE" -x "/sbin/$DAEMON" \
|
||||
-- $KLOGD_ARGS
|
||||
status=$?
|
||||
if [ "$status" -eq 0 ]; then
|
||||
echo "OK"
|
||||
else
|
||||
echo "FAIL"
|
||||
fi
|
||||
return "$status"
|
||||
}
|
||||
|
||||
stop() {
|
||||
printf 'Stopping %s: ' "$DAEMON"
|
||||
start-stop-daemon -K -q -p "$PIDFILE"
|
||||
status=$?
|
||||
if [ "$status" -eq 0 ]; then
|
||||
echo "OK"
|
||||
else
|
||||
echo "FAIL"
|
||||
fi
|
||||
return "$status"
|
||||
}
|
||||
|
||||
restart() {
|
||||
stop
|
||||
sleep 1
|
||||
start
|
||||
}
|
||||
|
||||
# SIGUSR1 makes klogd reload kernel module symbols
|
||||
# SIGUSR2 makes klogd reload static kernel symbols and kernel module symbols
|
||||
reload() {
|
||||
printf 'Reloading %s: ' "$DAEMON"
|
||||
start-stop-daemon -K -s "$KLOGD_RELOAD" -q -p "$PIDFILE"
|
||||
status=$?
|
||||
if [ "$status" -eq 0 ]; then
|
||||
echo "OK"
|
||||
else
|
||||
echo "FAIL"
|
||||
fi
|
||||
return "$status"
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start|stop|restart|reload)
|
||||
"$1";;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart|reload}"
|
||||
exit 1
|
||||
esac
|
@ -23,8 +23,10 @@ define SYSKLOGD_INSTALL_TARGET_CMDS
|
||||
endef
|
||||
|
||||
define SYSKLOGD_INSTALL_INIT_SYSV
|
||||
$(INSTALL) -m 755 -D package/sysklogd/S01logging \
|
||||
$(TARGET_DIR)/etc/init.d/S01logging
|
||||
$(INSTALL) -m 755 -D package/sysklogd/S01syslogd \
|
||||
$(TARGET_DIR)/etc/init.d/S01syslogd
|
||||
$(INSTALL) -m 755 -D package/sysklogd/S02klogd \
|
||||
$(TARGET_DIR)/etc/init.d/S02klogd
|
||||
endef
|
||||
|
||||
define SYSKLOGD_INSTALL_INIT_SYSTEMD
|
||||
|
Loading…
Reference in New Issue
Block a user