|
| 1 | +#!/bin/bash |
| 2 | +# Copyright (c) 2021, Oracle and/or its affiliates. |
| 3 | +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. |
| 4 | +# |
| 5 | +# Description: |
| 6 | +# |
| 7 | +# This script generates model files and variables files by calling WebLogic Deploy Tool (WDT) |
| 8 | +# bin/discoverDomain.sh script on an on-prem domain. |
| 9 | +# |
| 10 | +# It first installs WDT using the given download URLs, and then runs it using the |
| 11 | +# given Oracle home. It then generates WDT model file, WDT vars file, etc. |
| 12 | +# |
| 13 | +# Usage: |
| 14 | +# |
| 15 | +# Export customized values for the input shell environment variables as needed |
| 16 | +# before calling this script. |
| 17 | +# |
| 18 | +# Outputs: |
| 19 | +# |
| 20 | +# WDT install: WDT_DIR/weblogic-deploy/... |
| 21 | +# |
| 22 | +# Copy of wdt model: WDT_DIR/$(basename WDT_MODEL_FILE) |
| 23 | +# Copy of wdt vars: WDT_DIR/$(basename WDT_VAR_FILE) |
| 24 | +# |
| 25 | +# WDT logs: WDT_DIR/weblogic-deploy/logs/... |
| 26 | +# WDT stdout: WDT_DIR/createDomain.sh.out |
| 27 | +# |
| 28 | +# WebLogic domain home: DOMAIN_HOME_DIR |
| 29 | +# default: /shared/domains/<domainUID> |
| 30 | +# |
| 31 | +# Input environment variables: |
| 32 | +# |
| 33 | +# ORACLE_HOME Oracle home with a WebLogic install. |
| 34 | +# default: /u01/oracle |
| 35 | +# |
| 36 | +# WDT_MODEL_FILE Full path to WDT model file. |
| 37 | +# default: the directory that contains this script |
| 38 | +# plus "/wdt_model.yaml" |
| 39 | +# |
| 40 | +# WDT_VAR_FILE Full path to WDT variable file (java properties format). |
| 41 | +# default: the directory that contains this script |
| 42 | +# plus "/create-domain-inputs.yaml" |
| 43 | +# |
| 44 | +# WDT_INSTALL_ZIP_FILE Filename of WDT install zip. |
| 45 | +# default: weblogic-deploy.zip |
| 46 | +# |
| 47 | +# WDT_INSTALL_ZIP_URL URL for downloading WDT install zip |
| 48 | +# default: https://github.com/oracle/weblogic-deploy-tooling/releases/download/release-1.9.7/$WDT_INSTALL_ZIP_FILE |
| 49 | +# |
| 50 | +# https_proxy Proxy for downloading WDT_INSTALL_ZIP_URL. |
| 51 | +# default: "" |
| 52 | +# (If set to empty the script will try with no proxy.) |
| 53 | +# |
| 54 | +# https_proxy2 Alternate proxy for downloading WDT_INSTALL_ZIP_URL |
| 55 | +# default: "" |
| 56 | +# (If set to empty the script will try with no proxy.) |
| 57 | +# |
| 58 | +# WDT_DIR Target location to install and run WDT, and to keep a copy of |
| 59 | +# $WDT_MODEL_FILE and $WDT_MODEL_VARS. Also the location |
| 60 | +# of WDT log files. |
| 61 | +# default: /shared/wdt |
| 62 | +# WDT_VERSION WDT version to download. |
| 63 | +# default: latest |
| 64 | +# |
| 65 | +# DOMAIN_HOME_DIR Target location for generated domain. |
| 66 | +# |
| 67 | +# DOMAIN_TYPE Domain type. It can be WLS, JRF or RestrictedJRF. Default is WLS |
| 68 | +# |
| 69 | + |
| 70 | +# Initialize globals |
| 71 | + |
| 72 | +# using "-" instead of ":-" in case proxy vars are explicitly set to "". |
| 73 | +https_proxy=${https_proxy-""} |
| 74 | +https_proxy2=${https_proxy2-""} |
| 75 | +domain_src=${DOMAIN_SRC-""} |
| 76 | +discover_domain_output_dir=${DISCOVER_DOMAIN_OUTPUT_DIR-""} |
| 77 | +app=${APP-""} |
| 78 | + |
| 79 | +export ORACLE_HOME=${ORACLE_HOME:-/u01/oracle} |
| 80 | + |
| 81 | +SCRIPTPATH="$( cd "$(dirname "$0")" > /dev/null 2>&1 ; pwd -P )" |
| 82 | + |
| 83 | +WDT_DIR=${WDT_DIR:-/u01/wdt} |
| 84 | +if [ -z "${WDT_VERSION+x}" ] || [ ${WDT_VERSION} == "latest" ]; then |
| 85 | + curl_res=1 |
| 86 | + max=20 |
| 87 | + count=0 |
| 88 | + while [ $curl_res -ne 0 -a $count -lt $max ] ; do |
| 89 | + sleep 1 |
| 90 | + for proxy in "${https_proxy2}" "${https_proxy}"; do |
| 91 | + echo @@ "Info: Getting latest release WDT url with https_proxy=\"$proxy\"" |
| 92 | + https_proxy="${proxy}" \ |
| 93 | + curl -Ls -w %{url_effective} --connect-timeout 30 -o /dev/null \ |
| 94 | + https://github.com/oracle/weblogic-deploy-tooling/releases/latest > out |
| 95 | + curl_res=$? |
| 96 | + if [ $curl_res -eq 0 ]; then |
| 97 | + echo "Got URL $(cat out)" |
| 98 | + WDT_BASE_URL=$(cat out | sed -e "s/tag/download/g") |
| 99 | + rm out |
| 100 | + break |
| 101 | + fi |
| 102 | + done |
| 103 | + done |
| 104 | +else |
| 105 | +WDT_BASE_URL="https://github.com/oracle/weblogic-deploy-tooling/releases/download/release-$WDT_VERSION" |
| 106 | +fi |
| 107 | + |
| 108 | +WDT_INSTALL_ZIP_FILE="${WDT_INSTALL_ZIP_FILE:-weblogic-deploy.zip}" |
| 109 | +WDT_INSTALL_ZIP_URL=${WDT_INSTALL_ZIP_URL:-"$WDT_BASE_URL/$WDT_INSTALL_ZIP_FILE"} |
| 110 | + |
| 111 | +DOMAIN_TYPE="${DOMAIN_TYPE:-WLS}" |
| 112 | +TARGET_TYPE="${TARGET_TYPE:-wko}" |
| 113 | + |
| 114 | +# Define functions |
| 115 | + |
| 116 | +function setup_wdt_shared_dir { |
| 117 | + mkdir -p $WDT_DIR || return 1 |
| 118 | +} |
| 119 | + |
| 120 | +function install_wdt { |
| 121 | + # |
| 122 | + # Download $WDT_INSTALL_ZIP_FILE from $WDT_INSTALL_ZIP_URL into $WDT_DIR using |
| 123 | + # proxies https_proxy or https_proxy2, then unzip the zip file in $WDT_DIR. |
| 124 | + # |
| 125 | + |
| 126 | + local save_dir=`pwd` |
| 127 | + cd $WDT_DIR || return 1 |
| 128 | + |
| 129 | + local curl_res=1 |
| 130 | + max=20 |
| 131 | + count=0 |
| 132 | + while [ $curl_res -ne 0 -a $count -lt $max ] ; do |
| 133 | + sleep 10 |
| 134 | + count=`expr $count + 1` |
| 135 | + for proxy in "${https_proxy}" "${https_proxy2}"; do |
| 136 | + echo @@ "Info: Downloading $WDT_INSTALL_ZIP_URL with https_proxy=\"$proxy\"" |
| 137 | + https_proxy="${proxy}" \ |
| 138 | + curl --silent --show-error --connect-timeout 10 -O -L $WDT_INSTALL_ZIP_URL |
| 139 | + curl_res=$? |
| 140 | + [ $curl_res -eq 0 ] && break |
| 141 | + done |
| 142 | + done |
| 143 | + if [ $curl_res -ne 0 ] || [ ! -f $WDT_INSTALL_ZIP_FILE ]; then |
| 144 | + cd $save_dir |
| 145 | + echo @@ "Error: Download failed or $WDT_INSTALL_ZIP_FILE not found." |
| 146 | + return 1 |
| 147 | + fi |
| 148 | + |
| 149 | + echo @@ "Info: Archive downloaded to $WDT_DIR/$WDT_INSTALL_ZIP_FILE, about to unzip via 'jar xf'." |
| 150 | + |
| 151 | + jar xf $WDT_INSTALL_ZIP_FILE |
| 152 | + local jar_res=$? |
| 153 | + |
| 154 | + cd $save_dir |
| 155 | + |
| 156 | + if [ $jar_res -ne 0 ]; then |
| 157 | + echo @@ "Error: Install failed while unzipping $WDT_DIR/$WDT_INSTALL_ZIP_FILE" |
| 158 | + return $jar_res |
| 159 | + fi |
| 160 | + |
| 161 | + if [ ! -d "$WDT_DIR/weblogic-deploy/bin" ]; then |
| 162 | + echo @@ "Error: Install failed: directory '$WDT_DIR/weblogic-deploy/bin' not found." |
| 163 | + return 1 |
| 164 | + fi |
| 165 | + |
| 166 | + chmod 775 $WDT_DIR/weblogic-deploy/bin/* || return 1 |
| 167 | + |
| 168 | + echo @@ "Info: Install succeeded, wdt install is in the $WDT_DIR/weblogic-deploy directory." |
| 169 | + return 0 |
| 170 | +} |
| 171 | + |
| 172 | +function run_wdt { |
| 173 | + # |
| 174 | + # Run WDT using WDT_VAR_FILE, WDT_MODEL_FILE, and ORACLE_HOME. |
| 175 | + # Output: |
| 176 | + # - result domain will be in DOMAIN_HOME_DIR |
| 177 | + # - logging output is in $WDT_DIR/createDomain.sh.out and $WDT_DIR/weblogic-deploy/logs |
| 178 | + # - WDT_VAR_FILE & WDT_MODEL_FILE will be copied to WDT_DIR. |
| 179 | + # |
| 180 | + |
| 181 | + # Input files and directories. |
| 182 | + |
| 183 | + local inputs_orig="$WDT_VAR_FILE" |
| 184 | + local model_orig="$WDT_MODEL_FILE" |
| 185 | + local oracle_home="$ORACLE_HOME" |
| 186 | + local wdt_bin_dir="$WDT_DIR/weblogic-deploy/bin" |
| 187 | + local wdt_discoverDomain_script="$wdt_bin_dir/discoverDomain.sh" |
| 188 | + |
| 189 | + local domain_home_dir="/u01/$domain_src" |
| 190 | + if [ -z "${domain_home_dir}" ]; then |
| 191 | + local domain_dir="/shared/domains" |
| 192 | + local domain_uid=`egrep 'domainUID' $inputs_orig | awk '{print $2}'` |
| 193 | + local domain_home_dir=$domain_dir/$domain_uid |
| 194 | + fi |
| 195 | + |
| 196 | + echo domain_home_dir = $domain_home_dir |
| 197 | + mkdir -p $domain_home_dir |
| 198 | + unzip /u01/${domain_src}.zip -d $domain_home_dir |
| 199 | + |
| 200 | + # Output files and directories. |
| 201 | + |
| 202 | + local variable_file=${domain_src}.properties |
| 203 | + local model_file=${domain_src}.yaml |
| 204 | + local archive_file=${app}.zip |
| 205 | + local output_dir="/u01/${discover_domain_output_dir}" |
| 206 | + mkdir -p $output_dir |
| 207 | + local out_file=$WDT_DIR/discoverDomain.sh.out |
| 208 | + local wdt_log_dir="$WDT_DIR/weblogic-deploy/logs" |
| 209 | + |
| 210 | + local domain_type="$DOMAIN_TYPE" |
| 211 | + local target_type="$TARGET_TYPE" |
| 212 | + |
| 213 | + echo @@ "Info: About to run WDT discoverDomain.sh to generate required files to create $domain_type Domain" |
| 214 | + |
| 215 | + for directory in wdt_bin_dir SCRIPTPATH WDT_DIR oracle_home; do |
| 216 | + if [ ! -d "${!directory}" ]; then |
| 217 | + echo @@ "Error: Could not find ${directory} directory ${!directory}." |
| 218 | + return 1 |
| 219 | + fi |
| 220 | + done |
| 221 | + |
| 222 | + local save_dir=`pwd` |
| 223 | + cd $output_dir || return 1 |
| 224 | + |
| 225 | + echo @@ "Info: WDT discoverDomain.sh output will be in $out_file and $wdt_log_dir" |
| 226 | + |
| 227 | + $wdt_discoverDomain_script \ |
| 228 | + -oracle_home $oracle_home \ |
| 229 | + -target $target_type \ |
| 230 | + -domain_home $domain_home_dir \ |
| 231 | + -model_file $model_file \ |
| 232 | + -variable_file $variable_file \ |
| 233 | + -archive_file $archive_file \ |
| 234 | + -output_dir $output_dir > $out_file 2>&1 |
| 235 | + |
| 236 | + local wdt_res=$? |
| 237 | + |
| 238 | + cd $save_dir |
| 239 | + |
| 240 | + if [ $wdt_res -ne 0 ]; then |
| 241 | + cat $WDT_DIR/discoverDomain.sh.out |
| 242 | + echo @@ "Info: WDT discoverDomain.sh output is in $out_file and $wdt_log_dir" |
| 243 | + echo @@ "Error: WDT discoverDomain.sh failed." |
| 244 | + return 1 |
| 245 | + fi |
| 246 | + |
| 247 | + echo @@ "Info: WDT createDomain.sh succeeded." |
| 248 | + return 0 |
| 249 | +} |
| 250 | + |
| 251 | +# Run |
| 252 | + |
| 253 | +setup_wdt_shared_dir || exit 1 |
| 254 | + |
| 255 | +install_wdt || exit 1 |
| 256 | + |
| 257 | +run_wdt || exit 1 |
0 commit comments