@@ -166,38 +166,52 @@ spec:
166
166
echo "${TIMESTAMP} $@" > /proc/$pid/fd/1
167
167
fi
168
168
}
169
- log "Info: [poststart] Begin Poststart Hook Execution"
169
+
170
+ log "Info: [poststart] Poststart Hook Execution"
171
+ restart_check () {
172
+ local retry_count LAST_START timestamp=$1
173
+ LAST_START=$(curl -s --anyauth --user "${MARKLOGIC_ADMIN_USERNAME}":"${MARKLOGIC_ADMIN_PASSWORD}" "http://${MARKLOGIC_BOOTSTRAP_HOST}:8001/admin/v1/timestamp")
174
+ for ((retry_count = 0; retry_count < 5; retry_count = retry_count + 1)); do
175
+ if [[ "${timestamp}" == "${LAST_START}" ]] || [[ -z "${LAST_START}" ]]; then
176
+ sleep 10
177
+ LAST_START=$(curl -s --anyauth --user "${MARKLOGIC_ADMIN_USERNAME}":"${MARKLOGIC_ADMIN_PASSWORD}" "http://${MARKLOGIC_BOOTSTRAP_HOST}:8001/admin/v1/timestamp")
178
+ else
179
+ log "Info: [poststart] MarkLogic host: ${MARKLOGIC_BOOTSTRAP_HOST} has restarted."
180
+ return 0
181
+ fi
182
+ done
183
+ log "Error: [poststart] Failed to restart MarkLogic host: ${MARKLOGIC_BOOTSTRAP_HOST}"
184
+ exit 1
185
+ }
186
+
170
187
if [[ $POD_NAME != *-0 ]]; then
171
188
log "Info: [poststart] Skipping group configuration."
172
189
else
190
+ log "Info: [poststart] Begin group configuration."
173
191
while [ ! -f /var/opt/MarkLogic/ready ]; do
174
- log "[poststart] wait for marklogic server to be ready"
192
+ log "[poststart] waiting for MarkLogic server to be ready"
175
193
sleep 5s
176
194
done
177
195
178
- # Fetch timestamp before updating group config
179
- TIMESTAMP=`curl --anyauth http://${MARKLOGIC_BOOTSTRAP_HOST}:8001/admin/v1/timestamp --user ${MARKLOGIC_ADMIN_USERNAME}:${MARKLOGIC_ADMIN_PASSWORD}`
180
-
181
196
GROUP_CFG_TEMPLATE='{"group-name":"%s", "xdqp-ssl-enabled":"%s"}'
182
197
GROUP_CFG=$(printf "$GROUP_CFG_TEMPLATE" "$MARKLOGIC_GROUP" "$XDQP_SSL_ENABLED")
183
198
log "Info: [poststart] Updating group configuration: ${GROUP_CFG}"
184
- GROUP_RESP_CODE=`curl --retry 5 --retry-max-time 60 -o /dev/null -w "%{http_code}" --anyauth -m 20 -s -X PUT -H "Content-type: application/json" -d "${GROUP_CFG}" http://${MARKLOGIC_BOOTSTRAP_HOST}:8002/manage/v2/groups/Default/properties --user ${MARKLOGIC_ADMIN_USERNAME}:${MARKLOGIC_ADMIN_PASSWORD}`
185
-
186
- # check if MarkLogic has restarted
187
- if [[ ${GROUP_RESP_CODE} -eq 202 ]]; then
188
- log "Info: [poststart] Waiting for MarkLogic to restart ."
189
- LAST_START=`curl --anyauth http://${MARKLOGIC_BOOTSTRAP_HOST}:8001/admin/v1/timestamp --user ${MARKLOGIC_ADMIN_USERNAME}:${MARKLOGIC_ADMIN_PASSWORD}`
190
- for i in $(seq 1 5); do
191
- if [ ${TIMESTAMP} == ${LAST_START} ] || [ -z ${LAST_START} ]; then
192
- sleep 10
193
- LAST_START=`curl --anyauth http://${MARKLOGIC_BOOTSTRAP_HOST}:8001/admin/v1/timestamp --user ${MARKLOGIC_ADMIN_USERNAME}:${MARKLOGIC_ADMIN_PASSWORD}`
194
- else
195
- log "Info : [poststart] MarkLogic has restarted."
196
- fi
197
- done
199
+ GROUP_RESP_CODE=`curl --retry 5 --retry-max-time 60 -o /tmp/restart_payload.xml -w "%{http_code}" --anyauth -m 20 -s -X PUT -H "Content-type: application/json" -d "${GROUP_CFG}" http://${MARKLOGIC_BOOTSTRAP_HOST}:8002/manage/v2/groups/Default/properties --user ${MARKLOGIC_ADMIN_USERNAME}:${MARKLOGIC_ADMIN_PASSWORD}`
200
+
201
+ # check whether MarkLogic has restarted
202
+ if [[ ${GROUP_RESP_CODE} -eq 202 ]] || [[ ${GROUP_RESP_CODE} -eq 204 ]] ; then
203
+ log "Info: [poststart] Successfully configured properties for $MARKLOGIC_GROUP group on the MarkLogic cluster ."
204
+ TIMESTAMP=$(< /tmp/restart_payload.xml grep "last-startup" | sed 's%^.*<last-startup.*>\(.*\)</last-startup>.*$%\1%')
205
+ rm -f /tmp/restart_payload.xml
206
+ if [[ -n ${TIMESTAMP} ] ]; then
207
+ restart_check ${TIMESTAMP}
208
+ fi
209
+ else
210
+ log "Error : [poststart] Failed to configure properties for $MARKLOGIC_GROUP group.
211
+ log "Error: [poststart] Expected response code 202 or 204, got "${GROUP_RESP_CODE}"
212
+ exit 1
198
213
fi
199
214
fi
200
- log "Info: [poststart] Poststart Hook Execution Completed"
201
215
{{- end }}
202
216
preStop :
203
217
exec :
0 commit comments