Browse code

Merge remote-tracking branch 'origin/master' into image_config

Anthony Young authored on 2011/10/14 14:20:24
Showing 2 changed files
... ...
@@ -11,6 +11,13 @@ if ! grep -q natty /etc/lsb-release; then
11 11
     echo "WARNING: this script has only been tested on natty"
12 12
 fi
13 13
 
14
+# Abort if localrc is not set
15
+if [ ! -e ./localrc ]; then
16
+    echo "You must have a localrc with ALL necessary passwords defined before proceeding."
17
+    echo "See stack.sh for required passwords."
18
+    exit 1
19
+fi
20
+
14 21
 # Source params
15 22
 source ./stackrc
16 23
 
... ...
@@ -40,6 +40,9 @@ if [ ! -d $FILES ]; then
40 40
     exit 1
41 41
 fi
42 42
 
43
+# Keep track of the current devstack directory.
44
+TOP_DIR=$(cd $(dirname "$0") && pwd)
45
+
43 46
 # OpenStack is designed to be run as a regular user (Dashboard will fail to run
44 47
 # as root, since apache refused to startup serve content from root user).  If
45 48
 # stack.sh is run as root, it automatically creates a stack user with
... ...
@@ -86,14 +89,14 @@ fi
86 86
 # This script is customizable through setting environment variables.  If you
87 87
 # want to override a setting you can either::
88 88
 #
89
-#     export MYSQL_PASS=anothersecret
89
+#     export MYSQL_PASSWORD=anothersecret
90 90
 #     ./stack.sh
91 91
 #
92
-# You can also pass options on a single line ``MYSQL_PASS=simple ./stack.sh``
92
+# You can also pass options on a single line ``MYSQL_PASSWORD=simple ./stack.sh``
93 93
 #
94 94
 # Additionally, you can put any local variables into a ``localrc`` file, like::
95 95
 #
96
-#     MYSQL_PASS=anothersecret
96
+#     MYSQL_PASSWORD=anothersecret
97 97
 #     MYSQL_USER=hellaroot
98 98
 #
99 99
 # We try to have sensible defaults, so you should be able to run ``./stack.sh``
... ...
@@ -106,7 +109,7 @@ fi
106 106
 #
107 107
 # If ``localrc`` exists, then ``stackrc`` will load those settings.  This is 
108 108
 # useful for changing a branch or repostiory to test other versions.  Also you
109
-# can store your other settings like **MYSQL_PASS** or **ADMIN_PASSWORD** instead
109
+# can store your other settings like **MYSQL_PASSWORD** or **ADMIN_PASSWORD** instead
110 110
 # of letting devstack generate random ones for you.
111 111
 source ./stackrc
112 112
 
... ...
@@ -139,6 +142,43 @@ if [ ! -n "$HOST_IP" ]; then
139 139
     HOST_IP=`LC_ALL=C /sbin/ifconfig  | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
140 140
 fi
141 141
 
142
+# Generic helper to configure passwords
143
+function read_password {
144
+    set +o xtrace
145
+    var=$1; msg=$2
146
+    pw=${!var}
147
+
148
+    localrc=$TOP_DIR/localrc
149
+
150
+    # If the password is not defined yet, proceed to prompt user for a password.
151
+    if [ ! $pw ]; then
152
+        # If there is no localrc file, create one
153
+        if [ ! -e $localrc ]; then
154
+            touch $localrc
155
+        fi
156
+
157
+        # Presumably if we got this far it can only be that our localrc is missing 
158
+        # the required password.  Prompt user for a password and write to localrc.
159
+        echo ''
160
+        echo '################################################################################'
161
+        echo $msg
162
+        echo '################################################################################'
163
+        echo "This value will be written to your localrc file so you don't have to enter it again."
164
+        echo "It is probably best to avoid spaces and weird characters."
165
+        echo "If you leave this blank, a random default value will be used."
166
+        echo "Enter a password now:"
167
+        read $var
168
+        pw=${!var}
169
+        if [ ! $pw ]; then
170
+            pw=`openssl rand -hex 10`
171
+        fi
172
+        eval "$var=$pw"
173
+        echo "$var=$pw" >> $localrc
174
+    fi
175
+    set -o xtrace
176
+}
177
+
178
+
142 179
 # Nova Network Configuration
143 180
 # --------------------------
144 181
 
... ...
@@ -187,31 +227,32 @@ FLAT_INTERFACE=${FLAT_INTERFACE:-eth0}
187 187
 
188 188
 # By default this script will install and configure MySQL.  If you want to 
189 189
 # use an existing server, you can pass in the user/password/host parameters.
190
-# You will need to send the same ``MYSQL_PASS`` to every host if you are doing
190
+# You will need to send the same ``MYSQL_PASSWORD`` to every host if you are doing
191 191
 # a multi-node devstack installation.
192 192
 MYSQL_USER=${MYSQL_USER:-root}
193
-MYSQL_PASS=${MYSQL_PASS:-`openssl rand -hex 12`}
193
+read_password MYSQL_PASSWORD "ENTER A PASSWORD TO USE FOR MYSQL."
194 194
 MYSQL_HOST=${MYSQL_HOST:-localhost}
195 195
 
196 196
 # don't specify /db in this string, so we can use it for multiple services
197
-BASE_SQL_CONN=${BASE_SQL_CONN:-mysql://$MYSQL_USER:$MYSQL_PASS@$MYSQL_HOST}
197
+BASE_SQL_CONN=${BASE_SQL_CONN:-mysql://$MYSQL_USER:$MYSQL_PASSWORD@$MYSQL_HOST}
198 198
 
199 199
 # Rabbit connection info
200 200
 RABBIT_HOST=${RABBIT_HOST:-localhost}
201 201
 RABBIT_PASSWORD=${RABBIT_PASSWORD:-`openssl rand -hex 12`}
202
+read_password RABBIT_PASSWORD "ENTER A PASSWORD TO USE FOR RABBIT."
202 203
 
203 204
 # Glance connection info.  Note the port must be specified.
204 205
 GLANCE_HOSTPORT=${GLANCE_HOSTPORT:-$HOST_IP:9292}
205 206
 
207
+
206 208
 # Keystone
207 209
 # --------
208 210
 
209 211
 # Service Token - Openstack components need to have an admin token
210 212
 # to validate user tokens.
211
-SERVICE_TOKEN=${SERVICE_TOKEN:-`openssl rand -hex 12`}
213
+read_password SERVICE_TOKEN "ENTER A SERVICE_TOKEN TO USE FOR THE SERVICE ADMIN TOKEN."
212 214
 # Dash currently truncates usernames and passwords at 20 characters
213
-# so use 10 bytes
214
-ADMIN_PASSWORD=${ADMIN_PASSWORD:-`openssl rand -hex 10`}
215
+read_password ADMIN_PASSWORD "ENTER A PASSWORD TO USE FOR DASH AND KEYSTONE (20 CHARS OR LESS)."
215 216
 
216 217
 LOGFILE=${LOGFILE:-"$PWD/stack.sh.$$.log"}
217 218
 (
... ...
@@ -313,8 +354,8 @@ if [[ "$ENABLED_SERVICES" =~ "mysql" ]]; then
313 313
     # Seed configuration with mysql password so that apt-get install doesn't
314 314
     # prompt us for a password upon install.
315 315
     cat <<MYSQL_PRESEED | sudo debconf-set-selections
316
-mysql-server-5.1 mysql-server/root_password password $MYSQL_PASS
317
-mysql-server-5.1 mysql-server/root_password_again password $MYSQL_PASS
316
+mysql-server-5.1 mysql-server/root_password password $MYSQL_PASSWORD
317
+mysql-server-5.1 mysql-server/root_password_again password $MYSQL_PASSWORD
318 318
 mysql-server-5.1 mysql-server/start_on_boot boolean true
319 319
 MYSQL_PRESEED
320 320
 
... ...
@@ -325,7 +366,7 @@ MYSQL_PRESEED
325 325
         cat <<EOF >$HOME/.my.cnf
326 326
 [client]
327 327
 user=$MYSQL_USER
328
-password=$MYSQL_PASS    
328
+password=$MYSQL_PASSWORD
329 329
 host=$MYSQL_HOST
330 330
 EOF
331 331
         chmod 0600 $HOME/.my.cnf
... ...
@@ -334,7 +375,7 @@ EOF
334 334
     # Install and start mysql-server
335 335
     sudo apt-get -y -q install mysql-server
336 336
     # Update the DB to give user ‘$MYSQL_USER’@’%’ full control of the all databases:
337
-    sudo mysql -uroot -p$MYSQL_PASS -e "GRANT ALL PRIVILEGES ON *.* TO '$MYSQL_USER'@'%' identified by '$MYSQL_PASS';"
337
+    sudo mysql -uroot -p$MYSQL_PASSWORD -e "GRANT ALL PRIVILEGES ON *.* TO '$MYSQL_USER'@'%' identified by '$MYSQL_PASSWORD';"
338 338
 
339 339
     # Edit /etc/mysql/my.cnf to change ‘bind-address’ from localhost (127.0.0.1) to any (0.0.0.0) and restart the mysql service:
340 340
     sudo sed -i 's/127.0.0.1/0.0.0.0/g' /etc/mysql/my.cnf
... ...
@@ -385,8 +426,8 @@ if [[ "$ENABLED_SERVICES" =~ "g-reg" ]]; then
385 385
     mkdir -p $GLANCE_IMAGE_DIR
386 386
 
387 387
     # (re)create glance database
388
-    mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'DROP DATABASE IF EXISTS glance;'
389
-    mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'CREATE DATABASE glance;'
388
+    mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'DROP DATABASE IF EXISTS glance;'
389
+    mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'CREATE DATABASE glance;'
390 390
     # Copy over our glance-registry.conf
391 391
     GLANCE_CONF=$GLANCE_DIR/etc/glance-registry.conf
392 392
     cp $FILES/glance-registry.conf $GLANCE_CONF
... ...
@@ -515,8 +556,8 @@ fi
515 515
 
516 516
 if [[ "$ENABLED_SERVICES" =~ "mysql" ]]; then
517 517
     # (re)create nova database
518
-    mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'DROP DATABASE IF EXISTS nova;'
519
-    mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'CREATE DATABASE nova;'
518
+    mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'DROP DATABASE IF EXISTS nova;'
519
+    mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'CREATE DATABASE nova;'
520 520
 
521 521
     # (re)create nova database
522 522
     $NOVA_DIR/bin/nova-manage db sync
... ...
@@ -534,8 +575,8 @@ fi
534 534
 
535 535
 if [[ "$ENABLED_SERVICES" =~ "key" ]]; then
536 536
     # (re)create keystone database
537
-    mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'DROP DATABASE IF EXISTS keystone;'
538
-    mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'CREATE DATABASE keystone;'
537
+    mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'DROP DATABASE IF EXISTS keystone;'
538
+    mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'CREATE DATABASE keystone;'
539 539
 
540 540
     # FIXME (anthony) keystone should use keystone.conf.example
541 541
     KEYSTONE_CONF=$KEYSTONE_DIR/etc/keystone.conf