Skip to content

Commit

Permalink
[CLOUD-2453][KEYCLOAK-7098] Add wait_for_service launch script routine
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Jan Lieskovsky committed Oct 10, 2018
1 parent 9369223 commit 77b3957
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
14 changes: 14 additions & 0 deletions os-sso/module.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,17 @@ execute:
modules:
install:
- name: os-eap-launch

envs:
- name: "SSO_ADMIN_USERNAME"
example: "admin"
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."
- name: "SSO_ADMIN_PASSWORD"
example: "hardtoguess"
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."
- name: "SSO_SERVICE_USERNAME"
example: "username"
description: "RH-SSO Server service username with rights to create Client configurations in SSO_REALM. This user is created if this ENV is provided"
- name: "SSO_SERVICE_PASSWORD"
example: "password"
description: "Password for SSO_SERVICE_USERNAME"
3 changes: 3 additions & 0 deletions os-sso71/module.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ run:
user: 185
cmd:
- "/opt/eap/bin/openshift-launch.sh"

# See os-sso/module.yaml for the description of SSO_ADMIN_USERNAME,
# SSO_ADMIN_PASSWORD, SSO_SERVICE_USERNAME, and SSO_SERVICE_PASSWORD variables
31 changes: 31 additions & 0 deletions os-sso72/added/openshift-launch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,40 @@ function clean_shutdown() {
wait $!
}

# CLOUD-2453 Connect-retry loop to wait for the service to become reachable over network
function wait_for_service() {
if [ -n "${SERVICE_WAIT_NAME}" ]; then
local -r retry_period_seconds_default="10"
local -r connect_retry_message="${SERVICE_WAIT_RETRY_MESSAGE:-"Waiting for the \"${SERVICE_WAIT_NAME}\" service to become available ..."}"
local service="${SERVICE_WAIT_NAME/-/_}"
local -r service_host="${service^^}_SERVICE_HOST"
local -r service_port="${service^^}_SERVICE_PORT"
if [ -n "${SERVICE_WAIT_RETRY_PERIOD_SECONDS}" ] && [[ ! "${SERVICE_WAIT_RETRY_PERIOD_SECONDS}" =~ '^[0-9]+\.?[0-9]*$' ]]; then
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."
unset SERVICE_WAIT_RETRY_PERIOD_SECONDS
fi
if [ -z "${!service_host}" -o -z "${!service_port}" ]; then
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."
else
until ( echo > /dev/tcp/"${!service_host}"/"${!service_port}" ) &> /dev/null; do
if [ -n "${SERVICE_WAIT_INTRO_MESSAGE}" ]; then
log_warning "${SERVICE_WAIT_INTRO_MESSAGE}"
unset SERVICE_WAIT_INTRO_MESSAGE
fi
log_info "${connect_retry_message}"
sleep "${SERVICE_WAIT_RETRY_PERIOD_SECONDS:-${retry_period_seconds_default}}s"
done
fi
fi
}

function runServer() {
local instanceDir=$1
local count=$2
export NODE_NAME="${NODE_NAME:-node}-${count}"

wait_for_service

source $JBOSS_HOME/bin/launch/configure.sh

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

partitionPV "${DATA_DIR}" "${SPLIT_LOCK_TIMEOUT:-30}"
else
wait_for_service

source $JBOSS_HOME/bin/launch/configure.sh

log_info "Running $JBOSS_IMAGE_NAME image, version $JBOSS_IMAGE_VERSION"
Expand Down
13 changes: 13 additions & 0 deletions os-sso72/module.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,16 @@ run:
user: 185
cmd:
- "/opt/eap/bin/openshift-launch.sh"

envs:
# See os-sso/module.yaml for the description of SSO_ADMIN_USERNAME,
# SSO_ADMIN_PASSWORD, SSO_SERVICE_USERNAME, and SSO_SERVICE_PASSWORD variables
- name: "SERVICE_WAIT_NAME"
example: "sso-mysql"
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."
- name: "SERVICE_WAIT_RETRY_MESSAGE"
example: "Waiting for the \"${SERVICE_WAIT_NAME}\" service to become available ..."
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. Not set by default."
- name: "SERVICE_WAIT_INTRO_MESSAGE"
example: "Ensure a persistent volume is available for the \"${APPLICATION_NAME}-mysql-claim\" or a storage class is set."
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 comments on commit 77b3957

Please sign in to comment.