Browse code

move setting variables and run-as-stack-user code

Change the over all flow so that the default settings are
filled in in the outside shell (not inside the '()' and 'tee').

This way, those variables pass through to the subshell, but they're
also available in the parent shell at the end for outputting status.

Also, exit failure rather than success if 'exec' to run as stack
user failed.

Scott Moser authored on 2011/10/08 10:28:00
Showing 1 changed files
... ...
@@ -40,52 +40,6 @@ if [ ! -d $FILES ]; then
40 40
     exit 1
41 41
 fi
42 42
 
43
-# Settings
44
-# ========
45
-
46
-# This script is customizable through setting environment variables.  If you
47
-# want to override a setting you can either::
48
-#
49
-#     export MYSQL_PASS=anothersecret
50
-#     ./stack.sh
51
-#
52
-# You can also pass options on a single line ``MYSQL_PASS=simple ./stack.sh``
53
-#
54
-# Additionally, you can put any local variables into a ``localrc`` file, like::
55
-#
56
-#     MYSQL_PASS=anothersecret
57
-#     MYSQL_USER=hellaroot
58
-#
59
-# We try to have sensible defaults, so you should be able to run ``./stack.sh``
60
-# in most cases.
61
-#
62
-# We our settings from ``stackrc``.  This file is distributed with devstack and
63
-# contains locations for what repositories to use.  If you want to use other 
64
-# repositories and branches, you can add your own settings with another file 
65
-# called ``localrc``
66
-#
67
-# If ``localrc`` exists, then ``stackrc`` will load those settings.  This is 
68
-# useful for changing a branch or repostiory to test other versions.  Also you
69
-# can store your other settings like **MYSQL_PASS** or **ADMIN_PASSWORD** instead
70
-# of letting devstack generate random ones for you.
71
-source ./stackrc
72
-
73
-LOGFILE=${LOGFILE:-"$PWD/stack.sh.$$.log"}
74
-(
75
-# So that errors don't compound we exit on any errors so you see only the
76
-# first error that occured.
77
-trap failed ERR
78
-failed() {
79
-    local r=$?
80
-    set +o xtrace
81
-    [ -n "$LOGFILE" ] && echo "${0##*/} failed: full log in $LOGFILE"
82
-    exit $r
83
-}
84
-
85
-# Print the commands being run so that we can see the command that triggers
86
-# an error.  It is also useful for following along as the install occurs.
87
-set -o xtrace
88
-
89 43
 # OpenStack is designed to be run as a regular user (Dashboard will fail to run
90 44
 # as root, since apache refused to startup serve content from root user).  If
91 45
 # stack.sh is run as root, it automatically creates a stack user with
... ...
@@ -119,13 +73,42 @@ if [[ $EUID -eq 0 ]]; then
119 119
     else
120 120
         exec su -ec "cd $STACK_DIR; bash stack.sh" stack
121 121
     fi
122
-    exit 0
122
+    exit 1
123 123
 fi
124 124
 
125
+
126
+# Settings
127
+# ========
128
+
129
+# This script is customizable through setting environment variables.  If you
130
+# want to override a setting you can either::
131
+#
132
+#     export MYSQL_PASS=anothersecret
133
+#     ./stack.sh
134
+#
135
+# You can also pass options on a single line ``MYSQL_PASS=simple ./stack.sh``
136
+#
137
+# Additionally, you can put any local variables into a ``localrc`` file, like::
138
+#
139
+#     MYSQL_PASS=anothersecret
140
+#     MYSQL_USER=hellaroot
141
+#
142
+# We try to have sensible defaults, so you should be able to run ``./stack.sh``
143
+# in most cases.
144
+#
145
+# We our settings from ``stackrc``.  This file is distributed with devstack and
146
+# contains locations for what repositories to use.  If you want to use other 
147
+# repositories and branches, you can add your own settings with another file 
148
+# called ``localrc``
149
+#
150
+# If ``localrc`` exists, then ``stackrc`` will load those settings.  This is 
151
+# useful for changing a branch or repostiory to test other versions.  Also you
152
+# can store your other settings like **MYSQL_PASS** or **ADMIN_PASSWORD** instead
153
+# of letting devstack generate random ones for you.
154
+source ./stackrc
155
+
125 156
 # Destination path for installation ``DEST``
126 157
 DEST=${DEST:-/opt/stack}
127
-sudo mkdir -p $DEST
128
-sudo chown `whoami` $DEST
129 158
 
130 159
 # Set the destination directories for openstack projects
131 160
 NOVA_DIR=$DEST/nova
... ...
@@ -227,6 +210,24 @@ SERVICE_TOKEN=${SERVICE_TOKEN:-`openssl rand -hex 12`}
227 227
 # so use 10 bytes
228 228
 ADMIN_PASSWORD=${ADMIN_PASSWORD:-`openssl rand -hex 10`}
229 229
 
230
+LOGFILE=${LOGFILE:-"$PWD/stack.sh.$$.log"}
231
+(
232
+# So that errors don't compound we exit on any errors so you see only the
233
+# first error that occured.
234
+trap failed ERR
235
+failed() {
236
+    local r=$?
237
+    set +o xtrace
238
+    [ -n "$LOGFILE" ] && echo "${0##*/} failed: full log in $LOGFILE"
239
+    exit $r
240
+}
241
+
242
+# Print the commands being run so that we can see the command that triggers
243
+# an error.  It is also useful for following along as the install occurs.
244
+set -o xtrace
245
+
246
+sudo mkdir -p $DEST
247
+sudo chown `whoami` $DEST
230 248
 
231 249
 # Install Packages
232 250
 # ================