@@ -169,10 +169,11 @@ data:
169
169
#! /bin/bash
170
170
# Refer to https://docs.marklogic.com/guide/admin-api/cluster#id_10889 for cluster joining process
171
171
172
- mkdir -p /tmp/marklogic
173
172
N_RETRY=10
174
173
RETRY_INTERVAL=5
175
- HOST_FQDN="$(hostname).${MARKLOGIC_FQDN_SUFFIX}"
174
+ HOSTNAME=$(cat /etc/hostname)
175
+ HOST_FQDN="${HOSTNAME}.${MARKLOGIC_FQDN_SUFFIX}"
176
+ ML_KUBERNETES_FILE_PATH="/var/opt/MarkLogic/Kubernetes"
176
177
177
178
# HTTP_PROTOCOL could be http or https
178
179
HTTP_PROTOCOL="http"
@@ -183,7 +184,7 @@ data:
183
184
fi
184
185
185
186
IS_BOOTSTRAP_HOST=false
186
- if [[ "$(hostname) " == *-0 ]]; then
187
+ if [[ "${HOSTNAME} " == *-0 ]]; then
187
188
echo "IS_BOOTSTRAP_HOST true"
188
189
IS_BOOTSTRAP_HOST=true
189
190
else
@@ -344,16 +345,16 @@ data:
344
345
# return values: 0 - successfully initialized
345
346
# 1 - host not reachable
346
347
################################################################
347
- function wait_until_marklogic_ready {
348
+ function init_marklogic {
348
349
local host=$1
349
350
info "wait until $host is ready"
350
- timestamp=$( curl -s --anyauth \
351
+ timestamp=$( curl -s --anyauth -m 4 \
351
352
--user "${MARKLOGIC_ADMIN_USERNAME}":"${MARKLOGIC_ADMIN_PASSWORD}" \
352
- http://${host} :8001/admin/v1/timestamp )
353
+ http://localhost :8001/admin/v1/timestamp )
353
354
if [ -z "${timestamp}" ]; then
354
355
info "${host} - not responding yet"
355
- sleep 5s
356
- wait_until_marklogic_ready $host
356
+ sleep 10s
357
+ init_marklogic $host
357
358
return 0
358
359
else
359
360
info "${host} - responding with $timestamp"
@@ -365,7 +366,7 @@ data:
365
366
-i -X POST -H "Content-type:application/json" \
366
367
-d "${LICENSE_PAYLOAD}" \
367
368
--user "${MARKLOGIC_ADMIN_USERNAME}":"${MARKLOGIC_ADMIN_PASSWORD}" \
368
- http://${host} :8001/admin/v1/init \
369
+ http://localhost :8001/admin/v1/init \
369
370
)
370
371
if [ "${response_code}" = "202" ]; then
371
372
info "${host} - init called, restart triggered"
@@ -437,7 +438,7 @@ data:
437
438
info "${MARKLOGIC_BOOTSTRAP_HOST} - bootstrap security already initialized"
438
439
return 0
439
440
else
440
- info "${MARKLOGIC_BOOTSTRAP_HOST} - initializing bootstrap security"
441
+ info "initializing bootstrap security"
441
442
442
443
# Get last restart timestamp directly before instance-admin call to verify restart after
443
444
timestamp=$( \
@@ -454,7 +455,7 @@ data:
454
455
455
456
restart_check "${MARKLOGIC_BOOTSTRAP_HOST}" "${timestamp}"
456
457
457
- info "${MARKLOGIC_BOOTSTRAP_HOST} - bootstrap security initialized"
458
+ info "bootstrap security initialized"
458
459
return 0
459
460
fi
460
461
}
@@ -502,7 +503,7 @@ data:
502
503
503
504
# process to join the host
504
505
# Wait until the group is ready
505
- retry_count=5
506
+ retry_count=10
506
507
while [ $retry_count -gt 0 ]; do
507
508
GROUP_RESP_CODE=$( curl --anyauth -m 20 -s -o /dev/null -w "%{http_code}" $HTTPS_OPTION -X GET $HTTP_PROTOCOL://${MARKLOGIC_BOOTSTRAP_HOST}:8002/manage/v2/groups/${MARKLOGIC_GROUP} --anyauth --user ${MARKLOGIC_ADMIN_USERNAME}:${MARKLOGIC_ADMIN_PASSWORD} )
508
509
info "GROUP_RESP_CODE: $GROUP_RESP_CODE"
@@ -521,32 +522,32 @@ data:
521
522
fi
522
523
done
523
524
524
- info "${hostname} - joining cluster of group ${MARKLOGIC_GROUP}"
525
+ info "joining cluster of group ${MARKLOGIC_GROUP}"
525
526
MARKLOGIC_GROUP_PAYLOAD="group=${MARKLOGIC_GROUP}"
526
- curl_retry_validate false "http://${hostname} :8001/admin/v1/server-config" 200 \
527
+ curl_retry_validate false "http://localhost :8001/admin/v1/server-config" 200 \
527
528
"-o" "/tmp/host.xml" "-X" "GET" "-H" "Accept: application/xml"
528
529
529
- info "${hostname} - getting cluster-config from bootstrap host"
530
+ info "getting cluster-config from bootstrap host"
530
531
curl_retry_validate false "$HTTP_PROTOCOL://${MARKLOGIC_BOOTSTRAP_HOST}:8001/admin/v1/cluster-config" 200 \
531
532
"--anyauth" "--user" "${MARKLOGIC_ADMIN_USERNAME}:${MARKLOGIC_ADMIN_PASSWORD}" \
532
533
"-X" "POST" "-d" "${MARKLOGIC_GROUP_PAYLOAD}" \
533
534
"--data-urlencode" "server-config@/tmp/host.xml" \
534
535
"-H" "Content-type: application/x-www-form-urlencoded" \
535
536
"-o" "/tmp/cluster.zip" $HTTPS_OPTION
536
537
537
- timestamp=$(curl -s "http://${hostname} :8001/admin/v1/timestamp" )
538
+ timestamp=$(curl -s "http://localhost :8001/admin/v1/timestamp" )
538
539
539
- info "${hostname} - joining cluster of group ${MARKLOGIC_GROUP}"
540
- curl_retry_validate false "http://${hostname} :8001/admin/v1/cluster-config" 202 \
540
+ info "joining cluster of group ${MARKLOGIC_GROUP}"
541
+ curl_retry_validate false "http://localhost :8001/admin/v1/cluster-config" 202 \
541
542
"-o" "/dev/null" \
542
543
"-X" "POST" "-H" "Content-type: application/zip" \
543
544
"--data-binary" "@/tmp/cluster.zip"
544
545
545
546
# 202 causes restart
546
- info "${hostname} - restart triggered"
547
- restart_check "${hostname} " "${timestamp}"
547
+ info "restart triggered"
548
+ restart_check "localhost " "${timestamp}"
548
549
549
- info "${hostname} - joined group ${MARKLOGIC_GROUP}"
550
+ info "joined group ${MARKLOGIC_GROUP}"
550
551
}
551
552
552
553
################################################################
@@ -558,8 +559,8 @@ data:
558
559
local LOCAL_HTTP_PROTOCOL LOCAL_HTTPS_OPTION
559
560
LOCAL_HTTP_PROTOCOL="http"
560
561
LOCAL_HTTPS_OPTION=""
561
- protocol =$(get_current_host_protocol $MARKLOGIC_BOOTSTRAP_HOST)
562
- if [[ $protocol == "https" ]]; then
562
+ bootstrap_protocol =$(get_current_host_protocol $MARKLOGIC_BOOTSTRAP_HOST)
563
+ if [[ $bootstrap_protocol == "https" ]]; then
563
564
LOCAL_HTTP_PROTOCOL="https"
564
565
LOCAL_HTTPS_OPTION="-k"
565
566
fi
@@ -571,12 +572,12 @@ data:
571
572
# check if host is already in and get the current cluster
572
573
curl_retry_validate false "$LOCAL_HTTP_PROTOCOL://${MARKLOGIC_BOOTSTRAP_HOST}:8002/manage/v2/hosts/${HOST_FQDN}/properties?format=xml" 200 \
573
574
"--anyauth" "--user" "${MARKLOGIC_ADMIN_USERNAME}:${MARKLOGIC_ADMIN_PASSWORD}" \
574
- "-o" "/tmp/marklogic/ groups.out" $LOCAL_HTTPS_OPTION
575
+ "-o" "/tmp/groups.out" $LOCAL_HTTPS_OPTION
575
576
576
577
response_code=$?
577
578
if [ "${response_code}" = "200" ]; then
578
579
current_group=$( \
579
- cat "/tmp/marklogic/ groups.out" |
580
+ cat "/tmp/groups.out" |
580
581
grep "group" |
581
582
sed 's%^.*<group.*>\(.*\)</group>.*$%\1%' \
582
583
)
@@ -786,47 +787,98 @@ data:
786
787
787
788
log "Info: removing cert keys"
788
789
rm -f /run/secrets/marklogic-certs/*.key
789
- }
790
+ }
790
791
791
792
792
- info "Start configuring MarkLogic for $HOST_FQDN"
793
- info "Bootstrap host: $MARKLOGIC_BOOTSTRAP_HOST"
793
+ function configure_path_based_routing {
794
+ # Authentication configuration when path based is used
795
+ if [[ $PATH_BASED_ROUTING == "true" ]]; then
796
+ log "Info: path based routing is set. Adapting authentication method"
797
+ resp=$(curl --anyauth -w "%{http_code}" --user $MARKLOGIC_ADMIN_USERNAME:$MARKLOGIC_ADMIN_PASSWORD -m 20 -s -X PUT -H "Content-type: application/json" -d '{"authentication":"basic"}' http://localhost:8002/manage/v2/servers/Admin/properties?group-id=${MARKLOGIC_GROUP})
798
+ log "Info: Admin-Servers response code: $resp"
799
+ resp=$(curl --anyauth -w "%{http_code}" --user $MARKLOGIC_ADMIN_USERNAME:$MARKLOGIC_ADMIN_PASSWORD -m 20 -s -X PUT -H "Content-type: application/json" -d '{"authentication":"basic"}' http://localhost:8002/manage/v2/servers/App-Services/properties?group-id=${MARKLOGIC_GROUP})
800
+ log "Info: App Service response code: $resp"
801
+ resp=$(curl --anyauth -w "%{http_code}" --user $MARKLOGIC_ADMIN_USERNAME:$MARKLOGIC_ADMIN_PASSWORD -m 20 -s -X PUT -H "Content-type: application/json" -d '{"authentication":"basic"}' http://localhost:8002/manage/v2/servers/Manage/properties?group-id=${MARKLOGIC_GROUP})
802
+ log "Info: Manage response code: $resp"
803
+ log "Info: Default App-Servers authentication set to basic auth"
804
+ else
805
+ log "Info: This is not the boostrap host or path based routing is not set. Skipping authentication configuration"
806
+ fi
807
+ #End of authentication configuration
808
+ }
809
+
810
+ function set_status_file {
811
+ mkdir -p $ML_KUBERNETES_FILE_PATH
812
+ fqdn=$(hostname -f)
813
+ status_file="$ML_KUBERNETES_FILE_PATH/status.txt"
814
+ group_name="${MARKLOGIC_GROUP}"
815
+ group_xdqp_ssl_enabled="${XDQP_SSL_ENABLED}"
816
+ https_enabled="${MARKLOGIC_JOIN_TLS_ENABLED}"
817
+ echo "fqdn=${fqdn}" > $status_file
818
+ echo "group_name=${group_name}" >> $status_file
819
+ echo "group_xdqp_ssl_enabled=${group_xdqp_ssl_enabled}" >> $status_file
820
+ echo "https_enabled=${https_enabled}" >> $status_file
821
+ }
822
+
823
+ function check_status_file_for_nonbootstrap {
824
+ if [[ -f "$ML_KUBERNETES_FILE_PATH/status.txt" ]]; then
825
+ log "Info: status file exists. Skip configuration"
826
+ exit 0
827
+ else
828
+ log "Info: status file does not exist. Continue"
829
+ fi
830
+ }
831
+
832
+ function check_status_file_for_boostrap {
833
+ if [[ -f "$ML_KUBERNETES_FILE_PATH/status.txt" ]]; then
834
+ new_group_name="${MARKLOGIC_GROUP}"
835
+ new_group_xdqp_ssl_enabled="${XDQP_SSL_ENABLED}"
836
+ new_https_enabled="${MARKLOGIC_JOIN_TLS_ENABLED}"
837
+ source "$ML_KUBERNETES_FILE_PATH/status.txt"
838
+ if [[ "$new_group_name" == "$group_name" ]] && [[ "$new_group_xdqp_ssl_enabled" == "$group_xdqp_ssl_enabled" ]] && [[ "$new_https_enabled" == "$https_enabled" ]]; then
839
+ log "No change in values file. Skip configuration"
840
+ exit 0
841
+ else
842
+ log "Info: changes made in values file. Continue Configuration"
843
+ fi
844
+ else
845
+ return 0
846
+ fi
847
+ }
794
848
795
849
# Wait for current pod ready
796
- wait_until_marklogic_ready $HOST_FQDN
850
+
851
+ info "Start configuring MarkLogic for $HOST_FQDN"
852
+ info "Bootstrap host: $MARKLOGIC_BOOTSTRAP_HOST"
797
853
798
854
# Only do this if the bootstrap host is in the statefulset we are configuring
799
- if [[ "${MARKLOGIC_CLUSTER_TYPE}" = "bootstrap" && "${HOST_FQDN}" = "${MARKLOGIC_BOOTSTRAP_HOST}" ]]; then
800
- sleep 2s
801
- init_security_db
802
- configure_group
803
- else
855
+ if [[ "$IS_BOOTSTRAP_HOST" == "true" ]]; then
856
+ check_status_file_for_boostrap
857
+ init_marklogic $HOST_FQDN
858
+ if [[ "${MARKLOGIC_CLUSTER_TYPE}" == "bootstrap" ]]; then
859
+ log "Info: bootstrap host is ready"
860
+ init_security_db
861
+ configure_group
862
+ else
863
+ log "Info: bootstrap host is ready"
864
+ configure_group
865
+ join_cluster $HOST_FQDN
866
+ fi
867
+ configure_path_based_routing
868
+ else
869
+ check_status_file_for_nonbootstrap
870
+ init_marklogic $HOST_FQDN
804
871
wait_bootstrap_ready
805
- configure_group
806
872
join_cluster $HOST_FQDN
807
873
fi
808
874
809
- sleep 5s
810
-
811
- # Authentication configuration when path based is used
812
- if [[ "$IS_BOOTSTRAP_HOST" == "true" ]] && [[ $PATH_BASED_ROUTING == "true" ]]; then
813
- log "Info: path based routing is set. Adapting authentication method"
814
- resp=$(curl --anyauth -w "%{http_code}" --user $MARKLOGIC_ADMIN_USERNAME:$MARKLOGIC_ADMIN_PASSWORD -m 20 -s -X PUT -H "Content-type: application/json" -d '{"authentication":"basic"}' http://localhost:8002/manage/v2/servers/Admin/properties?group-id=${MARKLOGIC_GROUP})
815
- log "Info: Admin-Servers response code: $resp"
816
- resp=$(curl --anyauth -w "%{http_code}" --user $MARKLOGIC_ADMIN_USERNAME:$MARKLOGIC_ADMIN_PASSWORD -m 20 -s -X PUT -H "Content-type: application/json" -d '{"authentication":"basic"}' http://localhost:8002/manage/v2/servers/App-Services/properties?group-id=${MARKLOGIC_GROUP})
817
- log "Info: App Service response code: $resp"
818
- resp=$(curl --anyauth -w "%{http_code}" --user $MARKLOGIC_ADMIN_USERNAME:$MARKLOGIC_ADMIN_PASSWORD -m 20 -s -X PUT -H "Content-type: application/json" -d '{"authentication":"basic"}' http://localhost:8002/manage/v2/servers/Manage/properties?group-id=${MARKLOGIC_GROUP})
819
- log "Info: Manage response code: $resp"
820
- log "Info: Default App-Servers authentication set to basic auth"
821
- else
822
- log "Info: This is not the boostrap host or path based routing is not set. Skipping authentication configuration"
823
- fi
824
- #End of authentication configuration
825
-
826
875
if [[ $MARKLOGIC_JOIN_TLS_ENABLED == "true" ]]; then
876
+ log "configuring tls"
827
877
configure_tls
828
878
fi
829
879
880
+ set_status_file
881
+
830
882
info "helm script completed"
831
883
832
884
root-rootless-upgrade.sh : |
0 commit comments