Advertisement
gregmark

OpenStack or Bust, Part 5: test_stack script

Mar 6th, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.52 KB | None | 0 0
  1. #!/bin/bash
  2. ### ----------
  3. ### test_stack
  4. ### ----------
  5. ###
  6. ### AUTH: Greg Chavez, greg.chavez@gmail.com
  7. ###
  8. ### DESC: Prints out complete status of each OpenStack daemon configured
  9. ###       in the QUADS array, including:
  10. ###
  11. ###            1) service daemon status
  12. ###            2) date/time of most recent successful start
  13. ###            3) all error log messages since the last start
  14. ###
  15.  
  16. ######################################################################
  17. ### CONFIGURE HERE
  18. ######################################################################
  19.  
  20. # For each daemon, fill out a single line with four space-separated
  21. # array values:
  22. #     1) Service code name (nova, quantum, etc.)
  23. #     2) Service name as it appears in /etc/init.d
  24. #     3) Log filename (ommit directory)
  25. #     4) Log line that indicates a successful service start (must be
  26. #        quoted!)
  27. #
  28. # NB: Blank lines are ignored
  29.  
  30. QUADS=(
  31.  
  32. nova nova-api nova-api.log "wsgi starting up"
  33. nova nova-scheduler nova-scheduler.log "Starting scheduler node"
  34.  
  35. glance glance-api api.log "Using /var/lib/glance/keystone-signing as cache directory for signing certificate"
  36. glance glance-registry registry.log "Using /var/lib/glance/keystone-signing as cache directory for signing certificate"
  37.  
  38. quantum quantum-server server.log "wsgi starting up"
  39.  
  40. cinder cinder-api cinder-api.log "Started osapi_volume on"
  41. cinder cinder-scheduler cinder-scheduler.log "Creating Consumer connection for Service cinder-scheduler start"
  42. cinder cinder-volume cinder-volume.log "Creating Consumer connection for Service cinder-volume start"
  43.  
  44. )
  45.  
  46.  
  47. ######################################################################
  48. ### Colors
  49. ######################################################################
  50. txtbld=$(tput bold)     # Bold
  51. bldred=${txtbld}$(tput setaf 1) # Red
  52. bldgrn=${txtbld}$(tput setaf 2) # Green
  53. bldylw=${txtbld}$(tput setaf 3) # Yellow
  54. txtrst=$(tput sgr0)     # Reset
  55.  
  56.  
  57. ######################################################################
  58. ### Functions
  59. ######################################################################
  60.  
  61. function stat_me {
  62.  
  63.     CN=$1       # Code Name
  64.     SN=$2       # Service Name
  65.     LF=$3       # Log File
  66.     SM="$4"     # Start Message
  67.  
  68.     log="/var/log/${CN:-xxx}/${LF:-xxx}"
  69.     err=0
  70.  
  71.     if [ ! -f "/etc/init.d/$SN" ]; then
  72.         echo "${bldylw}ERR: Service $SN not found${txtrst}"
  73.         err=1
  74.     elif [ ! -r $log ]; then
  75.         echo "${bldylw}ERR: Log $log not found${txtrst}"
  76.         err=1
  77.     fi
  78.     [ $err -gt 0 ] && return $err
  79.  
  80.     LG=$(grep -n "$SM" $log | tail -1)      # log line
  81.     LN=$(echo $LG| awk -F: '{print $1}')        # line number
  82.     ERR=$(awk 'NR > ln && /ERR/' ln=$LN $log)   # err messages
  83.  
  84.     if service $SN status | grep -q running 2>/dev/null ; then
  85.         ST=${bldgrn}OK${txtrst}
  86.     else
  87.         ST=${bldred}FAILED${txtrst}
  88.     fi
  89.  
  90.     printf "%-15s%s\n" "SERVICE:" "$SN"
  91.     printf "%-15s%s\n" "STATUS:" "$ST"
  92.     printf "%-15s" "LAST START:"; echo ${LG:-none} | sed "s/^$LN://" | awk '{print $1, $2}'
  93.     echo "ERRORS:"; [ -n "$ERR" ] && echo "$ERR" | sed 's/^/    /'
  94.     echo "--------------------------------------------------"
  95.  
  96. }
  97.  
  98.  
  99. ######################################################################
  100. ### Main
  101. ######################################################################
  102.  
  103. echo "--------------------------------------------------"
  104. idx=0
  105. for Q in "${QUADS[@]}"; do
  106.     if [ $idx == 0 ]; then
  107.         code=$Q
  108.     elif [ $idx == 1 ]; then
  109.         svc=$Q
  110.     elif [ $idx == 2 ]; then
  111.         log=$Q
  112.     elif [ $idx == 3 ]; then
  113.         msg="$Q"
  114.         stat_me $code $svc $log "$msg"
  115.         idx=0
  116.         continue
  117.     fi
  118.     let "idx += 1"
  119. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement