|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Copyright 2015-2020 the original author or authors. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | + |
| 18 | +SERVER_PORT=8080 |
| 19 | + |
| 20 | +rootDir=$( |
| 21 | + cd "$(dirname "$0")"/.. || exit |
| 22 | + pwd |
| 23 | +) |
| 24 | + |
| 25 | +printf "%s \033[32mINFO\033[m : %s\n" "$(date '+%Y-%m-%d %H:%M:%S.000')" "Start run fat jars" |
| 26 | + |
| 27 | +targets=$(find "${rootDir}" -type f | grep -E "target/mybatis-spring-boot-sample-[a-z]*-[\.1-9]*.*\.jar$") |
| 28 | + |
| 29 | +for target in ${targets}; do |
| 30 | + printf "\n%s \033[32mINFO\033[m : %s\n" "$(date '+%Y-%m-%d %H:%M:%S.000')" "Run the '$(basename "${target}")'" |
| 31 | + if [[ "${target}" == *web* ]]; then |
| 32 | + java -jar "${target}" & |
| 33 | + pid=$! |
| 34 | + for i in $(seq 10); do |
| 35 | + if [ "$(ps -p "${pid}" | grep -c "")" = "2" ] && [ "$(lsof -i:${SERVER_PORT})" = "" ]; then |
| 36 | + sleep 1 |
| 37 | + else |
| 38 | + break |
| 39 | + fi |
| 40 | + done |
| 41 | + statusCode="$(curl -s http://localhost:${SERVER_PORT}/cities/US -o /dev/null -w '%{http_code}\n')" |
| 42 | + if [ "${statusCode}" = "200" ]; then resultCode=0; else resultCode=${statusCode}; fi |
| 43 | + kill ${pid} |
| 44 | + wait ${pid} |
| 45 | + else |
| 46 | + java -jar "${target}" && resultCode=0 || resultCode=$? |
| 47 | + fi |
| 48 | + results="${results}${target} ${resultCode}"$'\n' |
| 49 | +done |
| 50 | + |
| 51 | +exitCode=0 |
| 52 | +while read -r line; do |
| 53 | + if [ ! "${line}" = "" ]; then |
| 54 | + set ${line} |
| 55 | + target=${1} |
| 56 | + resultCode=${2} |
| 57 | + if [ "${resultCode}" = "0" ]; then |
| 58 | + printf "%s \033[32mINFO\033[m : %s\n" "$(date '+%Y-%m-%d %H:%M:%S.000')" "Succeed an execution of '$(basename "${target}")'" |
| 59 | + else |
| 60 | + exitCode=1 |
| 61 | + printf "%s \033[31mERROR\033[m : %s\n" "$(date '+%Y-%m-%d %H:%M:%S.000')" "Faild an execution of '$(basename "${target}")' resultCode=${resultCode}" |
| 62 | + fi |
| 63 | + fi |
| 64 | +done <<END |
| 65 | +${results} |
| 66 | +END |
| 67 | + |
| 68 | +exit ${exitCode} |
0 commit comments