-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsync5.sh
executable file
·39 lines (39 loc) · 1.83 KB
/
sync5.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
if [ "$1" = "" ]; then
echo "add clustername to command i.e. ./sync.sh rancher or rke-test, rke-int or rke-prod"
exit 1
fi
if [ "$1" == "rancher" ]; then
CLUSTER_NODES=$(cat /var/lib/containers/storage/volumes/srv-salt/_data/rke-cluster/server.txt|grep $1 |grep -v hostname|cut -f1 -d ",")
else
CLUSTER_NODES=$(cat /var/lib/containers/storage/volumes/srv-salt/_data/rke-cluster/server.txt|grep $1 |grep -v ^rancher |grep -v hostname|cut -f1 -d ",")
fi
DOMAIN=$(cat /var/lib/containers/storage/volumes/srv-salt/_data/rke-cluster/server.txt|grep $1 |grep -v hostname|cut -f2 -d ","|uniq)
CLUSTER_NODES_LIST=$(for CLUSTER_NODE in $CLUSTER_NODES; do echo -n $CLUSTER_NODE.$DOMAIN,; done|sed 's/,$//g')
echo "applying salt-state rke-cluster to: $CLUSTER_NODES_LIST"
podman exec -it uyuni-server salt -L $CLUSTER_NODES_LIST state.apply manager_org_1.rke-cluster
for CLUSTER_NODE in $CLUSTER_NODES; do
ROLE=$(grep $CLUSTER_NODE /var/lib/containers/storage/volumes/srv-salt/_data/rke-cluster/server.txt|cut -f6 -d ",")
echo "checking if node is rebooted after patching"
PATCHED="3"
while [ "$PATCHED" == "3" ]; do
# need to be enhanced - does not work in case there are no patches that require a reboot
echo "PATCHED for $CLUSTER_NODE.$DOMAIN is $PATCHED"
PATCHED=$(podman exec -it uyuni-server salt $CLUSTER_NODE.$DOMAIN cmd.shell "last reboot"|wc -l)
echo "PATCHED for $CLUSTER_NODE.$DOMAIN is $PATCHED"
sleep 5
done
echo "executing rke-cluster.sh on server $CLUSTER_NODE"
podman exec -it uyuni-server salt $CLUSTER_NODE.$DOMAIN cmd.shell "bash /home/rkeadmin/rke-cluster/rke-cluster.sh"
if [ "$2" == "nosleep" ]; then
echo "skip sleep"
else
if [ $ROLE == "master1" ] || [ $ROLE == "master" ]; then
echo "master deployed - waiting 60 seconds"
sleep 60
else
echo "worker deployed - waiting 10 seconds"
sleep 10
fi
fi
done