diff options
author | Alexander Dahl <post@lespocky.de> | 2017-07-06 13:54:45 +0200 |
---|---|---|
committer | Michael Olbrich <m.olbrich@pengutronix.de> | 2017-07-17 08:56:50 +0200 |
commit | 6597a67ea5d5f9ad584aa52b70e69ceb1d216aa9 (patch) | |
tree | 52fa6f8b468685bc721238ba3f1ba09f3a0449a4 | |
parent | a95a80c7b2d8339ead5226e9345dddd6f80f78e0 (diff) | |
download | ptxdist-6597a67ea5d5f9ad584aa52b70e69ceb1d216aa9.tar.gz ptxdist-6597a67ea5d5f9ad584aa52b70e69ceb1d216aa9.tar.xz |
haveged: Introduce bbinit startup
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 <post@lespocky.de>
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
-rwxr-xr-x | projectroot/etc/init.d/haveged | 114 | ||||
-rw-r--r-- | rules/haveged-bbinit.in | 9 | ||||
-rw-r--r-- | rules/haveged.in | 14 | ||||
-rw-r--r-- | rules/haveged.make | 11 |
4 files changed, 146 insertions, 2 deletions
diff --git a/projectroot/etc/init.d/haveged b/projectroot/etc/init.d/haveged new file mode 100755 index 000000000..1a4fc62a2 --- /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 000000000..b6aee2250 --- /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 9a8a59702..95b3f2a83 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 b05b0f6a4..af5fa0b30 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, \ |