[ptxdist] [PATCH 1/2] mtd-utils: Introduce bbinit startup for ubihealthd

2023-06-12 Thread Alexander Dahl
We already introduced a systemd service unit with 434bd8a2cee9
("mtd-utils: Introduce systemd unit for ubihealthd"), but it was not
possible before to start the ubihealthd on bbinit based systems.  This
new init script does not allow to run multiple instances however and
just starts one daemon for the default ubi device.

The script is inspired and adapted from the one used for haveged.

Signed-off-by: Alexander Dahl 
---
 projectroot/etc/init.d/ubihealthd | 111 ++
 rules/mtd-utils-bbinit.in |   9 +++
 rules/mtd-utils.in|   5 ++
 rules/mtd-utils.make  |   8 +++
 4 files changed, 133 insertions(+)
 create mode 100755 projectroot/etc/init.d/ubihealthd
 create mode 100644 rules/mtd-utils-bbinit.in

diff --git a/projectroot/etc/init.d/ubihealthd 
b/projectroot/etc/init.d/ubihealthd
new file mode 100755
index 0..62608cdff
--- /dev/null
+++ b/projectroot/etc/init.d/ubihealthd
@@ -0,0 +1,111 @@
+#!/bin/sh
+
+PATH='/usr/sbin:/usr/bin'
+DESC='ubihealthd UBI device PEB scan daemon'
+NAME='ubihealthd'
+DAEMON="/usr/sbin/$NAME"
+DAEMON_ARGS=''
+SCRIPTNAME="/etc/init.d/$NAME"
+
+# exit if binary is missing
+[ -x "$DAEMON" ] || exit 0
+
+is_running() {
+start-stop-daemon -K --quiet --test --exec $DAEMON
+}
+
+do_start() {
+is_running && return 1
+start-stop-daemon -S --quiet --exec $DAEMON -- $DAEMON_ARGS || return 2
+}
+
+do_stop() {
+is_running || return 0
+start-stop-daemon -K --quiet --exec $DAEMON
+RETVAL="$?"
+
+# wait up to 30 seconds until daemon stopped
+for i in $(seq 30)
+do
+sleep 1
+echo -n '.'
+if ! is_running
+then
+break
+fi
+done
+
+# see if it's still running
+if is_running
+then
+start-stop-daemon -K --quiet --signal KILL --exec $DAEMON
+
+for i in $(seq 5)
+do
+sleep 1
+echo -n '.'
+if ! is_running
+then
+break
+fi
+done
+
+if is_running
+then
+return 2
+fi
+fi
+
+rm -f $PIDFILE
+return "$RETVAL"
+}
+
+case "$1" in
+start)
+echo -n "Starting $DESC ..."
+do_start
+case "$?" in
+0|1)echo " Done." ;;
+2)  echo " Failed." ;;
+esac
+;;
+stop)
+echo -n "Stopping $DESC ."
+do_stop
+case "$?" in
+0|1)echo " Done." ;;
+2)  echo " Failed." ;;
+esac
+;;
+restart)
+echo -n "Restarting $DESC .."
+do_stop
+case "$?" in
+0|1)
+do_start
+case "$?" in
+0)  echo " Done." ;;
+1)  echo " Failed." ;; # Old process still running
+*)  echo " Failed." ;; # Failed to start
+esac
+;;
+*)
+echo " Failed." # Failed to stop
+;;
+esac
+;;
+status)
+if is_running
+then
+echo "$NAME is running"
+else
+echo "$NAME is not running"
+fi
+;;
+*)
+echo "Usage: $SCRIPTNAME {start|stop|restart|status}" >&2
+exit 3
+;;
+esac
+
+:
diff --git a/rules/mtd-utils-bbinit.in b/rules/mtd-utils-bbinit.in
new file mode 100644
index 0..e6b628938
--- /dev/null
+++ b/rules/mtd-utils-bbinit.in
@@ -0,0 +1,9 @@
+## SECTION=initmethod_bbinit
+
+config MTD_UTILS_UBIHEALTHD_BBINIT_LINK
+   string
+   depends on MTD_UTILS_UBIHEALTHD_STARTSCRIPT
+   prompt "ubihealthd"
+   default "S83ubihealthd"
+
+# vim: ft=kconfig noet tw=72
diff --git a/rules/mtd-utils.in b/rules/mtd-utils.in
index eaf073932..434d1e8fb 100644
--- a/rules/mtd-utils.in
+++ b/rules/mtd-utils.in
@@ -303,6 +303,11 @@ menuconfig MTD_UTILS_UBIHEALTHD
 
 if MTD_UTILS_UBIHEALTHD
 
+config MTD_UTILS_UBIHEALTHD_STARTSCRIPT
+   bool
+   prompt "install /etc/init.d/ubihealthd"
+   depends on INITMETHOD_BBINIT
+
 config MTD_UTILS_UBIHEALTHD_SYSTEMD_UNIT
bool
prompt "install systemd unit files"
diff --git a/rules/mtd-utils.make b/rules/mtd-utils.make
index 0a181a879..659a0385b 100644
--- a/rules/mtd-utils.make
+++ b/rules/mtd-utils.make
@@ -205,6 +205,14 @@ endif
 ifdef PTXCONF_MTD_UTILS_UBIHEALTHD
@$(call install_copy, mtd-utils, 0, 0, 0755, -, \
/usr/sbin/ubihealthd)
+ifdef PTXCONF_MTD_UTILS_UBIHEALTHD_STARTSCRIPT
+   @$(call install_alternative, mtd-utils, 0, 0, 0755, \
+   /etc/init.d/ubihealthd)
+ifneq ($(call remove_quotes,$(PTXCONF_MTD_UTILS_UBIHEALTHD_BBINIT_LINK)),)
+   @$(call install_link, mtd-utils, ../init.d/ubihealthd, \
+   /etc/rc.d/$(PTXCONF_MTD_UTILS_UBIHEALTHD_BBINIT_LINK))
+endif
+endif
 ifdef PTXCONF_MTD_UTILS_UBIHEALTHD_SYSTEMD_UNIT
@$(call install_alternative, mtd-utils, 0, 0, 

[ptxdist] [PATCH 0/2] mtd-utils: ubihealthd: Init script and help text

2023-06-12 Thread Alexander Dahl
Hei hei,

just made our targets using bbinit work with ubihealthd.  (We already
had support for systemd for other targets.)  While at it, I found the
help text is missing some requirements which can not easily be expressed
through Kconfig.

Greets
Alex

Alexander Dahl (2):
  mtd-utils: Introduce bbinit startup for ubihealthd
  mtd-utils: Add ubihealthd requirements to help text

 projectroot/etc/init.d/ubihealthd | 111 ++
 rules/mtd-utils-bbinit.in |   9 +++
 rules/mtd-utils.in|   6 ++
 rules/mtd-utils.make  |   8 +++
 4 files changed, 134 insertions(+)
 create mode 100755 projectroot/etc/init.d/ubihealthd
 create mode 100644 rules/mtd-utils-bbinit.in


base-commit: 900bff9908170aad8a9b61b3e2c14b4734817d62
-- 
2.30.2




[ptxdist] [PATCH 2/2] mtd-utils: Add ubihealthd requirements to help text

2023-06-12 Thread Alexander Dahl
Fixes: 7d4e5f3969df ("mtd-utils: version bump 2.1.1 -> 2.1.2")
Signed-off-by: Alexander Dahl 
---
 rules/mtd-utils.in | 1 +
 1 file changed, 1 insertion(+)

diff --git a/rules/mtd-utils.in b/rules/mtd-utils.in
index 434d1e8fb..8cc55caba 100644
--- a/rules/mtd-utils.in
+++ b/rules/mtd-utils.in
@@ -300,6 +300,7 @@ menuconfig MTD_UTILS_UBIHEALTHD
help
  Daemon that randomly scans each PEB of a UBI device to ensure that
  filesystems with little reading do enough wear leveling.
+ Requires kernel >= 5.1 and glibc >= 2.25.
 
 if MTD_UTILS_UBIHEALTHD
 
-- 
2.30.2