first_time_run.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/bin/bash
  2. # Deploy docker service.
  3. docker stack deploy -c mariadb.yml mariadb
  4. # Read functions
  5. source /opt/linux/scripts/functions/docker/check_container_healthy.sh
  6. source /opt/linux/scripts/functions/docker/array_count_unique.sh
  7. # Load mariadb-seed service
  8. echo "--------- mariadb_seed health check -----------"
  9. unset health_status; counter=1; condition1=0; condition2=0
  10. while [[ $condition1 != 1 ]] || [[ $condition2 != healthy ]]
  11. do
  12. echo "$counter. sek"
  13. counter=$(( $counter + 1 ))
  14. sleep 1
  15. # mariadb_seed health.status kontroll
  16. res=$(check_container_healthy mariadb_seed)
  17. IFS=' ' read -r -a health_status <<< "$res"; # declare -p health_status;
  18. # 1. condition1
  19. condition1=$(array_count_unique ${health_status[@]})
  20. echo "Erinevate elementide arv SEED vektoris: $condition1"
  21. # 2. condition2
  22. condition2=${health_status[0]}
  23. echo "Health Status SEED vektoris: ${condition2[0]}"
  24. done
  25. sleep 2
  26. # Load mariadb_node service
  27. echo "--------- mariadb_node health check -----------"
  28. unset health_status; counter=1; condition1=0; condition2=0
  29. while [[ $condition1 != 1 ]] || [[ $condition2 != healthy ]]
  30. do
  31. echo "$counter. sek"
  32. counter=$(( $counter + 1 ))
  33. sleep 1
  34. # mariadb_node health.status kontroll
  35. res=$(check_container_healthy mariadb_node)
  36. IFS=' ' read -r -a health_status <<< "$res"; # declare -p health_status;
  37. # 1. condition1
  38. condition1=$(array_count_unique ${health_status[@]})
  39. echo "Erinevate elementide arv NODE vektoris: $condition1"
  40. # 2. condition2
  41. condition2=${health_status[0]}
  42. echo "Health Status NODE vektoris: ${condition2[0]}"
  43. done
  44. # Increace mariadb_node replices to 2
  45. echo "--------- mariadb_node scale to 2 -----------"
  46. docker service scale $(docker service ls -f name=mariadb_node -q)=2
  47. # Check mariadb_node status to decreace mariadb_seed replices to 0
  48. echo "--------- mariadb_node health check -----------"
  49. unset health_status; counter=1; condition1=0; condition2=0
  50. while [[ $condition1 != 1 ]] || [[ $condition2 != healthy ]]
  51. do
  52. echo "$counter. sek"
  53. counter=$(( $counter + 1 ))
  54. sleep 1
  55. # mariadb_node health.status kontroll
  56. res=$(check_container_healthy mariadb_node)
  57. IFS=' ' read -r -a health_status <<< "$res"; # declare -p health_status;
  58. # 1. condition1
  59. condition1=$(array_count_unique ${health_status[@]})
  60. echo "Erinevate elementide arv NODE vektoris: $condition1"
  61. # 2. condition2
  62. condition2=${health_status[0]}
  63. echo "Health Status NODE vektoris: ${condition2[0]}"
  64. done
  65. sleep 2
  66. # Decreace mariadb_seed replices to 0.
  67. echo "--------- mariadb_seed scale to 0 -----------"
  68. docker service scale $(docker service ls -f name=mariadb_seed -q)=0
  69. # Check mariadb_seed status to icreace mariadb_node replices to 3
  70. echo "--------- mariadb_seed health check -----------"
  71. unset health_status; counter=1; condition1=0; condition2=0
  72. while [[ $condition1 != 3 ]] || [[ $condition2 != no ]]
  73. do
  74. echo "$counter. sek"
  75. counter=$(( $counter + 1 ))
  76. sleep 1
  77. # mariadb_seed health.status kontroll
  78. res=$(check_container_healthy mariadb_seed)
  79. IFS=' ' read -r -a health_status <<< "$res"; # declare -p health_status;
  80. # 1. condition1
  81. condition1=$(array_count_unique ${health_status[@]})
  82. echo "Erinevate elementide arv SEED vektoris: $condition1"
  83. # 2. condition2
  84. condition2=${health_status[0]}
  85. echo "Health Status SEED vektoris: ${condition2[0]}"
  86. done
  87. sleep 2
  88. # Increace mariadb_node replices to 3
  89. echo "--------- mariadb_node scale to 3 -----------"
  90. docker service scale $(docker service ls -f name=mariadb_node -q)=3
  91. # End
  92. echo "------------------- End --------------------"