From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Wed, 21 Jun 2023 10:51:58 +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 1qBtZH-00FRzf-KP for lore@lore.pengutronix.de; Wed, 21 Jun 2023 10:51:58 +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 1qBtZF-0006qA-JW; Wed, 21 Jun 2023 10:51:57 +0200 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qBtYW-0006Bd-Di; Wed, 21 Jun 2023 10:51:12 +0200 Received: from [2a0a:edc0:0:1101:1d::54] (helo=dude05.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1qBtYV-008zZM-L1; Wed, 21 Jun 2023 10:51:11 +0200 Received: from mol by dude05.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1qBtYV-00AiMy-07; Wed, 21 Jun 2023 10:51:11 +0200 From: Michael Olbrich To: ptxdist@pengutronix.de Date: Wed, 21 Jun 2023 10:51:11 +0200 Message-Id: <20230621085111.2553829-1-m.olbrich@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230612063849.19499-2-ada@thorsis.com> References: <20230612063849.19499-2-ada@thorsis.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: Re: [ptxdist] [APPLIED] 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 Cc: Alexander Dahl 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 Thanks, applied as 7b9d64648a001346a99f45900707c107c2a24084. Michael [sent from post-receive hook] On Wed, 21 Jun 2023 10:51:10 +0200, Alexander Dahl wrote: > 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 > Message-Id: <20230612063849.19499-2-ada@thorsis.com> > Signed-off-by: Michael Olbrich > > diff --git a/projectroot/etc/init.d/ubihealthd b/projectroot/etc/init.d/ubihealthd > new file mode 100755 > index 000000000000..62608cdff282 > --- /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 000000000000..e6b628938863 > --- /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 eaf073932537..434d1e8fb99f 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 0a181a879c0e..659a0385b783 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)