|
| 1 | +# SPDX-License-Identifier: EPL-1.0 |
| 2 | +############################################################################## |
| 3 | +# Copyright (c) 2021 The Linux Foundation and others. |
| 4 | +# |
| 5 | +# All rights reserved. This program and the accompanying materials |
| 6 | +# are made available under the terms of the Eclipse Public License v1.0 |
| 7 | +# which accompanies this distribution, and is available at |
| 8 | +# http://www.eclipse.org/legal/epl-v10.html |
| 9 | +############################################################################## |
| 10 | +#!/bin/bash -e |
| 11 | + |
| 12 | +function setup_cluster(){ |
| 13 | + if [ -z $ODL_REPLICAS ]; then |
| 14 | + echo "ODL_REPLICAS is not configured in Env field" |
| 15 | + exit |
| 16 | + fi |
| 17 | + |
| 18 | + hm=$(hostname) |
| 19 | + echo "Enable cluster for host: ${hm}" |
| 20 | + |
| 21 | + ## For hostname viz; odl-opendaylight-1, |
| 22 | + ## node_name will be 'odl-opendaylight' and node_index '1' |
| 23 | + node_name=${hm%-*}; |
| 24 | + node_index=${hm##*-}; |
| 25 | + node_list="${node_name}-0.{{ include "opendaylight.fullname" . }}.{{ .Release.Namespace }}"; |
| 26 | + |
| 27 | + for ((i=1;i<${ODL_REPLICAS};i++)); |
| 28 | + do |
| 29 | + node_list="${node_list} ${node_name}-$i.{{ include "opendaylight.fullname" . }}.{{ .Release.Namespace }}" |
| 30 | + done |
| 31 | + |
| 32 | + ${BASEDIR}/bin/configure_cluster.sh $((node_index+1)) ${node_list} |
| 33 | +} |
| 34 | + |
| 35 | +set -x |
| 36 | + |
| 37 | +mountpath="{{ .Values.persistence.mountPath }}" |
| 38 | +BASEDIR="{{ .Values.config.odl_basedir }}" |
| 39 | +odl_prefix="/opt/opendaylight" |
| 40 | + |
| 41 | +if [[ ! -d "$mountpath/snapshots" ]];then |
| 42 | + mkdir -p $mountpath/snapshots |
| 43 | +fi |
| 44 | + |
| 45 | +if [[ ! -d "$mountpath/data" ]];then |
| 46 | + mkdir -p $mountpath/data |
| 47 | +fi |
| 48 | + |
| 49 | +if [[ ! -d "$mountpath/segmented-journal" ]];then |
| 50 | + mkdir -p $mountpath/segmented-journal |
| 51 | +fi |
| 52 | + |
| 53 | +if [[ ! -d "$mountpath/daexim" ]];then |
| 54 | + mkdir -p $mountpath/daexim |
| 55 | +fi |
| 56 | + |
| 57 | +if [[ ! -L "$odl_prefix/snapshots" ]];then |
| 58 | + rm -rf $odl_prefix/snapshots && ln -s $mountpath/snapshots $odl_prefix/snapshots |
| 59 | +fi |
| 60 | + |
| 61 | +if [[ ! -L "$odl_prefix/data" ]];then |
| 62 | + rm -rf $odl_prefix/data && ln -s $mountpath/data $odl_prefix/data |
| 63 | +fi |
| 64 | + |
| 65 | +if [[ ! -L "$odl_prefix/segmented-journal" ]];then |
| 66 | + rm -rf $odl_prefix/segmented-journal && ln -s $mountpath/segmented-journal $odl_prefix/segmented-journal |
| 67 | +fi |
| 68 | + |
| 69 | +if [[ ! -L "$odl_prefix/daexim" ]];then |
| 70 | + rm -rf $odl_prefix/daexim && ln -s $mountpath/daexim $odl_prefix/daexim |
| 71 | +fi |
| 72 | + |
| 73 | +sed -i "s/\(featuresBoot= \|featuresBoot = \)/featuresBoot = ${FEATURES},/g" ${BASEDIR}/etc/org.apache.karaf.features.cfg |
| 74 | +cat ${BASEDIR}/etc/org.apache.karaf.features.cfg |
| 75 | + |
| 76 | +ODL_REPLICAS=${ODL_REPLICAS:-1} |
| 77 | +IS_CLUSTER_ENABLED=${IS_CLUSTER_ENABLED:-false} |
| 78 | +SLEEP_TIME=${SLEEP_TIME:-30} |
| 79 | + |
| 80 | +if $IS_CLUSTER_ENABLED; then |
| 81 | + ${BASEDIR}/bin/start; |
| 82 | + echo "Waiting ${SLEEP_TIME} seconds for OpenDaylight to initialize"; |
| 83 | + sleep ${SLEEP_TIME}; |
| 84 | + setup_cluster; |
| 85 | + echo "Restart ODL after cluster configuration"; |
| 86 | + ${BASEDIR}/bin/stop; |
| 87 | + sleep 20; |
| 88 | +fi |
| 89 | + |
| 90 | +echo "Starting OpenDaylight" |
| 91 | +${BASEDIR}/bin/karaf run |
0 commit comments