Browse code

Add a service_check function

There is no function to check if the services invoked by devstack are
running well or not. We could use the function to check their status
and print them at the end of devstack running.

Change-Id: I845f6b5dddce5cffa7165ec58517f9ae5d8632a6

jiajun xu authored on 2012/12/06 17:30:57
Showing 2 changed files
... ...
@@ -684,6 +684,8 @@ function restart_service() {
684 684
 function screen_it {
685 685
     NL=`echo -ne '\015'`
686 686
     SCREEN_NAME=${SCREEN_NAME:-stack}
687
+    SERVICE_DIR=${SERVICE_DIR:-${DEST}/status}
688
+
687 689
     if is_service_enabled $1; then
688 690
         # Append the service to the screen rc file
689 691
         screen_rc "$1" "$2"
... ...
@@ -699,7 +701,7 @@ function screen_it {
699 699
             screen -S $SCREEN_NAME -p $1 -X log on
700 700
             ln -sf ${SCREEN_LOGDIR}/screen-${1}.${CURRENT_LOG_TIME}.log ${SCREEN_LOGDIR}/screen-${1}.log
701 701
         fi
702
-        screen -S $SCREEN_NAME -p $1 -X stuff "$2$NL"
702
+        screen -S $SCREEN_NAME -p $1 -X stuff "$2 || touch \"$SERVICE_DIR/$SCREEN_NAME/$1.failure\"$NL"
703 703
     fi
704 704
 }
705 705
 
... ...
@@ -724,6 +726,47 @@ function screen_rc {
724 724
     fi
725 725
 }
726 726
 
727
+# Helper to remove the *.failure files under $SERVICE_DIR/$SCREEN_NAME
728
+# This is used for service_check when all the screen_it are called finished
729
+# init_service_check
730
+function init_service_check() {
731
+    SCREEN_NAME=${SCREEN_NAME:-stack}
732
+    SERVICE_DIR=${SERVICE_DIR:-${DEST}/status}
733
+
734
+    if [[ ! -d "$SERVICE_DIR/$SCREEN_NAME" ]]; then
735
+        mkdir -p "$SERVICE_DIR/$SCREEN_NAME"
736
+    fi
737
+
738
+    rm -f "$SERVICE_DIR/$SCREEN_NAME"/*.failure
739
+}
740
+
741
+# Helper to get the status of each running service
742
+# service_check
743
+function service_check() {
744
+    local service
745
+    local failures
746
+    SCREEN_NAME=${SCREEN_NAME:-stack}
747
+    SERVICE_DIR=${SERVICE_DIR:-${DEST}/status}
748
+
749
+
750
+    if [[ ! -d "$SERVICE_DIR/$SCREEN_NAME" ]]; then
751
+        echo "No service status directory found"
752
+        return
753
+    fi
754
+
755
+    # Check if there is any falure flag file under $SERVICE_DIR/$SCREEN_NAME
756
+    failures=`ls "$SERVICE_DIR/$SCREEN_NAME"/*.failure 2>/dev/null`
757
+
758
+    for service in $failures; do
759
+        service=`basename $service`
760
+        service=${service::-8}
761
+        echo "Error: Service $service is not running"
762
+    done
763
+
764
+    if [ -n "$failures" ]; then
765
+        echo "More details about the above errors can be found with screen, with ./rejoin-stack.sh"
766
+    fi
767
+}
727 768
 
728 769
 # ``pip install`` the dependencies of the package before ``setup.py develop``
729 770
 # so pip and not distutils processes the dependency chain
... ...
@@ -954,6 +954,8 @@ sleep 1
954 954
 # Set a reasonable status bar
955 955
 screen -r $SCREEN_NAME -X hardstatus alwayslastline "$SCREEN_HARDSTATUS"
956 956
 
957
+# Initialize the directory for service status check
958
+init_service_check
957 959
 
958 960
 # Keystone
959 961
 # --------
... ...
@@ -1726,6 +1728,8 @@ if [[ -x $TOP_DIR/local.sh ]]; then
1726 1726
     $TOP_DIR/local.sh
1727 1727
 fi
1728 1728
 
1729
+# Check the status of running services
1730
+service_check
1729 1731
 
1730 1732
 # Fin
1731 1733
 # ===