declare -A ports=( ["testapi"]="8082" ["reporting"]="8084")
## Urls to check if the modules are deployed or not ?
-#declare -A urls=( ["testapi"]="http://testresults.opnfv.org/test/" \
-# ["reporting"]="http://testresults.opnfv.org/reporting2/reporting/index.html")
-
-declare -A urls=( ["testapi"]="http://localhost:8082/" \
- ["reporting"]="http://testresults.opnfv.org/reporting2/reporting/index.html")
-
+declare -A urls=( ["testapi"]="http://testresults.opnfv.org/test/" \
+ ["reporting"]="http://testresults.opnfv.org/reporting/index.html")
### Functions related to checking.
function is_deploying() {
- echo -e "Checking job statuses"
- for module in "${modules[@]}"
- do
- if get_status $module; then
- exit 0
- fi
- done
-}
-
-function get_status() {
xml=$(curl -m10 "https://build.opnfv.org/ci/job/${1}-automate-master/lastBuild/api/xml?depth=1")
building=$(grep -oPm1 "(?<=<building>)[^<]+" <<< "$xml")
if [[ $building == "false" ]]
then
- return 1
+ false
else
- return 0
+ true
fi
}
echo -e "Docker status: $status"
if [ $status = "active" ]
then
- return 1
+ true
else
- return 0
+ false
fi
}
cmd=`curl --head -m10 --request GET ${2} | grep '200 OK' > /dev/null`
rc=$?
if [[ $rc == 0 ]]; then
- return 0
+ true
else
- return 1
+ false
fi
}
failed_modules=()
for module in "${modules[@]}"
do
+ if is_deploying $module; then
+ continue
+ fi
if ! check_connectivity $module "${urls[$module]}"; then
echo -e "$module failed"
failed_modules+=($module)
done
if [ ! -z "$failed_modules" ]; then
echo -e "Failed Modules: $failed_modules"
- return 1
+ false
else
echo -e "All modules working good"
exit 0
echo $pid
if [ ! -z "$pid" ]; then
kill $pid
- start_containers_fix $module
+ start_container_fix $module
fi
done
}
function start_containers_fix() {
- echo "Runnning start_containers_fix"
start_modules=("${@}")
for module in "${start_modules[@]}"
do
- echo -e "Starting a container $module"
+ start_container_fix $module
+ done
+}
+
+function start_container_fix() {
+ echo -e "Starting a container $module"
+ sudo docker stop $module
+ sudo docker start $module
+ sleep 5
+ if ! check_connectivity $module "${urls[$module]}"; then
+ echo -e "Starting an old container $module_old"
sudo docker stop $module
- sudo docker start $module
+ sudo docker start $module"_old"
sleep 5
- if ! check_connectivity $module "${urls[$module]}"; then
- echo -e "Starting an old container $module_old"
- sudo docker stop $module
- sudo docker start $module"_old"
- sleep 5
- fi
- done
+ fi
}
### Main Flow
echo -e `date "+%Y-%m-%d %H:%M:%S.%N"`
echo -e
-if ! is_deploying; then
- echo -e "Jenkins Jobs running"
- exit
-fi
-
## If the problem is related to docker daemon
-if get_docker_status; then
+if ! get_docker_status; then
restart_docker_fix
if ! check_modules; then
echo -e "Watchdog failed while restart_docker_fix"
exit
fi
-## If the problem is related to docker containers
+## If the problem is related to docker proxy
if ! check_modules; then
- start_containers_fix "${failed_modules[@]}"
+ docker_proxy_fix "${failed_modules[@]}"
fi
-## If the problem is related to docker proxy
+## If any other problem : restart docker
if ! check_modules; then
- docker_proxy_fix "${failed_modules[@]}"
+ restart_docker_fix
fi
## If nothing works out