check_oracle_health: update to 1.9.3.5
[omd.git] / packages / shinken / MONGODB_TCP_PORT.hook
blobcdadc3fca7578155c610f36e058211efe9c857b2
1 #!/bin/bash
3 # Alias: TCP port number and listening address for MongoDB
4 # Menu: Addons
5 # Description:
6 # Configure the TCP port used for the MongoDB
7 # process of this site. This option is only useful if
8 # the CORE is set to "shinken" and MONGODB is set to "on".
9 #
12 port_is_used ()
14 local PORT=$1
15 ls /omd/sites/*/etc/omd/site.conf >/dev/null 2>&1 || return 1
16 for conf in /omd/sites/*/etc/omd/site.conf
18 [ $conf != /omd/sites/$OMD_SITE/etc/omd/site.conf ] || continue
19 if grep -qx "CONFIG_MONGODB_TCP_PORT='$PORT'" < $conf > /dev/null 2>&1 ; then
20 return 0
22 done
23 return 1
27 next_free_hook ()
29 local PORT=$1
30 while port_is_used $PORT
32 PORT=$((PORT + 1))
33 done
34 echo "$PORT"
38 case "$1" in
39 default)
40 # Scan for a free port number by looking at the
41 # configuration of the other sites...
42 PORT=$(next_free_hook 27017)
43 echo "$PORT"
45 choices)
46 echo "([1-9][0-9]{0,5})|([a-zA-Z0-9\.\-]*:[1-9][0-9]{0,5})"
48 set)
49 SELECTED_PORT=${2:=localhost:27017}
50 if [ "${SELECTED_PORT##*:}" = "${SELECTED_PORT%%:*}" ]; then
51 BIND_IP=0.0.0.0
52 elif [ "${SELECTED_PORT%%:*}" = "localhost" ]; then
53 SELECTED_PORT=${SELECTED_PORT##*:}
54 BIND_IP=127.0.0.1
55 else
56 BIND_IP=${SELECTED_PORT%%:*}
57 SELECTED_PORT=${SELECTED_PORT##*:}
59 PORT=$(next_free_hook $SELECTED_PORT)
60 CHECK_PORT=${PORT##*:}
61 if [ "$CHECK_PORT" != "$SELECTED_PORT" ] ; then
62 echo "MongoDB port $SELECTED_PORT is in use. I've choosen $PORT instead." >&2
63 echo "$PORT"
65 cat <<EOF > $OMD_ROOT/etc/mongodb/mongod.d/port.conf
66 port = $PORT
67 bind_ip = $BIND_IP
68 EOF
70 depends)
71 [ "$CONFIG_MONGODB" = on ]
73 esac