summaryrefslogtreecommitdiffstats
path: root/scripts/ldadp-launcher
diff options
context:
space:
mode:
authorSimon Rettberg2014-06-27 21:21:11 +0200
committerSimon Rettberg2014-06-27 21:21:11 +0200
commit39fab1f2d65d652d48ec94123b1c7191c78932f3 (patch)
treef3ccbe24d2c3c9ae82fca18572661224b7e8a05d /scripts/ldadp-launcher
parentRemove IP address from PXE menu (diff)
downloadtmlite-bwlp-39fab1f2d65d652d48ec94123b1c7191c78932f3.tar.gz
tmlite-bwlp-39fab1f2d65d652d48ec94123b1c7191c78932f3.tar.xz
tmlite-bwlp-39fab1f2d65d652d48ec94123b1c7191c78932f3.zip
Better error handling for ldadp launching
Diffstat (limited to 'scripts/ldadp-launcher')
-rwxr-xr-xscripts/ldadp-launcher27
1 files changed, 16 insertions, 11 deletions
diff --git a/scripts/ldadp-launcher b/scripts/ldadp-launcher
index be73ec7..2bd8b90 100755
--- a/scripts/ldadp-launcher
+++ b/scripts/ldadp-launcher
@@ -1,7 +1,7 @@
#!/bin/bash
if [ $# -lt 2 ]; then
- echo "Invalid parameter count: '$#'"
+ echo "Invalid parameter count: '$#'" >&2
exit 1
fi
@@ -9,7 +9,7 @@ BASE="$1"
shift
if [ -z "$BASE" ] || [ ! -r "$BASE" ] || [ ! -d "$BASE" ]; then
- echo "Basedir invalid: '$BASE'"
+ echo "Basedir invalid: '$BASE'" >&2
exit 2
fi
cd "$BASE"
@@ -28,7 +28,7 @@ inArray () {
isInstance () {
if [ $# -ne 1 ]; then
- echo "isInstance needs 1 param, got $#"
+ echo "isInstance needs 1 param, got $#" >&2
return 0
fi
[ -L "/proc/$1/exe" ] && [ -r "/proc/$1/exe" ] && [[ "$(readlink -f "/proc/$1/exe")" == *ldadp ]] && return 0
@@ -38,21 +38,27 @@ isInstance () {
launch () {
local CONFIG="${BASE}/configs/${1}.cfg"
if [ ! -r "$CONFIG" ]; then
- echo "Told to start ldadp for module '${1}', but no config file found!"
+ echo "Told to start ldadp for module '${1}', but no config file found!" >&2
return 1
fi
echo "Launching #$1"
- "${BASE}/ldadp" -n "$CONFIG" &
+ local LOGFILE="${BASE}/logs/${1}.log"
+ if [ ! -w "${BASE}/logs" ] || [ -e "$LOGFILE" -a ! -w "$LOGFILE" ]; then
+ LOGFILE="/dev/null"
+ fi
+ "${BASE}/ldadp" -n "$CONFIG" > "$LOGFILE" &
local P=$!
sleep 1
if ! kill -0 "$P" 2>/dev/null; then
- echo "...FAILED!"
+ echo "...FAILED to launch #$1" >&2
return 1
fi
echo -n "$P" > "${BASE}/pid/${1}"
return 0
}
+RETVAL=0
+
for FILE in $(find "$BASE/pid" -type f -regextype posix-extended -regex "(^|.*/)[0-9]+$"); do
ID=$(basename $FILE)
PID=$(<$FILE)
@@ -63,10 +69,7 @@ for FILE in $(find "$BASE/pid" -type f -regextype posix-extended -regex "(^|.*/)
inArray $ID "$@" && isInstance $PID && continue # Should be running, is running, nothing to do
#
unlink "$FILE"
- if inArray $ID; then
- # Should be running, is not running, launch!
- launch $ID
- elif isInstance $PID; then
+ if isInstance $PID; then
# Is running, should not, kill
kill $PID
sleep 1
@@ -80,7 +83,9 @@ while [ $# -gt 0 ]; do
FILE="${BASE}/pid/${ID}"
[ -r "$FILE" ] && isInstance $(<$FILE) && continue
launch $ID
+ RET=$?
+ [ "$RET" != "0" ] && RETVAL=1
done
-exit 0
+exit "$RETVAL"