|
| 1 | +#!/bin/bash |
| 2 | +# Copyright 2018, 2019, Oracle Corporation and/or its affiliates. All rights reserved. |
| 3 | +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. |
| 4 | +# |
| 5 | +# Description: |
| 6 | +# |
| 7 | +# This script generates a domain by calling the WebLogic Deploy Tool (WDT) |
| 8 | +# bin/createDomain.sh script. |
| 9 | +# |
| 10 | +# It first installs WDT using the given download URLs, and then runs it using the |
| 11 | +# given Oracle home, 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/weblogic-deploy-tooling-0.24/$WDT_INSTALL_ZIP_FILE |
| 49 | +# |
| 50 | +# https_proxy Proxy for downloading WDT_INSTALL_ZIP_URL. |
| 51 | +# default: "http://www-proxy-hqdc.us.oracle.com:80" |
| 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 | +# |
| 63 | +# DOMAIN_HOME_DIR Target location for generated domain. |
| 64 | +# |
| 65 | + |
| 66 | +# Initialize globals |
| 67 | + |
| 68 | +export ORACLE_HOME=${ORACLE_HOME:-/u01/oracle} |
| 69 | + |
| 70 | +SCRIPTPATH="$( cd "$(dirname "$0")" > /dev/null 2>&1 ; pwd -P )" |
| 71 | +WDT_MODEL_FILE=${WDT_MODEL_FILE:-"$SCRIPTPATH/wdt_model.yaml"} |
| 72 | +WDT_VAR_FILE=${WDT_VAR_FILE:-"$SCRIPTPATH/create-domain-inputs.yaml"} |
| 73 | + |
| 74 | +WDT_DIR=${WDT_DIR:-/shared/wdt} |
| 75 | + |
| 76 | +WDT_INSTALL_ZIP_FILE="${WDT_INSTALL_ZIP_FILE:-weblogic-deploy.zip}" |
| 77 | +WDT_INSTALL_ZIP_URL=${WDT_INSTALL_ZIP_URL:-"https://github.com/oracle/weblogic-deploy-tooling/releases/download/weblogic-deploy-tooling-0.24/$WDT_INSTALL_ZIP_FILE"} |
| 78 | + |
| 79 | +# using "-" instead of ":-" in case proxy vars are explicitly set to "". |
| 80 | +https_proxy=${https_proxy-""} |
| 81 | +https_proxy2=${https_proxy2-"http://www-proxy-hqdc.us.oracle.com:80"} |
| 82 | + |
| 83 | +# Define functions |
| 84 | + |
| 85 | +function setup_wdt_shared_dir { |
| 86 | + mkdir -p $WDT_DIR || return 1 |
| 87 | +} |
| 88 | + |
| 89 | +function install_wdt { |
| 90 | + # |
| 91 | + # Download $WDT_INSTALL_ZIP_FILE from $WDT_INSTALL_ZIP_URL into $WDT_DIR using |
| 92 | + # proxies https_proxy or https_proxy2, then unzip the zip file in $WDT_DIR. |
| 93 | + # |
| 94 | + |
| 95 | + local save_dir=`pwd` |
| 96 | + cd $WDT_DIR || return 1 |
| 97 | + |
| 98 | + local curl_res=1 |
| 99 | + for proxy in "${https_proxy}" "${https_proxy2}"; do |
| 100 | + echo @@ "Info: Downloading $WDT_INSTALL_ZIP_URL with https_proxy=\"$proxy\"" |
| 101 | + https_proxy="${proxy}" \ |
| 102 | + curl --silent --show-error --connect-timeout 10 -O -L $WDT_INSTALL_ZIP_URL |
| 103 | + curl_res=$? |
| 104 | + [ $curl_res -eq 0 ] && break |
| 105 | + done |
| 106 | + |
| 107 | + if [ $curl_res -ne 0 ] || [ ! -f $WDT_INSTALL_ZIP_FILE ]; then |
| 108 | + cd $save_dir |
| 109 | + echo @@ "Error: Download failed or $WDT_INSTALL_ZIP_FILE not found." |
| 110 | + return 1 |
| 111 | + fi |
| 112 | + |
| 113 | + echo @@ "Info: Archive downloaded to $WDT_DIR/$WDT_INSTALL_ZIP_FILE, about to unzip via 'jar xf'." |
| 114 | + |
| 115 | + jar xf $WDT_INSTALL_ZIP_FILE |
| 116 | + local jar_res=$? |
| 117 | + |
| 118 | + cd $save_dir |
| 119 | + |
| 120 | + if [ $jar_res -ne 0 ]; then |
| 121 | + echo @@ "Error: Install failed while unzipping $WDT_DIR/$WDT_INSTALL_ZIP_FILE" |
| 122 | + return $jar_res |
| 123 | + fi |
| 124 | + |
| 125 | + if [ ! -d "$WDT_DIR/weblogic-deploy/bin" ]; then |
| 126 | + echo @@ "Error: Install failed: directory '$WDT_DIR/weblogic-deploy/bin' not found." |
| 127 | + return 1 |
| 128 | + fi |
| 129 | + |
| 130 | + chmod 775 $WDT_DIR/weblogic-deploy/bin/* || return 1 |
| 131 | + |
| 132 | + echo @@ "Info: Install succeeded, wdt install is in the $WDT_DIR/weblogic-deploy directory." |
| 133 | + return 0 |
| 134 | +} |
| 135 | + |
| 136 | +function run_wdt { |
| 137 | + # |
| 138 | + # Run WDT using WDT_VAR_FILE, WDT_MODEL_FILE, and ORACLE_HOME. |
| 139 | + # Output: |
| 140 | + # - result domain will be in DOMAIN_HOME_DIR |
| 141 | + # - logging output is in $WDT_DIR/createDomain.sh.out and $WDT_DIR/weblogic-deploy/logs |
| 142 | + # - WDT_VAR_FILE & WDT_MODEL_FILE will be copied to WDT_DIR. |
| 143 | + # |
| 144 | + |
| 145 | + # Input files and directories. |
| 146 | + |
| 147 | + local inputs_orig="$WDT_VAR_FILE" |
| 148 | + local model_orig="$WDT_MODEL_FILE" |
| 149 | + local oracle_home="$ORACLE_HOME" |
| 150 | + local wdt_bin_dir="$WDT_DIR/weblogic-deploy/bin" |
| 151 | + local wdt_createDomain_script="$wdt_bin_dir/createDomain.sh" |
| 152 | + |
| 153 | + local domain_home_dir="$DOMAIN_HOME_DIR" |
| 154 | + if [ -z "${domain_home_dir}" ]; then |
| 155 | + local domain_dir="/shared/domains" |
| 156 | + local domain_uid=`egrep 'domainUID' $inputs_orig | awk '{print $2}'` |
| 157 | + local domain_home_dir=$domain_dir/$domain_uid |
| 158 | + fi |
| 159 | + |
| 160 | + echo domain_home_dir = $domain_home_dir |
| 161 | + |
| 162 | + # Output files and directories. |
| 163 | + |
| 164 | + local inputs_final=$WDT_DIR/$(basename "$inputs_orig") |
| 165 | + local model_final=$WDT_DIR/$(basename "$model_orig") |
| 166 | + local out_file=$WDT_DIR/createDomain.sh.out |
| 167 | + local wdt_log_dir="$WDT_DIR/weblogic-deploy/logs" |
| 168 | + |
| 169 | + echo @@ "Info: About to run WDT createDomain.sh" |
| 170 | + |
| 171 | + for directory in wdt_bin_dir SCRIPTPATH WDT_DIR oracle_home; do |
| 172 | + if [ ! -d "${!directory}" ]; then |
| 173 | + echo @@ "Error: Could not find ${directory} directory ${!directory}." |
| 174 | + return 1 |
| 175 | + fi |
| 176 | + done |
| 177 | + |
| 178 | + for fil in inputs_orig model_orig wdt_createDomain_script; do |
| 179 | + if [ ! -f "${!fil}" ]; then |
| 180 | + echo @@ "Error: Could not find ${fil} file ${!fil}." |
| 181 | + return 1 |
| 182 | + fi |
| 183 | + done |
| 184 | + |
| 185 | + cp $model_orig $model_final || return 1 |
| 186 | + cp $inputs_orig $inputs_final || return 1 |
| 187 | + |
| 188 | + local save_dir=`pwd` |
| 189 | + cd $WDT_DIR || return 1 |
| 190 | + |
| 191 | + echo @@ "Info: WDT createDomain.sh output will be in $out_file and $wdt_log_dir" |
| 192 | + |
| 193 | + # domain_type can be WLS, JRF or RestrictedJRF |
| 194 | + $wdt_createDomain_script \ |
| 195 | + -oracle_home $oracle_home \ |
| 196 | + -domain_type JRF \ |
| 197 | + -domain_home $domain_home_dir \ |
| 198 | + -model_file $model_final \ |
| 199 | + -variable_file $inputs_final > $out_file 2>&1 |
| 200 | + |
| 201 | + local wdt_res=$? |
| 202 | + |
| 203 | + cd $save_dir |
| 204 | + |
| 205 | + if [ $wdt_res -ne 0 ]; then |
| 206 | + cat $WDT_DIR/createDomain.sh.out |
| 207 | + echo @@ "Info: WDT createDomain.sh output is in $out_file and $wdt_log_dir" |
| 208 | + echo @@ "Error: WDT createDomain.sh failed." |
| 209 | + return 1 |
| 210 | + fi |
| 211 | + |
| 212 | + echo @@ "Info: WDT createDomain.sh succeeded." |
| 213 | + return 0 |
| 214 | +} |
| 215 | + |
| 216 | +# Run |
| 217 | + |
| 218 | +setup_wdt_shared_dir || exit 1 |
| 219 | + |
| 220 | +install_wdt || exit 1 |
| 221 | + |
| 222 | +run_wdt || exit 1 |
0 commit comments