Browse code

Add non-verbose output mode

Set VERBOSE=False to turn off the noise of stack.sh output. All
output still is written to the logfile if LOGFILE is set.

Rebased

Change-Id: I316bc4d68c997ec907a48e720e2f7778428d935b

Dean Troyer authored on 2012/09/14 07:16:12
Showing 7 changed files
... ...
@@ -16,9 +16,9 @@
16 16
 # stop_XXX
17 17
 # cleanup_XXX
18 18
 
19
-# Print the commands being run so that we can see the command that triggers
20
-# an error.  It is also useful for following along as the install occurs.
21
-set -o xtrace
19
+# Save trace setting
20
+XTRACE=$(set +o | grep xtrace)
21
+set +o xtrace
22 22
 
23 23
 
24 24
 # Defaults
... ...
@@ -71,3 +71,6 @@ function start_ceilometer() {
71 71
     screen_it ceilometer-collector "cd $CEILOMETER_DIR && $CEILOMETER_BIN_DIR/ceilometer-collector --config-file $CEILOMETER_COLLECTOR_CONF"
72 72
     screen_it ceilometer-api "cd $CEILOMETER_DIR && $CEILOMETER_BIN_DIR/ceilometer-api -d -v --log-dir=$CEILOMETER_API_LOG_DIR"
73 73
 }
74
+
75
+# Restore xtrace
76
+$XTRACE
... ...
@@ -16,9 +16,9 @@
16 16
 # stop_XXX
17 17
 # cleanup_XXX
18 18
 
19
-# Print the commands being run so that we can see the command that triggers
20
-# an error.  It is also useful for following along as the install occurs.
21
-set -o xtrace
19
+# Save trace setting
20
+XTRACE=$(set +o | grep xtrace)
21
+set +o xtrace
22 22
 
23 23
 
24 24
 # Defaults
... ...
@@ -233,3 +233,6 @@ function stop_cinder() {
233 233
         stop_service tgt
234 234
     fi
235 235
 }
236
+
237
+# Restore xtrace
238
+$XTRACE
... ...
@@ -15,9 +15,9 @@
15 15
 # stop_XXX
16 16
 # cleanup_XXX
17 17
 
18
-# Print the commands being run so that we can see the command that triggers
19
-# an error.  It is also useful for following along as the install occurs.
20
-set -o xtrace
18
+# Save trace setting
19
+XTRACE=$(set +o | grep xtrace)
20
+set +o xtrace
21 21
 
22 22
 
23 23
 # Defaults
... ...
@@ -178,3 +178,6 @@ function stop_heat() {
178 178
     # This function intentionally left blank
179 179
     :
180 180
 }
181
+
182
+# Restore xtrace
183
+$XTRACE
... ...
@@ -18,9 +18,9 @@
18 18
 # stop_keystone
19 19
 # cleanup_keystone
20 20
 
21
-# Print the commands being run so that we can see the command that triggers
22
-# an error.  It is also useful for following along as the install occurs.
23
-set -o xtrace
21
+# Save trace setting
22
+XTRACE=$(set +o | grep xtrace)
23
+set +o xtrace
24 24
 
25 25
 
26 26
 # Defaults
... ...
@@ -170,3 +170,6 @@ function stop_keystone() {
170 170
     # Kill the Keystone screen window
171 171
     screen -S $SCREEN_NAME -p key -X kill
172 172
 }
173
+
174
+# Restore xtrace
175
+$XTRACE
... ...
@@ -18,9 +18,9 @@
18 18
 # stop_nvol
19 19
 # cleanup_nvol
20 20
 
21
-# Print the commands being run so that we can see the command that triggers
22
-# an error.  It is also useful for following along as the install occurs.
23
-set -o xtrace
21
+# Save trace setting
22
+XTRACE=$(set +o | grep xtrace)
23
+set +o xtrace
24 24
 
25 25
 
26 26
 # Defaults
... ...
@@ -120,3 +120,6 @@ function stop_nvol() {
120 120
 
121 121
     stop_service tgt
122 122
 }
123
+
124
+# Restore xtrace
125
+$XTRACE
... ...
@@ -16,9 +16,9 @@
16 16
 # stop_XXXX
17 17
 # cleanup_XXXX
18 18
 
19
-# Print the commands being run so that we can see the command that triggers
20
-# an error.  It is also useful for following along as the install occurs.
21
-set -o xtrace
19
+# Save trace setting
20
+XTRACE=$(set +o | grep xtrace)
21
+set +o xtrace
22 22
 
23 23
 
24 24
 # Defaults
... ...
@@ -75,3 +75,6 @@ function stop_XXXX() {
75 75
     # FIXME(dtroyer): stop only our screen screen window?
76 76
     :
77 77
 }
78
+
79
+# Restore xtrace
80
+$XTRACE
... ...
@@ -166,6 +166,9 @@ if is_service_enabled cinder && is_service_enabled n-vol; then
166 166
     exit 1
167 167
 fi
168 168
 
169
+# Set up logging level
170
+VERBOSE=$(trueorfalse True $VERBOSE)
171
+
169 172
 
170 173
 # root Access
171 174
 # -----------
... ...
@@ -380,6 +383,7 @@ SCHEDULER=${SCHEDULER:-nova.scheduler.filter_scheduler.FilterScheduler}
380 380
 
381 381
 # Generic helper to configure passwords
382 382
 function read_password {
383
+    XTRACE=$(set +o | grep xtrace)
383 384
     set +o xtrace
384 385
     var=$1; msg=$2
385 386
     pw=${!var}
... ...
@@ -416,7 +420,7 @@ function read_password {
416 416
         eval "$var=$pw"
417 417
         echo "$var=$pw" >> $localrc
418 418
     fi
419
-    set -o xtrace
419
+    $XTRACE
420 420
 }
421 421
 
422 422
 
... ...
@@ -599,6 +603,18 @@ APACHE_GROUP=${APACHE_GROUP:-$APACHE_USER}
599 599
 # Log files
600 600
 # ---------
601 601
 
602
+# Echo text to the log file, summary log file and stdout
603
+# echo_summary "something to say"
604
+function echo_summary() {
605
+    echo $@ >&6
606
+}
607
+
608
+# Echo text only to stdout, no log files
609
+# echo_nolog "something not for the logs"
610
+function echo_nolog() {
611
+    echo $@ >&3
612
+}
613
+
602 614
 # Set up logging for ``stack.sh``
603 615
 # Set ``LOGFILE`` to turn on logging
604 616
 # Append '.xxxxxxxx' to the given name to maintain history
... ...
@@ -617,13 +633,38 @@ if [[ -n "$LOGFILE" ]]; then
617 617
     LOGNAME=$(basename "$LOGFILE")
618 618
     mkdir -p $LOGDIR
619 619
     find $LOGDIR -maxdepth 1 -name $LOGNAME.\* -mtime +$LOGDAYS -exec rm {} \;
620
-
621 620
     LOGFILE=$LOGFILE.${CURRENT_LOG_TIME}
622
-    # Redirect stdout/stderr to tee to write the log file
623
-    exec 1> >( tee "${LOGFILE}" ) 2>&1
624
-    echo "stack.sh log $LOGFILE"
621
+    SUMFILE=$LOGFILE.${CURRENT_LOG_TIME}.summary
622
+
623
+    # Redirect output according to config
624
+    # Copy stdout to fd 3
625
+    exec 3>&1
626
+    if [[ "$VERBOSE" == "True" ]]; then
627
+        # Redirect stdout/stderr to tee to write the log file
628
+        exec 1> >( tee "${LOGFILE}" ) 2>&1
629
+        # Set up a second fd for output
630
+        exec 6> >( tee "${SUMFILE}" )
631
+    else
632
+        # Set fd 1 and 2 to primary logfile
633
+        exec 1> "${LOGFILE}" 2>&1
634
+        # Set fd 6 to summary logfile and stdout
635
+        exec 6> >( tee "${SUMFILE}" /dev/fd/3 )
636
+    fi
637
+
638
+    echo_summary "stack.sh log $LOGFILE"
625 639
     # Specified logfile name always links to the most recent log
626 640
     ln -sf $LOGFILE $LOGDIR/$LOGNAME
641
+    ln -sf $SUMFILE $LOGDIR/$LOGNAME.summary
642
+else
643
+    # Set up output redirection without log files
644
+    # Copy stdout to fd 3
645
+    exec 3>&1
646
+    if [[ "$VERBOSE" != "yes" ]]; then
647
+        # Throw away stdout and stderr
648
+        exec 1>/dev/null 2>&1
649
+    fi
650
+    # Always send summary fd to original stdout
651
+    exec 6>&3
627 652
 fi
628 653
 
629 654
 # Set up logging of screen windows
... ...
@@ -667,6 +708,7 @@ set -o xtrace
667 667
 # OpenStack uses a fair number of other projects.
668 668
 
669 669
 # Install package requirements
670
+echo_summary "Installing package prerequisites"
670 671
 if [[ "$os_PACKAGE" = "deb" ]]; then
671 672
     install_package $(get_packages $FILES/apts)
672 673
 else
... ...
@@ -785,6 +827,7 @@ TRACK_DEPENDS=${TRACK_DEPENDS:-False}
785 785
 
786 786
 # Install python packages into a virtualenv so that we can track them
787 787
 if [[ $TRACK_DEPENDS = True ]] ; then
788
+    echo_summary "Installing Python packages into a virtualenv $DEST/.venv"
788 789
     install_package python-virtualenv
789 790
 
790 791
     rm -rf $DEST/.venv
... ...
@@ -794,12 +837,15 @@ if [[ $TRACK_DEPENDS = True ]] ; then
794 794
 fi
795 795
 
796 796
 # Install python requirements
797
+echo_summary "Installing Python prerequisites"
797 798
 pip_install $(get_packages $FILES/pips | sort -u)
798 799
 
799 800
 
800 801
 # Check Out Source
801 802
 # ----------------
802 803
 
804
+echo_summary "Installing OpenStack project source"
805
+
803 806
 install_keystoneclient
804 807
 
805 808
 git_clone $NOVA_REPO $NOVA_DIR $NOVA_BRANCH
... ...
@@ -857,6 +903,8 @@ fi
857 857
 # Initialization
858 858
 # ==============
859 859
 
860
+echo_summary "Configuring OpenStack projects"
861
+
860 862
 # Set up our checkouts so they are installed into python path
861 863
 # allowing ``import nova`` or ``import glance.client``
862 864
 configure_keystoneclient
... ...
@@ -923,6 +971,7 @@ EOF
923 923
 EOF
924 924
         sudo mv /tmp/90-stack-s.conf /etc/rsyslog.d
925 925
     fi
926
+    echo_summary "Starting rsyslog"
926 927
     restart_service rsyslog
927 928
 fi
928 929
 
... ...
@@ -932,6 +981,7 @@ fi
932 932
 
933 933
 if is_service_enabled rabbit; then
934 934
     # Start rabbitmq-server
935
+    echo_summary "Starting RabbitMQ"
935 936
     if [[ "$os_PACKAGE" = "rpm" ]]; then
936 937
         # RPM doesn't start the service
937 938
         restart_service rabbitmq-server
... ...
@@ -939,6 +989,7 @@ if is_service_enabled rabbit; then
939 939
     # change the rabbit password since the default is "guest"
940 940
     sudo rabbitmqctl change_password guest $RABBIT_PASSWORD
941 941
 elif is_service_enabled qpid; then
942
+    echo_summary "Starting qpid"
942 943
     restart_service qpidd
943 944
 fi
944 945
 
... ...
@@ -947,6 +998,7 @@ fi
947 947
 # -----
948 948
 
949 949
 if is_service_enabled mysql; then
950
+    echo_summary "Configuring and starting MySQL"
950 951
 
951 952
     # Start mysql-server
952 953
     if [[ "$os_PACKAGE" = "rpm" ]]; then
... ...
@@ -998,6 +1050,7 @@ screen -r $SCREEN_NAME -X hardstatus alwayslastline "$SCREEN_HARDSTATUS"
998 998
 # --------
999 999
 
1000 1000
 if is_service_enabled key; then
1001
+    echo_summary "Starting Keystone"
1001 1002
     configure_keystone
1002 1003
     init_keystone
1003 1004
     start_keystone
... ...
@@ -1030,6 +1083,7 @@ fi
1030 1030
 # Set up the django horizon application to serve via apache/wsgi
1031 1031
 
1032 1032
 if is_service_enabled horizon; then
1033
+    echo_summary "Configuring and starting Horizon"
1033 1034
 
1034 1035
     # Remove stale session database.
1035 1036
     rm -f $HORIZON_DIR/openstack_dashboard/local/dashboard_openstack.sqlite3
... ...
@@ -1079,6 +1133,8 @@ fi
1079 1079
 # ------
1080 1080
 
1081 1081
 if is_service_enabled g-reg; then
1082
+    echo_summary "Configuring Glance"
1083
+
1082 1084
     GLANCE_CONF_DIR=/etc/glance
1083 1085
     if [[ ! -d $GLANCE_CONF_DIR ]]; then
1084 1086
         sudo mkdir -p $GLANCE_CONF_DIR
... ...
@@ -1174,6 +1230,7 @@ fi
1174 1174
 # -------
1175 1175
 
1176 1176
 if is_service_enabled quantum; then
1177
+    echo_summary "Configuring Quantum"
1177 1178
     #
1178 1179
     # Quantum Network Configuration
1179 1180
     #
... ...
@@ -1469,6 +1526,8 @@ fi
1469 1469
 # Nova
1470 1470
 # ----
1471 1471
 
1472
+echo_summary "Configuring Nova"
1473
+
1472 1474
 # Put config files in ``/etc/nova`` for everyone to find
1473 1475
 NOVA_CONF_DIR=/etc/nova
1474 1476
 if [[ ! -d $NOVA_CONF_DIR ]]; then
... ...
@@ -1676,6 +1735,7 @@ fi
1676 1676
 # ---------------
1677 1677
 
1678 1678
 if is_service_enabled swift; then
1679
+    echo_summary "Configuring Swift"
1679 1680
 
1680 1681
     # Make sure to kill all swift processes first
1681 1682
     swift-init all stop || true
... ...
@@ -1930,8 +1990,10 @@ fi
1930 1930
 # --------------
1931 1931
 
1932 1932
 if is_service_enabled cinder; then
1933
+    echo_summary "Configuring Cinder"
1933 1934
     init_cinder
1934 1935
 elif is_service_enabled n-vol; then
1936
+    echo_summary "Configuring Nova volumes"
1935 1937
     init_nvol
1936 1938
 fi
1937 1939
 
... ...
@@ -2072,6 +2134,7 @@ done
2072 2072
 # ---------
2073 2073
 
2074 2074
 if [ "$VIRT_DRIVER" = 'xenserver' ]; then
2075
+    echo_summary "Using XenServer virtualization driver"
2075 2076
     read_password XENAPI_PASSWORD "ENTER A PASSWORD TO USE FOR XEN."
2076 2077
     add_nova_opt "compute_driver=xenapi.XenAPIDriver"
2077 2078
     XENAPI_CONNECTION_URL=${XENAPI_CONNECTION_URL:-"http://169.254.0.1"}
... ...
@@ -2084,6 +2147,7 @@ if [ "$VIRT_DRIVER" = 'xenserver' ]; then
2084 2084
     XEN_FIREWALL_DRIVER=${XEN_FIREWALL_DRIVER:-"nova.virt.firewall.IptablesFirewallDriver"}
2085 2085
     add_nova_opt "firewall_driver=$XEN_FIREWALL_DRIVER"
2086 2086
 elif [ "$VIRT_DRIVER" = 'openvz' ]; then
2087
+    echo_summary "Using OpenVZ virtualization driver"
2087 2088
     # TODO(deva): OpenVZ driver does not yet work if compute_driver is set here.
2088 2089
     #             Replace connection_type when this is fixed.
2089 2090
     #             add_nova_opt "compute_driver=openvz.connection.OpenVzConnection"
... ...
@@ -2091,6 +2155,7 @@ elif [ "$VIRT_DRIVER" = 'openvz' ]; then
2091 2091
     LIBVIRT_FIREWALL_DRIVER=${LIBVIRT_FIREWALL_DRIVER:-"nova.virt.libvirt.firewall.IptablesFirewallDriver"}
2092 2092
     add_nova_opt "firewall_driver=$LIBVIRT_FIREWALL_DRIVER"
2093 2093
 else
2094
+    echo_summary "Using libvirt virtualization driver"
2094 2095
     add_nova_opt "compute_driver=libvirt.LibvirtDriver"
2095 2096
     LIBVIRT_FIREWALL_DRIVER=${LIBVIRT_FIREWALL_DRIVER:-"nova.virt.libvirt.firewall.IptablesFirewallDriver"}
2096 2097
     add_nova_opt "firewall_driver=$LIBVIRT_FIREWALL_DRIVER"
... ...
@@ -2121,6 +2186,7 @@ fi
2121 2121
 # ----
2122 2122
 
2123 2123
 if is_service_enabled heat; then
2124
+    echo_summary "Configuring Heat"
2124 2125
     init_heat
2125 2126
 fi
2126 2127
 
... ...
@@ -2134,6 +2200,7 @@ fi
2134 2134
 
2135 2135
 # Launch the glance registry service
2136 2136
 if is_service_enabled g-reg; then
2137
+    echo_summary "Starting Glance"
2137 2138
     screen_it g-reg "cd $GLANCE_DIR; $GLANCE_BIN_DIR/glance-registry --config-file=$GLANCE_CONF_DIR/glance-registry.conf"
2138 2139
 fi
2139 2140
 
... ...
@@ -2163,6 +2230,7 @@ screen_it zeromq "cd $NOVA_DIR && $NOVA_DIR/bin/nova-rpc-zmq-receiver"
2163 2163
 
2164 2164
 # Launch the nova-api and wait for it to answer before continuing
2165 2165
 if is_service_enabled n-api; then
2166
+    echo_summary "Starting Nova API"
2166 2167
     add_nova_opt "enabled_apis=$NOVA_ENABLED_APIS"
2167 2168
     screen_it n-api "cd $NOVA_DIR && $NOVA_BIN_DIR/nova-api"
2168 2169
     echo "Waiting for nova-api to start..."
... ...
@@ -2173,6 +2241,7 @@ if is_service_enabled n-api; then
2173 2173
 fi
2174 2174
 
2175 2175
 if is_service_enabled q-svc; then
2176
+    echo_summary "Starting Quantum"
2176 2177
     # Start the Quantum service
2177 2178
     screen_it q-svc "cd $QUANTUM_DIR && python $QUANTUM_DIR/bin/quantum-server --config-file $Q_CONF_FILE --config-file /$Q_PLUGIN_CONF_FILE"
2178 2179
     echo "Waiting for Quantum to start..."
... ...
@@ -2226,6 +2295,7 @@ screen_it q-agt "sudo python $AGENT_BINARY --config-file $Q_CONF_FILE --config-f
2226 2226
 screen_it q-dhcp "sudo python $AGENT_DHCP_BINARY --config-file $Q_CONF_FILE --config-file=$Q_DHCP_CONF_FILE"
2227 2227
 screen_it q-l3 "sudo python $AGENT_L3_BINARY --config-file $Q_CONF_FILE --config-file=$Q_L3_CONF_FILE"
2228 2228
 
2229
+echo_summary "Starting Nova"
2229 2230
 # The group **libvirtd** is added to the current user in this script.
2230 2231
 # Use 'sg' to execute nova-compute as a member of the **libvirtd** group.
2231 2232
 # ``screen_it`` checks ``is_service_enabled``, it is not needed here
... ...
@@ -2237,12 +2307,15 @@ screen_it n-novnc "cd $NOVNC_DIR && ./utils/nova-novncproxy --config-file $NOVA_
2237 2237
 screen_it n-xvnc "cd $NOVA_DIR && ./bin/nova-xvpvncproxy --config-file $NOVA_CONF_DIR/$NOVA_CONF"
2238 2238
 screen_it n-cauth "cd $NOVA_DIR && ./bin/nova-consoleauth"
2239 2239
 if is_service_enabled n-vol; then
2240
+    echo_summary "Starting Nova volumes"
2240 2241
     start_nvol
2241 2242
 fi
2242 2243
 if is_service_enabled cinder; then
2244
+    echo_summary "Starting Cinder"
2243 2245
     start_cinder
2244 2246
 fi
2245 2247
 if is_service_enabled ceilometer; then
2248
+    echo_summary "Starting Ceilometer"
2246 2249
     configure_ceilometer
2247 2250
     start_ceilometer
2248 2251
 fi
... ...
@@ -2256,6 +2329,7 @@ is_service_enabled swift3 || \
2256 2256
 
2257 2257
 # launch heat engine, api and metadata
2258 2258
 if is_service_enabled heat; then
2259
+    echo_summary "Starting Heat"
2259 2260
     start_heat
2260 2261
 fi
2261 2262
 
... ...
@@ -2274,6 +2348,7 @@ fi
2274 2274
 #  * **precise**: http://uec-images.ubuntu.com/precise/current/precise-server-cloudimg-amd64.tar.gz
2275 2275
 
2276 2276
 if is_service_enabled g-reg; then
2277
+    echo_summary "Uploading images"
2277 2278
     TOKEN=$(keystone  token-get | grep ' id ' | get_field 2)
2278 2279
 
2279 2280
     # Option to upload legacy ami-tty, which works with xenserver
... ...
@@ -2302,6 +2377,15 @@ fi
2302 2302
 
2303 2303
 set +o xtrace
2304 2304
 
2305
+if [[ -n "$LOGFILE" ]]; then
2306
+    exec 1>&3
2307
+    # Force all output to stdout and logs now
2308
+    exec 1> >( tee "${LOGFILE}" ) 2>&1
2309
+else
2310
+    # Force all output to stdout now
2311
+    exec 1>&3
2312
+fi
2313
+
2305 2314
 
2306 2315
 # Using the cloud
2307 2316
 # ---------------
... ...
@@ -2329,8 +2413,8 @@ echo "This is your host ip: $HOST_IP"
2329 2329
 
2330 2330
 # Warn that ``EXTRA_FLAGS`` needs to be converted to ``EXTRA_OPTS``
2331 2331
 if [[ -n "$EXTRA_FLAGS" ]]; then
2332
-    echo "WARNING: EXTRA_FLAGS is defined and may need to be converted to EXTRA_OPTS"
2332
+    echo_summary "WARNING: EXTRA_FLAGS is defined and may need to be converted to EXTRA_OPTS"
2333 2333
 fi
2334 2334
 
2335 2335
 # Indicate how long this took to run (bash maintained variable ``SECONDS``)
2336
-echo "stack.sh completed in $SECONDS seconds."
2336
+echo_summary "stack.sh completed in $SECONDS seconds."