osmo-service-respawn: Add a shell script that spawns and respawns services

Adjust the oom_score_adj of the shell script to avoid ever beeing
killed. Adjust the score of the child and nice it. Sleep a given
interval before respawning it.

This script creates a .pid file so it can be used by a sysv init
script to stop the respawner and the client.
diff --git a/recipes-osmocom/osmo-service-respawn/files/osmo-service-respawn.sh b/recipes-osmocom/osmo-service-respawn/files/osmo-service-respawn.sh
new file mode 100755
index 0000000..e7274d4
--- /dev/null
+++ b/recipes-osmocom/osmo-service-respawn/files/osmo-service-respawn.sh
@@ -0,0 +1,19 @@
+#!/usr/bin/env bash
+
+NAME=`basename $1`
+PIDFILE="/var/run/$NAME.pid"
+PID=$$
+echo "$PID" > $PIDFILE
+echo "-1000" > /proc/$PID/oom_score_adj
+
+trap "{ rm -f $PIDFILE ; kill 0; }" EXIT
+
+while true;
+do
+        echo "Restarting not dealing well with spaces.."
+        (echo "0" > /proc/self/oom_score_adj && exec $@) &
+        LAST_PID=$!
+        wait $LAST_PID
+        sleep 10s
+done
+
diff --git a/recipes-osmocom/osmo-service-respawn/osmo-service-respawn_1.0.bb b/recipes-osmocom/osmo-service-respawn/osmo-service-respawn_1.0.bb
new file mode 100644
index 0000000..8779f34
--- /dev/null
+++ b/recipes-osmocom/osmo-service-respawn/osmo-service-respawn_1.0.bb
@@ -0,0 +1,13 @@
+DESCRIPTION = "Shell script to start, nice and respawn services"
+HOMEPAGE = "http://openbsc.osmocom.org/"
+LICENSE = "AGPLv3+"
+LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=3f40d7994397109285ec7b81fdeb3b58"
+
+SRC_URI = "file://osmo-service-respawn.sh"
+
+RDEPENDS_${PN} = "bash"
+
+do_install() {
+	install -d ${D}${bindir}
+	install -m 0775 ${WORKDIR}/osmo-service-respawn.sh ${D}${bindir}
+}