|
20 | 20 | {{- with .Values.affinity }}
|
21 | 21 | affinity: {{- toYaml . | nindent 8}}
|
22 | 22 | {{- end }}
|
| 23 | + terminationGracePeriodSeconds: {{ .Values.terminationGracePeriod }} |
23 | 24 | containers:
|
24 | 25 | - name: marklogic-server
|
25 | 26 | image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
|
|
60 | 61 | {{- if .Values.extraContainerPorts }}
|
61 | 62 | {{- toYaml .Values.extraContainerPorts | nindent 12 }}
|
62 | 63 | {{- end }}
|
| 64 | + lifecycle: |
| 65 | + preStop: |
| 66 | + exec: |
| 67 | + command: |
| 68 | + - bash |
| 69 | + - '-c' |
| 70 | + - | |
| 71 | + log () { |
| 72 | + local TIMESTAMP=$(date +"%Y-%m-%d %T.%3N") |
| 73 | + echo "${TIMESTAMP} $@" > /proc/$pid/fd/1 |
| 74 | + } |
| 75 | +
|
| 76 | + pid=$(ps aux | grep -i '/bin/bas[h] /usr' | awk {'print $2'}) |
| 77 | + log "Info: [prestop] Prestop Hook Execution" |
| 78 | +
|
| 79 | + my_host=$(hostname -f) |
| 80 | +
|
| 81 | + log "Info: [prestop] MarkLogic Pod Hostname: "$my_host |
| 82 | +
|
| 83 | + for ((i = 0; i < 5; i = i + 1)); do |
| 84 | + res_code=$(curl --anyauth --user $MARKLOGIC_ADMIN_USERNAME:$MARKLOGIC_ADMIN_PASSWORD \ |
| 85 | + -o /dev/null -m 10 -s -w %{http_code} \ |
| 86 | + -i -X POST --data "state=shutdown&failover=true" \ |
| 87 | + -H "Content-type: application/x-www-form-urlencoded" \ |
| 88 | + http://localhost:8002/manage/v2/hosts/$my_host?format=json) |
| 89 | +
|
| 90 | + if [[ ${res_code} -eq 202 ]]; then |
| 91 | + log "Info: [prestop] Host shut down response code: "$res_code |
| 92 | +
|
| 93 | + while (true) |
| 94 | + do |
| 95 | + ml_status=$(service MarkLogic status) |
| 96 | + log "Info: [prestop] MarkLogic Status: "$ml_status |
| 97 | + if [[ "$ml_status" =~ "running" ]]; then |
| 98 | + sleep 5s |
| 99 | + continue |
| 100 | + else |
| 101 | + break |
| 102 | + fi |
| 103 | + done |
| 104 | + break |
| 105 | + else |
| 106 | + log "ERROR: [prestop] Retry Attempt: "$i |
| 107 | + log "ERROR: [prestop] Host shut down expected response code 202, got "$res_code |
| 108 | + sleep 10s |
| 109 | + fi |
| 110 | + done |
63 | 111 | {{- if .Values.livenessProbe.enabled }}
|
64 | 112 | livenessProbe:
|
65 | 113 | httpGet:
|
|
0 commit comments