From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Mon, 12 Jun 2023 08:41:03 +0200 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by lore.white.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1q8bEe-003VOt-Qa for lore@lore.pengutronix.de; Mon, 12 Jun 2023 08:41:03 +0200 Received: from localhost ([127.0.0.1] helo=metis.ext.pengutronix.de) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1q8bEc-0004mq-Qo; Mon, 12 Jun 2023 08:41:02 +0200 Received: from mail.thorsis.com ([92.198.35.195]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q8bDo-0004MA-Ng for ptxdist@pengutronix.de; Mon, 12 Jun 2023 08:40:13 +0200 Received: from adahl by ada.ifak-system.com with local (Exim 4.94.2) (envelope-from ) id 1q8bCT-00055I-B9 for ptxdist@pengutronix.de; Mon, 12 Jun 2023 08:38:49 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thorsis.com; s=default; t=1686552011; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XGOdIMKztzfJUiLTaN+yFgvRzBMR81Hs0OMV/zlgxag=; b=vFC9Cs/Ci6wGcZAfGrPbcWqswDBqgjtG9DO4hX7XCdnZqED22op7Q01fb4FOYppuBzbHFL 0Tfr1UfOURt6r1HPI8N4dIxhBF+jxE9PpZybByFei0ZsctnnIzQPos9OHDfImWfBKyy9EK BPeCKBVCuEEbuHRuDCQSCUQWSbsVRICOFMI1cf9OQFAZH2gwefurwWaCqmkIMoMMSgff0N U9Kx602EVxcwlPEjZqPav7+PD5JcLtsVjJ9w6LUB5FmTajkeO4lMbpq9wkwT3bKX3zsPLH 5RAlFJn/qKpHtXEO/D/ZZyTZSGa3vGRsXhIpe3ke+7KPLadLrSecAKV1IJSaCA== From: Alexander Dahl To: ptxdist@pengutronix.de Date: Mon, 12 Jun 2023 08:38:48 +0200 Message-Id: <20230612063849.19499-2-ada@thorsis.com> In-Reply-To: <20230612063849.19499-1-ada@thorsis.com> References: <20230612063849.19499-1-ada@thorsis.com> Content-Transfer-Encoding: 8bit X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on metis.ext.pengutronix.de X-Spam-Level: X-Spam-Status: No, score=-2.8 required=4.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Subject: [ptxdist] [PATCH 1/2] mtd-utils: Introduce bbinit startup for ubihealthd X-BeenThere: ptxdist@pengutronix.de X-Mailman-Version: 2.1.29 Precedence: list List-Id: PTXdist Development Mailing List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: ptxdist@pengutronix.de Sender: "ptxdist" X-SA-Exim-Connect-IP: 127.0.0.1 X-SA-Exim-Mail-From: ptxdist-bounces@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false 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 000000000..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 000000000..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, 0644, \ /usr/lib/systemd/system/ubihealthd@.service) -- 2.30.2