Skip to content

Commit 6c8e0b5

Browse files
author
Jan Lieskovsky
committed
[CLOUD-2453][KEYCLOAK-7098] Add wait_for_service launch script routine
Describe and add example values for the newly introduced SERVICE_WAIT_NAME, SERVICE_WAIT_RETRY_MESSAGE, and SERVICE_WAIT_INTRO_MESSAGE environment variables Also move the description of SSO_ADMIN_USERNAME, SSO_ADMIN_PASSWORD, SSO_SERVICE_USERNAME, and SSO_SERVICE_PASSWORD variables from image.yaml to os-sso/module.yaml. These variables aren't used / referenced outside of some of os-sso, os-sso71, and os-sso72 modules, and for the future we want one common 'os-sso' module, sharing all the parts common to all RH-SSO images. This move is part of such unification Signed-off-by: Jan Lieskovsky <[email protected]>
1 parent 9369223 commit 6c8e0b5

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

os-sso/module.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,17 @@ execute:
88
modules:
99
install:
1010
- name: os-eap-launch
11+
12+
envs:
13+
- name: "SSO_ADMIN_USERNAME"
14+
example: "admin"
15+
description: "Username of the administrator account for the 'master' realm of the RH-SSO server. Required. If no value is specified, it is auto generated and displayed as an OpenShift Instructional message when the template is instantiated."
16+
- name: "SSO_ADMIN_PASSWORD"
17+
example: "hardtoguess"
18+
description: "Password of the administrator account for the 'master' realm of the RH-SSO server. Required. If no value is specified, it is auto generated and displayed as an OpenShift Instructional message when the template is instantiated."
19+
- name: "SSO_SERVICE_USERNAME"
20+
example: "username"
21+
description: "RH-SSO Server service username with rights to create Client configurations in SSO_REALM. This user is created if this ENV is provided"
22+
- name: "SSO_SERVICE_PASSWORD"
23+
example: "password"
24+
description: "Password for SSO_SERVICE_USERNAME"

os-sso71/module.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ run:
1717
user: 185
1818
cmd:
1919
- "/opt/eap/bin/openshift-launch.sh"
20+
21+
# See os-sso/module.yaml for the description of SSO_ADMIN_USERNAME,
22+
# SSO_ADMIN_PASSWORD, SSO_SERVICE_USERNAME, and SSO_SERVICE_PASSWORD variables

os-sso72/added/openshift-launch.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,40 @@ function clean_shutdown() {
1111
wait $!
1212
}
1313

14+
# CLOUD-2453 Connect-retry loop to wait for the service to become reachable over network
15+
function wait_for_service() {
16+
if [ -n "${SERVICE_WAIT_NAME}" ]; then
17+
local -r retry_period_seconds_default="10"
18+
local -r connect_retry_message="${SERVICE_WAIT_RETRY_MESSAGE:-"Waiting for the \"${SERVICE_WAIT_NAME}\" service to become available ..."}"
19+
local service="${SERVICE_WAIT_NAME/-/_}"
20+
local -r service_host="${service^^}_SERVICE_HOST"
21+
local -r service_port="${service^^}_SERVICE_PORT"
22+
if [ -n "${SERVICE_WAIT_RETRY_PERIOD_SECONDS}" ] && [[ ! "${SERVICE_WAIT_RETRY_PERIOD_SECONDS}" =~ '^[0-9]+\.?[0-9]*$' ]]; then
23+
log_warning "Value of SERVICE_WAIT_RETRY_PERIOD_SECONDS variable can be only arbitrary floating point number. Ignoring \"${SERVICE_WAIT_RETRY_PERIOD_SECONDS}\" setting, defaulting to ${retry_period_seconds_default} seconds."
24+
unset SERVICE_WAIT_RETRY_PERIOD_SECONDS
25+
fi
26+
if [ -z "${!service_host}" -o -z "${!service_port}" ]; then
27+
log_warning "Unable to determine target host or port of the \"${SERVICE_WAIT_NAME}\" service. The RH-SSO pod will start without waiting for the \"${SERVICE_WAIT_NAME}\" service to become reachable over network. Please make sure you specified correct service name in SERVICE_WAIT_NAME."
28+
else
29+
until ( echo > /dev/tcp/"${!service_host}"/"${!service_port}" ) &> /dev/null; do
30+
if [ -n "${SERVICE_WAIT_INTRO_MESSAGE}" ]; then
31+
log_warning "${SERVICE_WAIT_INTRO_MESSAGE}"
32+
unset SERVICE_WAIT_INTRO_MESSAGE
33+
fi
34+
log_info "${connect_retry_message}"
35+
sleep "${SERVICE_WAIT_RETRY_PERIOD_SECONDS:-${retry_period_seconds_default}}s"
36+
done
37+
fi
38+
fi
39+
}
40+
1441
function runServer() {
1542
local instanceDir=$1
1643
local count=$2
1744
export NODE_NAME="${NODE_NAME:-node}-${count}"
1845

46+
wait_for_service
47+
1948
source $JBOSS_HOME/bin/launch/configure.sh
2049

2150
log_info "Running $JBOSS_IMAGE_NAME image, version $JBOSS_IMAGE_VERSION"
@@ -47,6 +76,8 @@ if [ "${SPLIT_DATA^^}" = "TRUE" ]; then
4776

4877
partitionPV "${DATA_DIR}" "${SPLIT_LOCK_TIMEOUT:-30}"
4978
else
79+
wait_for_service
80+
5081
source $JBOSS_HOME/bin/launch/configure.sh
5182

5283
log_info "Running $JBOSS_IMAGE_NAME image, version $JBOSS_IMAGE_VERSION"

os-sso72/module.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,16 @@ run:
2323
user: 185
2424
cmd:
2525
- "/opt/eap/bin/openshift-launch.sh"
26+
27+
envs:
28+
# See os-sso/module.yaml for the description of SSO_ADMIN_USERNAME,
29+
# SSO_ADMIN_PASSWORD, SSO_SERVICE_USERNAME, and SSO_SERVICE_PASSWORD variables
30+
- name: "SERVICE_WAIT_NAME"
31+
example: "sso-mysql"
32+
description: "Name of the OpenShift service, the RH-SSO pod should wait for to become reachable over network, prior starting the RH-SSO server. Not set by default."
33+
- name: "SERVICE_WAIT_RETRY_MESSAGE"
34+
example: "Waiting for the \"${SERVICE_WAIT_NAME}\" service to become reachable over network ..."
35+
description: "Message to be displayed in connect-retry loop, in which the RH-SSO pod is waiting for the SERVICE_WAIT_NAME to become reachable over network. Defaults to 'Waiting for the \"${SERVICE_WAIT_NAME}\" service to become available ....' if the SERVICE_WAIT_NAME variable is set."
36+
- name: "SERVICE_WAIT_INTRO_MESSAGE"
37+
example: "Ensure a persistent volume is available for the \"${APPLICATION_NAME}-mysql-claim\" or a storage class is set."
38+
description: "Message to be displayed prior starting the connect-retry loop, in which the RH-SSO pod is waiting for the SERVICE_WAIT_NAME to become reachable over network. Typically describes additional requirements in order the connect-retry loop of the RH-SSO pod successfully to finish. Not set by default."

0 commit comments

Comments
 (0)