[omd-commits] OMD Git: omd: shinken: add a forgotten hook-file

git version control git at mathias-kettner.de
Thu May 17 11:48:46 CEST 2012


Module:   omd
Branch:   master
Commit:   0930bb6c455fbf89c4d7bebafcfd644427b313c7
URL:      http://omdistro.org/projects/omd/repository/revisions/0930bb6c455fbf89c4d7bebafcfd644427b313c7

Author:   Gerhard Lausser <gerhard.lausser at consol.de>
Date:     Thu May 17 01:29:22 2012 +0200
Commiter: Gerhard Lausser <gerhard.lausser at consol.de>
Date:     Thu May 17 11:13:17 2012 +0200

shinken: add a forgotten hook-file

---

 packages/shinken/MONGODB_TCP_PORT.hook             |   72 ++++++++++++++++++++
 .../shinken/skel/etc/mongodb/mongod.d/port.conf    |    2 +
 2 files changed, 74 insertions(+), 0 deletions(-)

diff --git a/packages/shinken/MONGODB_TCP_PORT.hook b/packages/shinken/MONGODB_TCP_PORT.hook
new file mode 100755
index 0000000..e4fbbfa
--- /dev/null
+++ b/packages/shinken/MONGODB_TCP_PORT.hook
@@ -0,0 +1,72 @@
+#!/bin/bash
+
+# Alias: TCP port number and listening address for MongoDB
+# Menu: Addons
+# Description: 
+#  Configure the TCP port used for the MongoDB
+#  process of this site. This option is only useful if 
+#  the CORE is set to "shinken" and MONGODB is set to "on".
+#  
+
+
+port_is_used ()
+{
+    local PORT=$1
+    ls /omd/sites/*/etc/omd/site.conf >/dev/null 2>&1 || return 1
+    for conf in /omd/sites/*/etc/omd/site.conf
+    do
+        [ $conf != /omd/sites/$OMD_SITE/etc/omd/site.conf ] || continue
+        if grep -qx "CONFIG_MONGODB_TCP_PORT='$PORT'" < $conf > /dev/null 2>&1 ; then
+            return 0
+        fi
+    done
+    return 1
+}
+
+
+next_free_hook ()
+{
+    local PORT=$1
+    while port_is_used $PORT
+    do
+        PORT=$((PORT + 1))
+    done
+    echo "$PORT"
+}
+
+
+case "$1" in
+    default)
+        # Scan for a free port number by looking at the
+        # configuration of the other sites...
+        PORT=$(next_free_hook 27017)
+        echo "$PORT"
+    ;;
+    choices)
+        echo "([1-9][0-9]{0,5})|([a-zA-Z0-9\.\-]*:[1-9][0-9]{0,5})"
+    ;;
+    set)
+        SELECTED_PORT=${2:=localhost:27017}
+        if [ "${SELECTED_PORT##*:}" = "${SELECTED_PORT%%:*}" ]; then
+            BIND_IP=0.0.0.0
+        elif [ "${SELECTED_PORT%%:*}" = "localhost" ]; then
+            SELECTED_PORT=${SELECTED_PORT##*:}
+            BIND_IP=127.0.0.1
+        else
+            BIND_IP=${SELECTED_PORT%%:*}
+            SELECTED_PORT=999
+        fi
+        PORT=$(next_free_hook $SELECTED_PORT)
+        if [ "$PORT" != "$SELECTED_PORT" ] ; then
+            echo "MongoDB port $SELECTED_PORT is in use. I've choosen $PORT instead." >&2
+            echo "$PORT"
+        fi
+        cat <<EOF > $OMD_ROOT/etc/mongodb/port.conf
+port = $PORT
+bind_ip = $BIND_IP
+EOF
+    ;;
+    depends)
+        [ "$MONGODB" = on ]
+    ;;
+esac
diff --git a/packages/shinken/skel/etc/mongodb/mongod.d/port.conf b/packages/shinken/skel/etc/mongodb/mongod.d/port.conf
new file mode 100644
index 0000000..1c3c53d
--- /dev/null
+++ b/packages/shinken/skel/etc/mongodb/mongod.d/port.conf
@@ -0,0 +1,2 @@
+port = 27017
+bind_ip = localhost



More information about the omd-commits mailing list