From 0041f26af3daa14588a645673f4591d7f3c20244 Mon Sep 17 00:00:00 2001 From: viktorxda <35473052+viktorxda@users.noreply.github.com> Date: Sun, 31 Mar 2024 23:38:59 +0200 Subject: [PATCH] Overlay: sync init.d script structure (#1369) --- general/overlay/etc/init.d/S01syslogd | 18 +++------- general/overlay/etc/init.d/S21rngd | 29 +++++++++------- .../etc/init.d/{S10modules => S35modules} | 2 +- general/overlay/etc/init.d/S40network | 2 -- general/overlay/etc/init.d/S49ntpd | 20 +++-------- general/overlay/etc/init.d/S50dropbear | 33 ++++++++++--------- general/overlay/etc/init.d/S60crond | 20 +++-------- .../etc/init.d/{S94rc.local => S99rc.local} | 0 general/overlay/etc/init.d/rcK | 23 +++++++++++++ general/overlay/etc/init.d/rcS | 5 ++- general/overlay/usr/sbin/sysupgrade | 1 + general/package/majestic/files/S95majestic | 12 +++---- 12 files changed, 81 insertions(+), 84 deletions(-) rename general/overlay/etc/init.d/{S10modules => S35modules} (89%) rename general/overlay/etc/init.d/{S94rc.local => S99rc.local} (100%) create mode 100755 general/overlay/etc/init.d/rcK diff --git a/general/overlay/etc/init.d/S01syslogd b/general/overlay/etc/init.d/S01syslogd index cea35a57..d0c472f1 100755 --- a/general/overlay/etc/init.d/S01syslogd +++ b/general/overlay/etc/init.d/S01syslogd @@ -4,35 +4,25 @@ DAEMON="syslogd" PIDFILE="/var/run/$DAEMON.pid" SYSLOGD_ARGS="-C64 -t" -# shellcheck source=/dev/null -[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON" - -# BusyBox' syslogd does not create a pidfile, so pass "-n" in the command line -# and use "-m" to instruct start-stop-daemon to create one. start() { - printf 'Starting %s: ' "$DAEMON" - # shellcheck disable=SC2086 # we need the word splitting + printf "Starting $DAEMON: " start-stop-daemon -b -m -S -q -p "$PIDFILE" -x "/sbin/$DAEMON" -- -n $SYSLOGD_ARGS - status=$? - if [ "$status" -eq 0 ]; then + if [ $? = 0 ]; then echo "OK" else echo "FAIL" fi - return "$status" } stop() { - printf 'Stopping %s: ' "$DAEMON" + printf "Stopping $DAEMON: " start-stop-daemon -K -q -p "$PIDFILE" - status=$? - if [ "$status" -eq 0 ]; then + if [ $? = 0 ]; then rm -f "$PIDFILE" echo "OK" else echo "FAIL" fi - return "$status" } case "$1" in diff --git a/general/overlay/etc/init.d/S21rngd b/general/overlay/etc/init.d/S21rngd index 6f701da7..02d1f515 100755 --- a/general/overlay/etc/init.d/S21rngd +++ b/general/overlay/etc/init.d/S21rngd @@ -1,21 +1,27 @@ #!/bin/sh DAEMON="rngd" -DAEMON_ARGS="-r /dev/urandom" -PID_FILE="/var/run/$DAEMON.pid" +PIDFILE="/var/run/$DAEMON.pid" +RNGD_ARGS="-r /dev/urandom" start() { - echo "Starting $DAEMON..." - start-stop-daemon -S -q -x "/usr/sbin/$DAEMON" -- $DAEMON_ARGS + printf "Starting $DAEMON: " + start-stop-daemon -S -q -x "/usr/sbin/$DAEMON" -- $RNGD_ARGS + if [ $? = 0 ]; then + echo "OK" + else + echo "FAIL" + fi } stop() { - echo "Stopping $DAEMON..." - # This daemon does not exit properly with the default TERM signal unless - # it's forced to work by something reading /dev/random. Killing it and - # removing its PID file is more straightforward. - start-stop-daemon -K -q -s KILL -p "$PID_FILE" -n "$DAEMON" - rm -f "$PID_FILE" + printf "Stopping $DAEMON: " + start-stop-daemon -K -q -n "$DAEMON" + if [ $? = 0 ]; then + echo "OK" + else + echo "FAIL" + fi } case "$1" in @@ -25,11 +31,12 @@ case "$1" in restart|reload) stop + sleep 1 start ;; *) - echo "Usage: $0 {start|stop|restart|reload}" >&2 + echo "Usage: $0 {start|stop|restart|reload}" exit 1 ;; esac diff --git a/general/overlay/etc/init.d/S10modules b/general/overlay/etc/init.d/S35modules similarity index 89% rename from general/overlay/etc/init.d/S10modules rename to general/overlay/etc/init.d/S35modules index 7fb03528..47ae9d8c 100755 --- a/general/overlay/etc/init.d/S10modules +++ b/general/overlay/etc/init.d/S35modules @@ -2,7 +2,7 @@ case "$1" in start) - echo "Loading kernel modules..." + echo "Loading modules..." # load modules from /etc/modules [ -r /etc/modules ] || exit 0 diff --git a/general/overlay/etc/init.d/S40network b/general/overlay/etc/init.d/S40network index 1da04b7c..44579a10 100755 --- a/general/overlay/etc/init.d/S40network +++ b/general/overlay/etc/init.d/S40network @@ -46,5 +46,3 @@ case "$1" in exit 1 ;; esac - -exit 0 diff --git a/general/overlay/etc/init.d/S49ntpd b/general/overlay/etc/init.d/S49ntpd index 0cba8499..186e84ce 100755 --- a/general/overlay/etc/init.d/S49ntpd +++ b/general/overlay/etc/init.d/S49ntpd @@ -4,35 +4,25 @@ DAEMON="ntpd" PIDFILE="/var/run/$DAEMON.pid" NTPD_ARGS="-n" -# shellcheck source=/dev/null -[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON" - -# BusyBox' ntpd does not create a pidfile, so pass "-n" in the command line -# and use "-m" to instruct start-stop-daemon to create one. start() { - printf 'Starting %s: ' "$DAEMON" - # shellcheck disable=SC2086 # we need the word splitting + printf "Starting $DAEMON: " start-stop-daemon -b -m -S -q -p "$PIDFILE" -x "/usr/sbin/$DAEMON" -- $NTPD_ARGS - status=$? - if [ "$status" -eq 0 ]; then + if [ $? = 0 ]; then echo "OK" else echo "FAIL" fi - return "$status" } stop() { - printf 'Stopping %s: ' "$DAEMON" + printf "Stopping $DAEMON: " start-stop-daemon -K -q -p "$PIDFILE" - status=$? - if [ "$status" -eq 0 ]; then + if [ $? = 0 ]; then rm -f "$PIDFILE" echo "OK" else echo "FAIL" fi - return "$status" } case "$1" in @@ -40,7 +30,7 @@ case "$1" in "$1" ;; - reload) + restart|reload) stop sleep 1 start diff --git a/general/overlay/etc/init.d/S50dropbear b/general/overlay/etc/init.d/S50dropbear index b3d9fb67..8da0769c 100755 --- a/general/overlay/etc/init.d/S50dropbear +++ b/general/overlay/etc/init.d/S50dropbear @@ -1,14 +1,10 @@ #!/bin/sh -# -# Starts dropbear sshd. -# -# Allow a few customizations from a config file -test -r /etc/default/dropbear && . /etc/default/dropbear +DAEMON="dropbear" +PIDFILE="/var/run/$DAEMON.pid" +DROPBEAR_ARGS="-R -B -k -p 22 -K 300" start() { - DROPBEAR_ARGS="$DROPBEAR_ARGS -R -B -k -p 22 -K 300" - # If /etc/dropbear is a symlink to /var/run/dropbear, and # - the filesystem is RO (i.e. we can not rm the symlink), # create the directory pointed to by the symlink. @@ -24,17 +20,25 @@ start() { fi fi - printf "Starting dropbear sshd: " + printf "Starting $DAEMON: " umask 077 - start-stop-daemon -S -q -p /var/run/dropbear.pid --exec /usr/sbin/dropbear -- $DROPBEAR_ARGS - [ $? = 0 ] && echo "OK" || echo "FAIL" + start-stop-daemon -S -q -p "$PIDFILE" -x "/usr/sbin/$DAEMON" -- $DROPBEAR_ARGS + if [ $? = 0 ]; then + echo "OK" + else + echo "FAIL" + fi } stop() { - printf "Stopping dropbear sshd: " - start-stop-daemon -K -q -p /var/run/dropbear.pid - [ $? = 0 ] && echo "OK" || echo "FAIL" + printf "Stopping $DAEMON: " + start-stop-daemon -K -q -p "$PIDFILE" + if [ $? = 0 ]; then + echo "OK" + else + echo "FAIL" + fi } case "$1" in @@ -44,6 +48,7 @@ case "$1" in restart|reload) stop + sleep 1 start ;; @@ -52,5 +57,3 @@ case "$1" in exit 1 ;; esac - -exit $? diff --git a/general/overlay/etc/init.d/S60crond b/general/overlay/etc/init.d/S60crond index 2a6e76fa..1f3a9850 100755 --- a/general/overlay/etc/init.d/S60crond +++ b/general/overlay/etc/init.d/S60crond @@ -4,37 +4,25 @@ DAEMON="crond" PIDFILE="/var/run/$DAEMON.pid" CROND_ARGS="-f -c /etc/crontabs" -# shellcheck source=/dev/null -[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON" - -# The mini-snmpd does not create a pidfile, so pass "-n" in the command line -# and use "-m" to instruct start-stop-daemon to create one. start() { - printf 'Starting %s: ' "$DAEMON" - [ -f /usr/sbin/$DAEMON ] || echo -en "DISABLED, " - # shellcheck disable=SC2086 # we need the word splitting + printf "Starting $DAEMON: " start-stop-daemon -b -m -S -q -p "$PIDFILE" -x "/usr/sbin/$DAEMON" -- $CROND_ARGS - status=$? - if [ "$status" -eq 0 ]; then + if [ $? = 0 ]; then echo "OK" else echo "FAIL" fi - return "$status" } stop() { - printf 'Stopping %s: ' "$DAEMON" - [ -f /usr/sbin/$DAEMON ] || echo -en "DISABLED, " + printf "Stopping $DAEMON: " start-stop-daemon -K -q -p "$PIDFILE" - status=$? - if [ "$status" -eq 0 ]; then + if [ $? = 0 ]; then rm -f "$PIDFILE" echo "OK" else echo "FAIL" fi - return "$status" } case "$1" in diff --git a/general/overlay/etc/init.d/S94rc.local b/general/overlay/etc/init.d/S99rc.local similarity index 100% rename from general/overlay/etc/init.d/S94rc.local rename to general/overlay/etc/init.d/S99rc.local diff --git a/general/overlay/etc/init.d/rcK b/general/overlay/etc/init.d/rcK new file mode 100755 index 00000000..47057217 --- /dev/null +++ b/general/overlay/etc/init.d/rcK @@ -0,0 +1,23 @@ +#!/bin/sh + +# Stop all init scripts in /etc/init.d executing them in reversed numerical order. +for i in $(ls -r /etc/init.d/S??*); do + # Ignore dangling symlinks (if any). + [ ! -f "$i" ] && continue + + case "$i" in + *.sh) + # Source shell script for speed. + ( + trap - INT QUIT TSTP + set stop + . $i + ) + ;; + + *) + # No sh extension, so fork subprocess. + $i stop + ;; + esac +done diff --git a/general/overlay/etc/init.d/rcS b/general/overlay/etc/init.d/rcS index 3b28ce57..b2c50e0d 100755 --- a/general/overlay/etc/init.d/rcS +++ b/general/overlay/etc/init.d/rcS @@ -7,8 +7,7 @@ export TZ=$(cat /etc/TZ) # Set the firmware creation time as the base system time /bin/date -s @$(stat -t /etc/os-release | cut -d" " -f12) -# Start all init scripts in /etc/init.d -# executing them in numerical order. +# Start all init scripts in /etc/init.d executing them in numerical order. for i in /etc/init.d/S??*; do # Ignore dangling symlinks (if any). [ ! -f "$i" ] && continue @@ -19,7 +18,7 @@ for i in /etc/init.d/S??*; do ( trap - INT QUIT TSTP set start - $i + . $i ) ;; diff --git a/general/overlay/usr/sbin/sysupgrade b/general/overlay/usr/sbin/sysupgrade index 0be9b77a..bd334478 100755 --- a/general/overlay/usr/sbin/sysupgrade +++ b/general/overlay/usr/sbin/sysupgrade @@ -108,6 +108,7 @@ free_resources() { fi /etc/init.d/S60crond stop /etc/init.d/S49ntpd stop + /etc/init.d/S21rngd stop /etc/init.d/S02klogd stop /etc/init.d/S01syslogd stop sleep 1 diff --git a/general/package/majestic/files/S95majestic b/general/package/majestic/files/S95majestic index 06629253..9e12bc48 100755 --- a/general/package/majestic/files/S95majestic +++ b/general/package/majestic/files/S95majestic @@ -2,7 +2,7 @@ DAEMON="majestic" PIDFILE="/var/run/$DAEMON.pid" -DAEMON_ARGS="-s" +MAJESTIC_ARGS="-s" debug_majestic() { [ -f /etc/coredump.conf ] && . /etc/coredump.conf @@ -13,9 +13,8 @@ debug_majestic() { load_majestic() { printf "Starting $DAEMON: " - start-stop-daemon -b -S -m -q -p "$PIDFILE" -x "/usr/bin/$DAEMON" -- $DAEMON_ARGS - status=$? - if [ "$status" -eq 0 ]; then + start-stop-daemon -b -S -m -q -p "$PIDFILE" -x "/usr/bin/$DAEMON" -- $MAJESTIC_ARGS + if [ $? = 0 ]; then echo "OK" else echo "FAIL" @@ -23,7 +22,7 @@ load_majestic() { } start() { - logger -s -p daemon.info -t $(ipcinfo -v) "Loading video system has started..." + logger -s -p daemon.info -t $(ipcinfo -v) "Loading video system..." export SENSOR=$(fw_printenv -n sensor) debug_majestic load_majestic @@ -32,8 +31,7 @@ start() { stop() { printf "Stopping $DAEMON: " start-stop-daemon -K -q -p "$PIDFILE" - status=$? - if [ "$status" -eq 0 ]; then + if [ $? = 0 ]; then rm -f "$PIDFILE" echo "OK" else