Browse code

log output of stack.sh to logfile in current dir

use the variable LOGFILE to log stack.sh output for debugging

Scott Moser authored on 2011/10/07 22:50:21
Showing 1 changed files
... ...
@@ -40,6 +40,52 @@ 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
+
43 89
 # OpenStack is designed to be run as a regular user (Dashboard will fail to run
44 90
 # as root, since apache refused to startup serve content from root user).  If
45 91
 # stack.sh is run as root, it automatically creates a stack user with
... ...
@@ -51,7 +97,7 @@ if [[ $EUID -eq 0 ]]; then
51 51
     # since this script runs as a normal user, we need to give that user
52 52
     # ability to run sudo
53 53
     apt-get update
54
-    apt-get install -qqy sudo
54
+    apt-get install -y sudo
55 55
 
56 56
     if ! getent passwd | grep -q stack; then
57 57
         echo "Creating a user called stack"
... ...
@@ -67,51 +113,13 @@ if [[ $EUID -eq 0 ]]; then
67 67
     echo "Running the script as stack in 3 seconds..."
68 68
     sleep 3
69 69
     if [[ "$SHELL_AFTER_RUN" != "no" ]]; then
70
-	exec su -c "cd /home/stack/$THIS_DIR/; bash stack.sh; bash" stack
70
+        exec su -c "cd /home/stack/$THIS_DIR/; bash stack.sh; bash" stack
71 71
     else
72
-	exec su -c "cd /home/stack/$THIS_DIR/; bash stack.sh" stack
72
+        exec su -c "cd /home/stack/$THIS_DIR/; bash stack.sh" stack
73 73
     fi
74 74
     exit 0
75 75
 fi
76 76
 
77
-# So that errors don't compound we exit on any errors so you see only the
78
-# first error that occured.
79
-set -o errexit
80
-
81
-# Print the commands being run so that we can see the command that triggers
82
-# an error.  It is also useful for following allowing as the install occurs.
83
-set -o xtrace
84
-
85
-# Settings
86
-# ========
87
-
88
-# This script is customizable through setting environment variables.  If you
89
-# want to override a setting you can either::
90
-#
91
-#     export MYSQL_PASS=anothersecret
92
-#     ./stack.sh
93
-#
94
-# You can also pass options on a single line ``MYSQL_PASS=simple ./stack.sh``
95
-#
96
-# Additionally, you can put any local variables into a ``localrc`` file, like::
97
-#
98
-#     MYSQL_PASS=anothersecret
99
-#     MYSQL_USER=hellaroot
100
-#
101
-# We try to have sensible defaults, so you should be able to run ``./stack.sh``
102
-# in most cases.
103
-#
104
-# We our settings from ``stackrc``.  This file is distributed with devstack and
105
-# contains locations for what repositories to use.  If you want to use other 
106
-# repositories and branches, you can add your own settings with another file 
107
-# called ``localrc``
108
-#
109
-# If ``localrc`` exists, then ``stackrc`` will load those settings.  This is 
110
-# useful for changing a branch or repostiory to test other versions.  Also you
111
-# can store your other settings like **MYSQL_PASS** or **ADMIN_PASSWORD** instead
112
-# of letting devstack generate random ones for you.
113
-source ./stackrc
114
-
115 77
 # Destination path for installation ``DEST``
116 78
 DEST=${DEST:-/opt/stack}
117 79
 sudo mkdir -p $DEST
... ...
@@ -663,5 +671,16 @@ fi
663 663
 # Fin
664 664
 # ===
665 665
 
666
+
667
+) 2>&1 | tee "${LOGFILE}"
668
+
669
+# because of the way pipes work, the left side of the pipe may
670
+# have failed, but 'tee' will succeed.  We need to check that.
671
+for ret in "${PIPESTATUS[@]}"; do
672
+	[ $ret -eq 0 ] || exit $ret
673
+done
674
+
666 675
 # indicate how long this took to run (bash maintained variable 'SECONDS')
667
-echo "stack.sh completed in $SECONDS seconds."
676
+echo "stack.sh completed in $SECONDS seconds." | tee -a "${LOGFILE}"
677
+
678
+exit 0