Added a startup script inspired by upstream, debian, buildroot and the
lldpd startup script already present in ptxdist. Also added the usual
ptxdist menu stuff for daemons started with bbinit method.

Signed-off-by: Alexander Dahl <p...@lespocky.de>
---
 projectroot/etc/init.d/haveged | 114 +++++++++++++++++++++++++++++++++++++++++
 rules/haveged-bbinit.in        |   9 ++++
 rules/haveged.in               |  14 ++++-
 rules/haveged.make             |  11 ++++
 4 files changed, 146 insertions(+), 2 deletions(-)
 create mode 100755 projectroot/etc/init.d/haveged
 create mode 100644 rules/haveged-bbinit.in

diff --git a/projectroot/etc/init.d/haveged b/projectroot/etc/init.d/haveged
new file mode 100755
index 0000000..1a4fc62
--- /dev/null
+++ b/projectroot/etc/init.d/haveged
@@ -0,0 +1,114 @@
+#!/bin/sh
+
+PATH='/sbin:/usr/sbin:/bin:/usr/bin'
+DESC='haveged entropy daemon'
+NAME='haveged'
+DAEMON="/usr/sbin/$NAME"
+DAEMON_ARGS='-w 1024 -r 0 -v 1'
+PIDFILE="/var/run/${NAME}.pid"
+SCRIPTNAME="/etc/init.d/$NAME"
+
+# exit if binary is missing
+[ -x "$DAEMON" ] || exit 0
+
+is_running() {
+    start-stop-daemon -K --quiet --test --exec $DAEMON --pidfile $PIDFILE
+}
+
+do_start() {
+    is_running && return 1
+    start-stop-daemon -S --quiet --pidfile $PIDFILE --exec $DAEMON -- \
+        $DAEMON_ARGS \
+        || return 2
+}
+
+do_stop() {
+    is_running || return 0
+    start-stop-daemon -K --quiet --pidfile $PIDFILE --name $NAME
+    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 --pidfile $PIDFILE --name 
$NAME
+
+        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 with PID $(cat $PIDFILE) ..."
+        else
+            echo "$NAME is not running"
+        fi
+        ;;
+    *)
+        echo "Usage: $SCRIPTNAME {start|stop|restart|status}" >&2
+        exit 3
+        ;;
+esac
+
+:
diff --git a/rules/haveged-bbinit.in b/rules/haveged-bbinit.in
new file mode 100644
index 0000000..b6aee22
--- /dev/null
+++ b/rules/haveged-bbinit.in
@@ -0,0 +1,9 @@
+## SECTION=initmethod_bbinit
+
+config HAVEGED_BBINIT_LINK
+       string
+       depends on HAVEGED_STARTSCRIPT
+       prompt "haveged"
+       default "S21haveged"
+
+# vim: ft=kconfig noet tw=72
diff --git a/rules/haveged.in b/rules/haveged.in
index 9a8a597..f048327 100644
--- a/rules/haveged.in
+++ b/rules/haveged.in
@@ -1,7 +1,17 @@
 ## SECTION=networking
 
-config HAVEGED
+menuconfig HAVEGED
        tristate
-       prompt "haveged"
+       prompt "haveged                       "
+       select BUSYBOX_START_STOP_DAEMON if HAVEGED_STARTSCRIPT
+       select BUSYBOX_FEATURE_START_STOP_DAEMON_LONG_OPTIONS if 
HAVEGED_STARTSCRIPT
        help
          haveged is a simple entropy daemon
+
+if HAVEGED
+
+config HAVEGED_STARTSCRIPT
+       bool
+       prompt "install /etc/init.d/haveged"
+
+endif
diff --git a/rules/haveged.make b/rules/haveged.make
index b05b0f6..af5fa0b 100644
--- a/rules/haveged.make
+++ b/rules/haveged.make
@@ -63,6 +63,17 @@ $(STATEDIR)/haveged.targetinstall:
        @$(call install_lib, haveged, 0, 0, 0644, libhavege)
        @$(call install_copy, haveged, 0, 0, 0755, -, /usr/sbin/haveged)
 
+ifdef PTXCONF_INITMETHOD_BBINIT
+ifdef PTXCONF_HAVEGED_STARTSCRIPT
+       @$(call install_alternative, haveged, 0, 0, 0755, /etc/init.d/haveged)
+
+ifneq ($(call remove_quotes,$(PTXCONF_HAVEGED_BBINIT_LINK)),)
+       @$(call install_link, haveged, ../init.d/haveged, \
+               /etc/rc.d/$(PTXCONF_HAVEGED_BBINIT_LINK))
+endif
+endif
+endif
+
 ifdef PTXCONF_INITMETHOD_SYSTEMD
        @$(call install_copy, haveged, 0, 0, 0644, -, 
/usr/lib/systemd/system/haveged.service)
        @$(call install_link, haveged, ../haveged.service, \
-- 
2.1.4


_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de

Reply via email to