From 24410adac8d2d6aa342c45384a02653ad6608596 Mon Sep 17 00:00:00 2001 From: Brendan Early Date: Mon, 10 May 2021 19:48:34 -0500 Subject: [PATCH] solr: modify startup script to include special args --- .../solr/templates/configmap.yml | 9 +++ .../solr/templates/deploymentconfig.yml | 10 ++- .../solr/templates/solr-start.sh | 73 +++++++++++++++++++ 3 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 roles/openshift-apps/solr/templates/solr-start.sh diff --git a/roles/openshift-apps/solr/templates/configmap.yml b/roles/openshift-apps/solr/templates/configmap.yml index a311ace186..0a121cf13c 100644 --- a/roles/openshift-apps/solr/templates/configmap.yml +++ b/roles/openshift-apps/solr/templates/configmap.yml @@ -11,3 +11,12 @@ data: {{ load_file('packages/solrconfig.xml') | indent }} schema.xml: |- {{ load_file('packages/schema.xml') | indent }} +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: solr-start-configmap + labels: + app: solr + solr-start.sh: |- + {{ load_file('solr-start.sh') | indent }} diff --git a/roles/openshift-apps/solr/templates/deploymentconfig.yml b/roles/openshift-apps/solr/templates/deploymentconfig.yml index b796c4aefd..133a519036 100644 --- a/roles/openshift-apps/solr/templates/deploymentconfig.yml +++ b/roles/openshift-apps/solr/templates/deploymentconfig.yml @@ -23,9 +23,8 @@ spec: - name: solr image: solr:8 command: - - solr-precreate - args: - - packages + - bash + - /opt/solr-start/solr-start.sh ports: - containerPort: 8983 resources: {} @@ -35,6 +34,8 @@ spec: - name: config-volume mountPath: /opt/solr/server/solr/configsets/packages readOnly: true + - name: script-volume + mountpath: /opt/solr-start readinessProbe: timeoutSeconds: 1 initialDelaySeconds: 30 @@ -54,6 +55,9 @@ spec: - name: config-volume configMap: name: solr-configmap + - name: script-volume + configMap: + name: solr-start-configmap triggers: - type: ConfigChange diff --git a/roles/openshift-apps/solr/templates/solr-start.sh b/roles/openshift-apps/solr/templates/solr-start.sh new file mode 100644 index 0000000000..da4fbfccb4 --- /dev/null +++ b/roles/openshift-apps/solr/templates/solr-start.sh @@ -0,0 +1,73 @@ +#!/bin/bash +# +# Taken from https://github.com/docker-solr/docker-solr/blob/master/scripts/solr-precreate +# Chnaged so that Solr itself is called with -p 8983 (otherwise it will crash). +set -e + +if [[ "${VERBOSE:-}" == "yes" ]]; then + set -x +fi + +# init script for handling an empty /var/solr +/opt/docker-solr/scripts/init-var-solr + +. /opt/docker-solr/scripts/run-initdb + +/opt/docker-solr/scripts/precreate-core "packages" + +#!/bin/bash +# +# start solr in the foreground +set -e + +if [[ "$VERBOSE" == "yes" ]]; then + set -x +fi + +EXTRA_ARGS=() +EXTRA_ARGS+=(-a '-p 8983') + +# Start of https://github.com/docker-solr/docker-solr/blob/master/scripts/solr-fg +if [[ -z "${OOM:-}" ]]; then + OOM='none' +fi +case "$OOM" in + 'script') + EXTRA_ARGS+=(-a '-XX:OnOutOfMemoryError=/opt/docker-solr/scripts/oom_solr.sh') + ;; + 'exit') + # recommended + EXTRA_ARGS+=(-a '-XX:+ExitOnOutOfMemoryError') + ;; + 'crash') + EXTRA_ARGS+=(-a '-XX:+CrashOnOutOfMemoryError') + ;; + 'none'|'') + ;; + *) + echo "Unsupported value in OOM=$OOM" + exit 1 +esac + +echo "Starting Solr $SOLR_VERSION" +# determine TINI default. If it is already set, assume the user knows what they want +if [[ -z "${TINI:-}" ]]; then + if [[ "$$" == 1 ]]; then + # Default to running tini, so we can run with an OOM script and have 'kill -9' work + TINI=yes + else + # Presumably we're already running under tini through 'docker --init', in which case we + # don't need to run it twice. + # It's also possible that we're run from a wrapper script without exec, + # in which case running tini would not be ideal either. + TINI=no + fi +fi +if [[ "$TINI" == yes ]]; then + exec /usr/bin/tini -- solr -f "$@" "${EXTRA_ARGS[@]}" +elif [[ "$TINI" == no ]]; then + exec solr -f "$@" "${EXTRA_ARGS[@]}" +else + echo "invalid value TINI=$TINI" + exit 1 +fi \ No newline at end of file