Browse code

Merge pull request #59 from smoser/localdev

several changes, largest of which is logging output

Jesse Andrews authored on 2011/10/14 01:26:50
Showing 1 changed files
... ...
@@ -20,9 +20,6 @@
20 20
 # Sanity Check
21 21
 # ============
22 22
 
23
-# Record the start time.  This allows us to print how long this script takes to run.
24
-START_TIME=`python -c "import time; print time.time()"`
25
-
26 23
 # Warn users who aren't on natty, but allow them to override check and attempt
27 24
 # installation with ``FORCE=yes ./stack``
28 25
 if ! grep -q natty /etc/lsb-release; then
... ...
@@ -50,40 +47,38 @@ fi
50 50
 
51 51
 if [[ $EUID -eq 0 ]]; then
52 52
     echo "You are running this script as root."
53
+    echo "In 10 seconds, we will create a user 'stack' and run as that user"
54
+    sleep 10 
53 55
 
54 56
     # since this script runs as a normal user, we need to give that user
55 57
     # ability to run sudo
56 58
     apt-get update
57
-    apt-get install -qqy sudo
59
+    apt-get install -y sudo
58 60
 
59
-    if ! getent passwd | grep -q stack; then
61
+    if ! getent passwd stack >/dev/null; then
60 62
         echo "Creating a user called stack"
61 63
         useradd -U -G sudo -s /bin/bash -m stack
62 64
     fi
65
+
63 66
     echo "Giving stack user passwordless sudo priviledges"
64
-    echo "stack ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
67
+    # natty uec images sudoers does not have a '#includedir'. add one.
68
+    grep -q "^#includedir.*/etc/sudoers.d" /etc/sudoers ||
69
+        echo "#includedir /etc/sudoers.d" >> /etc/sudoers
70
+    ( umask 226 && echo "stack ALL=(ALL) NOPASSWD:ALL" \
71
+        > /etc/sudoers.d/50_stack_sh )
65 72
 
66 73
     echo "Copying files to stack user"
67
-    cp -r -f `pwd` /home/stack/
68
-    THIS_DIR=$(basename $(dirname $(readlink -f $0)))
69
-    chown -R stack /home/stack/$THIS_DIR
70
-    echo "Running the script as stack in 3 seconds..."
71
-    sleep 3
74
+    STACK_DIR="/home/stack/${PWD##*/}"
75
+    cp -r -f "$PWD" "$STACK_DIR"
76
+    chown -R stack "$STACK_DIR"
72 77
     if [[ "$SHELL_AFTER_RUN" != "no" ]]; then
73
-	exec su -c "cd /home/stack/$THIS_DIR/; bash stack.sh; bash" stack
78
+        exec su -c "set -e; cd $STACK_DIR; bash stack.sh; bash" stack
74 79
     else
75
-	exec su -c "cd /home/stack/$THIS_DIR/; bash stack.sh" stack
80
+        exec su -c "set -e; cd $STACK_DIR; bash stack.sh" stack
76 81
     fi
77
-    exit 0
82
+    exit 1
78 83
 fi
79 84
 
80
-# So that errors don't compound we exit on any errors so you see only the
81
-# first error that occured.
82
-set -o errexit
83
-
84
-# Print the commands being run so that we can see the command that triggers
85
-# an error.  It is also useful for following allowing as the install occurs.
86
-set -o xtrace
87 85
 
88 86
 # Settings
89 87
 # ========
... ...
@@ -117,8 +112,6 @@ source ./stackrc
117 117
 
118 118
 # Destination path for installation ``DEST``
119 119
 DEST=${DEST:-/opt/stack}
120
-sudo mkdir -p $DEST
121
-sudo chown `whoami` $DEST
122 120
 
123 121
 # Set the destination directories for openstack projects
124 122
 NOVA_DIR=$DEST/nova
... ...
@@ -220,6 +213,24 @@ SERVICE_TOKEN=${SERVICE_TOKEN:-`openssl rand -hex 12`}
220 220
 # so use 10 bytes
221 221
 ADMIN_PASSWORD=${ADMIN_PASSWORD:-`openssl rand -hex 10`}
222 222
 
223
+LOGFILE=${LOGFILE:-"$PWD/stack.sh.$$.log"}
224
+(
225
+# So that errors don't compound we exit on any errors so you see only the
226
+# first error that occured.
227
+trap failed ERR
228
+failed() {
229
+    local r=$?
230
+    set +o xtrace
231
+    [ -n "$LOGFILE" ] && echo "${0##*/} failed: full log in $LOGFILE"
232
+    exit $r
233
+}
234
+
235
+# Print the commands being run so that we can see the command that triggers
236
+# an error.  It is also useful for following along as the install occurs.
237
+set -o xtrace
238
+
239
+sudo mkdir -p $DEST
240
+sudo chown `whoami` $DEST
223 241
 
224 242
 # Install Packages
225 243
 # ================
... ...
@@ -228,6 +239,7 @@ ADMIN_PASSWORD=${ADMIN_PASSWORD:-`openssl rand -hex 10`}
228 228
 
229 229
 
230 230
 # install apt requirements
231
+sudo apt-get update
231 232
 sudo apt-get install -qqy `cat $FILES/apts/* | cut -d\# -f1 | grep -Ev "mysql-server|rabbitmq-server"`
232 233
 
233 234
 # install python requirements
... ...
@@ -584,9 +596,8 @@ fi
584 584
 # have to do a little more than that in our script.  Since we add the group
585 585
 # ``libvirtd`` to our user in this script, when nova-compute is run it is
586 586
 # within the context of our original shell (so our groups won't be updated).
587
-# We can send the command nova-compute to the ``newgrp`` command to execute
588
-# in a specific context.
589
-screen_it n-cpu "cd $NOVA_DIR && echo $NOVA_DIR/bin/nova-compute | newgrp libvirtd"
587
+# Use 'sg' to execute nova-compute as a member of the libvirtd group.
588
+screen_it n-cpu "cd $NOVA_DIR && sg libvirtd $NOVA_DIR/bin/nova-compute"
590 589
 screen_it n-net "cd $NOVA_DIR && $NOVA_DIR/bin/nova-network"
591 590
 screen_it n-sch "cd $NOVA_DIR && $NOVA_DIR/bin/nova-scheduler"
592 591
 screen_it n-vnc "cd $NOVNC_DIR && ./utils/nova-wsproxy.py 6080 --web . --flagfile=../nova/bin/nova.conf"
... ...
@@ -646,6 +657,16 @@ if [[ "$ENABLED_SERVICES" =~ "g-reg" ]]; then
646 646
 
647 647
 fi
648 648
 
649
+# Fin
650
+# ===
651
+
652
+
653
+) 2>&1 | tee "${LOGFILE}"
654
+
655
+# Check that the left side of the above pipe succeeded
656
+for ret in "${PIPESTATUS[@]}"; do [ $ret -eq 0 ] || exit $ret; done
657
+
658
+(
649 659
 # Using the cloud
650 660
 # ===============
651 661
 
... ...
@@ -663,10 +684,7 @@ if [[ "$ENABLED_SERVICES" =~ "key" ]]; then
663 663
     echo "the password: $ADMIN_PASSWORD"
664 664
 fi
665 665
 
666
-# Fin
667
-# ===
666
+# indicate how long this took to run (bash maintained variable 'SECONDS')
667
+echo "stack.sh completed in $SECONDS seconds."
668 668
 
669
-# End our timer and give a timing summary
670
-END_TIME=`python -c "import time; print time.time()"`
671
-ELAPSED=`python -c "print $END_TIME - $START_TIME"`
672
-echo "stack.sh completed in $ELAPSED seconds."
669
+) | tee -a "$LOGFILE"