#!/bin/bash

install_prefix=/root/wdd/install

echo "运行前确保所有虚拟机都已经启动，IP网卡正常可互通"

#重启镜像服务
echo "恢复镜像服务"
docker-compose -f /root/wdd/harbor/docker-compose.yml up -d
echo "等待10s"
sleep 10s

# 关停所有的后端服务
kubectl --kubeconfig /root/.kube/config delete -f ${install_prefix}/k8s-mysql.yaml
kubectl --kubeconfig /root/.kube/config delete -f ${install_prefix}/k8s-nacos.yaml
kubectl --kubeconfig /root/.kube/config delete -f ${install_prefix}/k8s-backend.yaml

echo "重启本机nginx服务"
systemctl stop nginx && sleep 3 && systemctl start nginx
docker-compose -f ${install_prefix}/nginx-docker-compose.yaml up -d

echo "等待10s 开始启动全部的服务"
kubectl --kubeconfig /root/.kube/config apply -f ${install_prefix}/k8s-mysql.yaml
echo "等待360s， 等待mysql启动！"
sleep 360s
kubectl --kubeconfig /root/.kube/config apply -f ${install_prefix}/k8s-nacos.yaml
sleep 30s
echo "等待30s，等待nacos启动！"


kubectl --kubeconfig /root/.kube/config apply -f ${install_prefix}/k8s-backend.yaml
echo "等待 10min"
sleep 10m

kubectl --kubeconfig /root/.kube/config -n bjtg get pods | grep Off | awk '{print$1}' | xargs kubectl --kubeconfig /root/.kube/config -n bjtg delete pod

echo "等待2分钟,确保服务都完全启动"
sleep 2m

kubectl --kubeconfig /root/.kube/config get pods -A

echo "确认上文输出都是running"
echo "可登录平台进行验证"
