summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorSimon Rettberg2014-06-03 16:47:36 +0200
committerSimon Rettberg2014-06-03 16:47:36 +0200
commit32dc5354e2916387a2c62eadae0a4568023f1151 (patch)
tree7fd9a0173d6073e86d1d48e545646b1bc8c1a5eb /scripts
downloadtmlite-bwlp-32dc5354e2916387a2c62eadae0a4568023f1151.tar.gz
tmlite-bwlp-32dc5354e2916387a2c62eadae0a4568023f1151.tar.xz
tmlite-bwlp-32dc5354e2916387a2c62eadae0a4568023f1151.zip
Initial commit
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/ldadp-launcher86
-rwxr-xr-xscripts/mount-store82
2 files changed, 168 insertions, 0 deletions
diff --git a/scripts/ldadp-launcher b/scripts/ldadp-launcher
new file mode 100755
index 0000000..be73ec7
--- /dev/null
+++ b/scripts/ldadp-launcher
@@ -0,0 +1,86 @@
+#!/bin/bash
+
+if [ $# -lt 2 ]; then
+ echo "Invalid parameter count: '$#'"
+ exit 1
+fi
+
+BASE="$1"
+shift
+
+if [ -z "$BASE" ] || [ ! -r "$BASE" ] || [ ! -d "$BASE" ]; then
+ echo "Basedir invalid: '$BASE'"
+ exit 2
+fi
+cd "$BASE"
+
+[ "x$1" == "x--" ] && shift
+
+# At this point $@ should only be ldadp instance ids
+
+inArray () {
+ local e
+ for e in "${@:2}"; do
+ [[ "x$e" == "x$1" ]] && return 0
+ done
+ return 1
+}
+
+isInstance () {
+ if [ $# -ne 1 ]; then
+ echo "isInstance needs 1 param, got $#"
+ return 0
+ fi
+ [ -L "/proc/$1/exe" ] && [ -r "/proc/$1/exe" ] && [[ "$(readlink -f "/proc/$1/exe")" == *ldadp ]] && return 0
+ return 1
+}
+
+launch () {
+ local CONFIG="${BASE}/configs/${1}.cfg"
+ if [ ! -r "$CONFIG" ]; then
+ echo "Told to start ldadp for module '${1}', but no config file found!"
+ return 1
+ fi
+ echo "Launching #$1"
+ "${BASE}/ldadp" -n "$CONFIG" &
+ local P=$!
+ sleep 1
+ if ! kill -0 "$P" 2>/dev/null; then
+ echo "...FAILED!"
+ return 1
+ fi
+ echo -n "$P" > "${BASE}/pid/${1}"
+ return 0
+}
+
+for FILE in $(find "$BASE/pid" -type f -regextype posix-extended -regex "(^|.*/)[0-9]+$"); do
+ ID=$(basename $FILE)
+ PID=$(<$FILE)
+ if ! [[ "$PID" =~ ^[0-9]+$ ]]; then
+ echo "Invalid PID file: '$FILE'"
+ unlink "$FILE"
+ fi
+ 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
+ # Is running, should not, kill
+ kill $PID
+ sleep 1
+ isInstance $PID && kill -9 $PID
+ fi
+done
+
+while [ $# -gt 0 ]; do
+ ID=$1
+ shift
+ FILE="${BASE}/pid/${ID}"
+ [ -r "$FILE" ] && isInstance $(<$FILE) && continue
+ launch $ID
+done
+
+exit 0
+
diff --git a/scripts/mount-store b/scripts/mount-store
new file mode 100755
index 0000000..1291d1a
--- /dev/null
+++ b/scripts/mount-store
@@ -0,0 +1,82 @@
+#!/bin/bash
+
+if [ $# -lt 2 ]; then
+ echo "Bad call to $0." >&2
+ echo "Expected: $0 images <source> [username] [password]" >&2
+ exit 1
+fi
+
+WHAT="$1"
+SOURCE="$2"
+USERNAME="$3"
+PASSWORD="$4"
+
+# Currently WHAT can only be images (the central store for all images),
+# but maybe there will be other storage types in the future.
+case "$WHAT" in
+images)
+ DEST="/opt/openslx/nfs"
+ ;;
+*)
+ echo "Invalid/Unknown mount type: '$WHAT'." >&2
+ exit 1
+ ;;
+esac
+
+# Sanity checks: Destination exists?
+if [ ! -d "$DEST" ]; then
+ mkdir -p "$DEST"
+ chown root:images "$DEST"
+ chmod 0775 "$DEST"
+fi
+
+# Still a no?
+if [ ! -d "$DEST" ]; then
+ echo "Mount point '$DEST' does not exist and could not be created!" >&2
+ echo "This should not happen and means this server is severely messed up. :(" >&2
+ exit 1
+fi
+
+# Already mounted?
+if awk '{print $2}' "/proc/mounts" | grep -q "^${DEST}\$"; then
+ echo "Trying to unmount '$DEST'..."
+ umount -v "$DEST"
+ RET=$?
+ if [ "$RET" -ne "0" ]; then
+ echo "Cannot unmount '$DEST'!" >&2
+ exit "$RET"
+ fi
+fi
+
+# Unmount and not requested to mount (local mode)
+if [[ "${SOURCE}" == "null" ]]; then
+ rm -f "${DEST}/.notmounted"
+ exit 0
+fi
+
+touch "${DEST}/.notmounted"
+
+# Mount!
+
+if grep -E -q '^[^/].+:.+' <<<$SOURCE; then
+ # seems to be NFS
+ mount -t nfs -o rw,async,nolock,fg,ac,retry=1,timeo=600 "$SOURCE" "$DEST"
+ RET=$?
+elif grep -E -q '^//' <<<$SOURCE; then
+ # seens to be SMB
+ export USER="$USERNAME"
+ export PASSWD="$PASSWORD"
+ mount -t cifs -o rw,uid=0,gid=12345,forceuid,forcegid,file_mode=0664,dir_mode=0775,sec=ntlm "$SOURCE" "$DEST"
+ RET=$?
+ unset USER PASSWD
+else
+ echo "Unknown mount type: $SOURCE"
+ exit 1
+fi
+
+if [ "$RET" == "0" ]; then
+ chmod -R ug+rw "$DEST"
+fi
+
+exit $RET
+