Browse Source

Bugfix in mass deploy for remote mongodb connection

Yann Weber 8 years ago
parent
commit
5ef11f5b6d
1 changed files with 13 additions and 12 deletions
  1. 13
    12
      progs/mass_deploy.sh

+ 13
- 12
progs/mass_deploy.sh View File

@@ -37,6 +37,7 @@ test -f $conffile || badconf
37 37
 . $conffile
38 38
 test -z "$MONGODB_ADMIN_USER" && badconf
39 39
 test -z "$MONGODB_ADMIN_PASSWORD" && badconf
40
+$MONGODB_HOST=${MONGODB_HOST:="127.0.0.1"}
40 41
 
41 42
 
42 43
 if [ -z "$fixed_name" ]
@@ -65,17 +66,17 @@ fi
65 66
 
66 67
 if [ -f "/etc/mongodb.conf" ]
67 68
 then
68
-	if cat /etc/mongodb.conf  |grep -E '^ *auth *= *true *$' >/dev/null
69
-	then
70
-		echo "OK, auth enabled"
71
-	else
72
-		echo "WARNING : auth seems disabled on mongod !" >&2
73
-	fi
69
+        if cat /etc/mongodb.conf  |grep -E '^ *auth *= *true *$' >/dev/null
70
+        then
71
+                echo "OK, auth enabled"
72
+        else
73
+                echo "WARNING : auth seems disabled on mongod !" >&2
74
+        fi
74 75
 else
75
-	echo "/etc/mongodb.conf not found. Unable to check if auth is on"
76
+        echo "/etc/mongodb.conf not found. Unable to check if auth is on"
76 77
 fi
77 78
 
78
-echo "exit" | mongo $MONGODB_HOST --quiet -u "$MONGODB_ADMIN_USER" -p "$MONGODB_ADMIN_PASSWORD" admin &>/dev/null || mongodb_connfail
79
+echo "exit" | mongo $MONGODB_HOST --quiet -u "$MONGODB_ADMIN_USER" -p "$MONGODB_ADMIN_PASSWORD" --authenticationDatabase admin &>/dev/null || mongodb_connfail
79 80
 
80 81
 if [ "$1" == 'purgedb' ]
81 82
 then
@@ -88,9 +89,9 @@ then
88 89
 	read rep
89 90
 	if [ "$rep" = "Y" ]
90 91
 	then
91
-		for dbname in $(echo "show dbs" | mongo -u admin -p pass admin  |grep "^$MONGODB_DB_PREFIX"|cut -f1)
92
+		for dbname in $(echo "show dbs" | mongo $MONGODB_HOST --quiet -u "$MONGODB_ADMIN_USER" -p "$MONGODB_ADMIN_PASSWORD" --authenticationDatabase admin |grep "^$MONGODB_DB_PREFIX"|cut -f1)
92 93
 		do 
93
-			echo -e "use $dname\ndb.dropDatabase()\nexit\n" | mongo -u $MONGODB_ADMIN_USER -p $MONGODB_ADMIN_PASSWORD --quiet --authenticationDatabase admin $dbname && echo "$dbname succesfully deleted" || echo "$dbname deletion fails" >&2
94
+			echo -e "use $dname\ndb.dropDatabase()\nexit\n" | mongo $MONGODB_HOST -u "$MONGODB_ADMIN_USER" -p "$MONGODB_ADMIN_PASSWORD" --quiet --authenticationDatabase admin && echo "$dbname succesfully deleted" || echo "$dbname deletion fails" >&2
94 95
 		done
95 96
 		echo "Done."
96 97
 	else
@@ -139,13 +140,13 @@ do
139 140
 	dbname="${MONGODB_DB_PREFIX}_$iname"
140 141
 	dbuser="lodel2_$iname"
141 142
 	dbpass=$($rnd_pass_cmd)
142
-	mongo $MONGODB_HOST -u "$MONGODB_ADMIN_USER" -p "$MONGODB_ADMIN_PASSWORD" admin <<EOF
143
+	mongo $MONGODB_HOST -u "$MONGODB_ADMIN_USER" -p "$MONGODB_ADMIN_PASSWORD" --authenticationDatabase admin <<EOF
143 144
 use $dbname
144 145
 db.addUser({user:"$dbuser", pwd:"$dbpass", roles:["readWrite", "dbAdmin"]})
145 146
 exit
146 147
 EOF
147 148
 	#Append created db to instance conf
148
-	slim -n $iname -s --datasource_connectors mongodb --host localhost --user $dbuser --password $dbpass --db_name $dbname || slim_fails "configuring the instance's datasource"
149
+	slim -n $iname -s --datasource_connectors mongodb --host $MONGODB_HOST --user $dbuser --password $dbpass --db_name $dbname || slim_fails "configuring the instance's datasource"
149 150
 
150 151
 done
151 152
 

Loading…
Cancel
Save