From 1b7bb4ae95080069fac8b226569d424f1393e1b7 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sat, 16 Mar 2013 11:25:49 +0100 Subject: [PATCH] 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. --- .../files/osmo-service-respawn.sh | 19 +++++++++++++++++++ .../osmo-service-respawn_1.0.bb | 13 +++++++++++++ 2 files changed, 32 insertions(+) create mode 100755 recipes-osmocom/osmo-service-respawn/files/osmo-service-respawn.sh create mode 100644 recipes-osmocom/osmo-service-respawn/osmo-service-respawn_1.0.bb 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 0000000000..e7274d4f30 --- /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 0000000000..8779f34fd9 --- /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} +}