mailarchive of the ptxdist mailing list
 help / color / mirror / Atom feed
From: Michael Olbrich <m.olbrich@pengutronix.de>
To: ptxdist@pengutronix.de
Cc: Alexander Dahl <ada@thorsis.com>
Subject: Re: [ptxdist] [APPLIED] mtd-utils: Introduce bbinit startup for ubihealthd
Date: Wed, 21 Jun 2023 10:51:11 +0200	[thread overview]
Message-ID: <20230621085111.2553829-1-m.olbrich@pengutronix.de> (raw)
In-Reply-To: <20230612063849.19499-2-ada@thorsis.com>

Thanks, applied as 7b9d64648a001346a99f45900707c107c2a24084.

Michael

[sent from post-receive hook]

On Wed, 21 Jun 2023 10:51:10 +0200, Alexander Dahl <ada@thorsis.com> 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 <ada@thorsis.com>
> Message-Id: <20230612063849.19499-2-ada@thorsis.com>
> Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
> 
> 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)



  reply	other threads:[~2023-06-21  8:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-12  6:38 [ptxdist] [PATCH 0/2] mtd-utils: ubihealthd: Init script and help text Alexander Dahl
2023-06-12  6:38 ` [ptxdist] [PATCH 1/2] mtd-utils: Introduce bbinit startup for ubihealthd Alexander Dahl
2023-06-21  8:51   ` Michael Olbrich [this message]
2023-06-12  6:38 ` [ptxdist] [PATCH 2/2] mtd-utils: Add ubihealthd requirements to help text Alexander Dahl
2023-06-21  8:51   ` [ptxdist] [APPLIED] " Michael Olbrich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230621085111.2553829-1-m.olbrich@pengutronix.de \
    --to=m.olbrich@pengutronix.de \
    --cc=ada@thorsis.com \
    --cc=ptxdist@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox