-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathstart-db2-container.sh
87 lines (74 loc) · 2.43 KB
/
start-db2-container.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
if [ "$NS" == "" ]; then
echo "Using default namespace"
export NS=default
fi
export POD_NAME=db2-test-pod
kubectl get pods -n ${NS}
echo "Checking for previous component test leftovers at " `date`
kubectl get -n ${NS} Pod/${POD_NAME}
if [ "$?" == "0" ]; then
echo "Found pod; deleting it at " `date`
kubectl delete -n ${NS} Pod/${POD_NAME}
for i in `seq 1 24`
do
podName=`kubectl get -n ${NS} -l app=${POD_NAME} pod -o name`
if [ "$podName" == "" ]; then
echo "Pods not running at " `date`
rc=0
break
else
echo "Found pod $podName at " `date`
fi
sleep 5
done
sleep 10
else
echo "No pod found at " `date`
fi
echo "Creating DB2 container for component test at " `date`
cat /work/ace-demo-pipeline/tekton/temp-db2/db2-test-pod.yaml | sed 's/PASSWORD_REPLACEMENT_STRING/SecurePassw0rd/g' | kubectl apply -f -
rc=1
echo "Starting polling for container start at " `date`
for i in `seq 1 120`
do
kubectl logs -n ${NS} Pod/${POD_NAME} | head -n 20 | grep "Creating"
if [ "$?" == "0" ]; then
echo "Container is ready at " `date`
rc=0
break
fi
if [ $( expr $i % 6 ) == "0" ]; then
echo "Still waiting after" $( expr $i \* 5 ) "seconds . . ."
fi
sleep 5
done
if [ "$rc" == "1" ]; then
echo "Container start failed; giving up at " `date`
echo "Current logs from the pod:"
echo "----------------------------------------"
kubectl logs -n ${NS} Pod/${POD_NAME}
echo "----------------------------------------"
return 1
fi
echo "Setting up auto-shutdown script at " `date`
scriptFile=$(mktemp)
cat <<EOF > $scriptFile
#!/bin/bash
# Create second script to shut the container down after 30 minutes
echo "#!/bin/bash" > /tmp/timed-shutdown.sh
echo 'echo "### Sleeping for 1800 seconds" >> /proc/1/fd/1' >> /tmp/timed-shutdown.sh
echo "sleep 1800" >> /tmp/timed-shutdown.sh
echo 'echo "### Sending SIGTERM to process 1" >> /proc/1/fd/1' >> /tmp/timed-shutdown.sh
echo "kill -TERM 1" >> /tmp/timed-shutdown.sh
chmod 775 /tmp/timed-shutdown.sh
echo "### Starting timed shutdown script" >> /proc/1/fd/1
cd /tmp
echo "" | nohup /tmp/timed-shutdown.sh > /dev/null 2>&1 &
echo "Timer script launched; exiting"
EOF
#cat $scriptFile
chmod 775 $scriptFile
kubectl cp $scriptFile ${NS}/${POD_NAME}:/tmp/shutdown-script.sh
kubectl exec db2-test-pod -- /tmp/shutdown-script.sh
rm $scriptFile