@@ -220,6 +220,23 @@ data:
220
220
echo $message >> /tmp/script.log
221
221
}
222
222
223
+ ###############################################################
224
+ # Function to get the current host protocol
225
+ # $1: The host name
226
+ # $2: The port number (default 8001)
227
+ ###############################################################
228
+ get_current_host_protocol() {
229
+ local hostname port protocol resp_code
230
+ hostname="${1:-localhost}"
231
+ port="${2:-8001}"
232
+ protocol="http"
233
+ resp_code=$(curl -s -o /dev/null -w '%{http_code}' http://$hostname:$port)
234
+ if [[ $resp_code -eq 403 ]]; then
235
+ protocol="https"
236
+ fi
237
+ echo $protocol
238
+ }
239
+
223
240
###############################################################
224
241
# Env Setup of MarkLogic
225
242
###############################################################
@@ -336,9 +353,10 @@ data:
336
353
if [ -z "${timestamp}" ]; then
337
354
info "${host} - not responding yet"
338
355
sleep 5s
339
- wait_until_marklogic_ready $host
356
+ wait_until_marklogic_ready $host
357
+ return 0
340
358
else
341
- info "${host} - responding, calling init "
359
+ info "${host} - responding with $timestamp "
342
360
out="/tmp/${host}.out"
343
361
344
362
response_code=$( \
@@ -537,15 +555,23 @@ data:
537
555
# return
538
556
################################################################
539
557
function configure_group {
558
+ local LOCAL_HTTP_PROTOCOL LOCAL_HTTPS_OPTION
559
+ LOCAL_HTTP_PROTOCOL="http"
560
+ LOCAL_HTTPS_OPTION=""
561
+ protocol=$(get_current_host_protocol $MARKLOGIC_BOOTSTRAP_HOST)
562
+ if [[ $protocol == "https" ]]; then
563
+ LOCAL_HTTP_PROTOCOL="https"
564
+ LOCAL_HTTPS_OPTION="-k"
565
+ fi
540
566
log "configuring group"
541
567
if [[ "$IS_BOOTSTRAP_HOST" == "true" ]]; then
542
568
group_cfg_template='{"group-name":"%s", "xdqp-ssl-enabled":"%s"}'
543
569
group_cfg=$(printf "$group_cfg_template" "$MARKLOGIC_GROUP" "$XDQP_SSL_ENABLED")
544
570
545
571
# check if host is already in and get the current cluster
546
- curl_retry_validate false "http ://${MARKLOGIC_BOOTSTRAP_HOST}:8002/manage/v2/hosts/${HOST_FQDN}/properties?format=xml" 200 \
572
+ curl_retry_validate false "$LOCAL_HTTP_PROTOCOL ://${MARKLOGIC_BOOTSTRAP_HOST}:8002/manage/v2/hosts/${HOST_FQDN}/properties?format=xml" 200 \
547
573
"--anyauth" "--user" "${MARKLOGIC_ADMIN_USERNAME}:${MARKLOGIC_ADMIN_PASSWORD}" \
548
- "-o" "/tmp/marklogic/groups.out"
574
+ "-o" "/tmp/marklogic/groups.out" $LOCAL_HTTPS_OPTION
549
575
550
576
response_code=$?
551
577
if [ "${response_code}" = "200" ]; then
@@ -558,15 +584,14 @@ data:
558
584
info "current_group: $current_group"
559
585
info "group_cfg: $group_cfg"
560
586
561
- # curl retry doesn't work in the lower version
562
587
response_code=$( \
563
588
curl -s --anyauth \
564
589
--user ${MARKLOGIC_ADMIN_USERNAME}:${MARKLOGIC_ADMIN_PASSWORD} \
565
590
-w '%{http_code}' \
566
591
-X PUT \
567
592
-H "Content-type: application/json" \
568
- -d "${group_cfg}" \
569
- http ://${MARKLOGIC_BOOTSTRAP_HOST}:8002/manage/v2/groups/${current_group}/properties \
593
+ $LOCAL_HTTPS_OPTION -d "${group_cfg}" \
594
+ $LOCAL_HTTP_PROTOCOL ://${MARKLOGIC_BOOTSTRAP_HOST}:8002/manage/v2/groups/${current_group}/properties \
570
595
)
571
596
572
597
info "response_code: $response_code"
@@ -607,6 +632,16 @@ data:
607
632
}
608
633
609
634
function configure_tls {
635
+ local protocol
636
+ if [[ "$IS_BOOTSTRAP_HOST" == "true" ]] && [[ $MARKLOGIC_CLUSTER_TYPE == "bootstrap" ]]; then
637
+ protocol=$(get_current_host_protocol)
638
+ log "Info: Current host protocol: $protocol"
639
+ if [[ $protocol == "https" ]]; then
640
+ log "Info: MarkLogic server has already configured HTTPS for bootstrap host."
641
+ return 0
642
+ fi
643
+ fi
644
+
610
645
info "Configuring TLS for App Servers"
611
646
612
647
AUTH_CURL="curl --anyauth --user $MARKLOGIC_ADMIN_USERNAME:$MARKLOGIC_ADMIN_PASSWORD -m 20 -s "
@@ -638,7 +673,7 @@ data:
638
673
}
639
674
EOF
640
675
641
- if [[ $POD_NAME == *-0 ]] && [[ $MARKLOGIC_CLUSTER_TYPE == "bootstrap" ]]; then
676
+ if [[ "$IS_BOOTSTRAP_HOST" == "true" ]] && [[ $MARKLOGIC_CLUSTER_TYPE == "bootstrap" ]]; then
642
677
log "Info: creating default certificate Template"
643
678
response=$($AUTH_CURL -X POST --header "Content-Type:application/json" -d @defaultCertificateTemplate.json http://localhost:8002/manage/v2/certificate-templates)
644
679
sleep 5s
@@ -707,7 +742,7 @@ data:
707
742
708
743
log "Info: inserting following certificates for $cert_path for $MARKLOGIC_CLUSTER_TYPE"
709
744
710
- if [[ $POD_NAME == *-0 ]]; then
745
+ if [[ "$IS_BOOTSTRAP_HOST" == "true" ]]; then
711
746
res=$($AUTH_CURL -X POST --header "Content-Type:application/json" -d @insert_cert_payload.json http://localhost:8002/manage/v2/certificate-templates/defaultTemplate 2>&1)
712
747
else
713
748
res=$($AUTH_CURL -k -X POST --header "Content-Type:application/json" -d @insert_cert_payload.json https://localhost:8002/manage/v2/certificate-templates/defaultTemplate 2>&1)
@@ -716,7 +751,7 @@ data:
716
751
sleep 5s
717
752
fi
718
753
719
- if [[ $POD_NAME == *-0 ]]; then
754
+ if [[ "$IS_BOOTSTRAP_HOST" == "true" ]]; then
720
755
if [[ $MARKLOGIC_CLUSTER_TYPE == "bootstrap" ]]; then
721
756
log "Info: Generating Temporary CA Certificate"
722
757
$AUTH_CURL -X POST -i -d @generateCA.xqy \
@@ -774,7 +809,7 @@ data:
774
809
sleep 5s
775
810
776
811
# Authentication configuration when path based is used
777
- if [[ $POD_NAME == *-0 ]] && [[ $PATH_BASED_ROUTING == "true" ]]; then
812
+ if [[ "$IS_BOOTSTRAP_HOST" == "true" ]] && [[ $PATH_BASED_ROUTING == "true" ]]; then
778
813
log "Info: path based routing is set. Adapting authentication method"
779
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})
780
815
log "Info: Admin-Servers response code: $resp"
0 commit comments