-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.sh
executable file
·127 lines (109 loc) · 2.35 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env bash
__DIR__="$(dirname "$("${READLINK_PATH:-readlink}" -f "$0")")"
# required libs
source "${__DIR__}/.bash/functions.shlib"
set -E
trap 'throw_exception' ERR
usage() {
cat <<EOF
Usage: ${0##*/} OPTIONS
test role
-h display this help and exit
-i STRING target host to run against (default: 127.0.0.1)
-u STRING connect as this user (default: current user)
EOF
}
OPTIND=1
while getopts "hi:u:" opt; do
case "${opt}" in
h )
usage
exit 0
;;
i )
TARGET_HOST="${OPTARG}"
;;
u )
CONNECT_USER="${OPTARG}"
;;
'?' )
usage >&2
exit 1
;;
esac
done
shift "$((OPTIND-1))"
if [[ -z "${TARGET_HOST}" ]]; then
TARGET_HOST="127.0.0.1"
CONNECTION="local"
fi
if [[ -z "${CONNECT_USER}" ]]; then
CONNECT_USER="$(whoami)"
fi
if [[ -z "${CONNECTION}" ]]; then
CONNECTION="smart"
fi
role_root="$(pwd)"
consolelog "installing requirements"
# does not work with travis/precise
if [[ -z "${TRAVIS}" ]]; then
ansible-galaxy install lifeofguenter.oracle-java
else
cat <<'EOF' > meta/main.yml
galaxy_info:
author: Gunter Grodotzki
description: Installs GlassFish on Debian-like systems.
company: 9JKH (Pty) Ltd.
license: MIT
min_ansible_version: 2.4
platforms:
- name: Ubuntu
versions:
- xenial
- trusty
- name: Debian
versions:
- stretch
- jessie
galaxy_tags:
- system
- development
EOF
fi
consolelog "running role as playbook #1"
ansible-playbook \
--inventory="${TARGET_HOST}," \
--user="${CONNECT_USER}" \
--extra-vars="role_root=${role_root}" \
--connection="${CONNECTION}" \
tests/test.yml
consolelog "running role as playbook #2"
ansible-playbook \
--inventory="${TARGET_HOST}," \
--user="${CONNECT_USER}" \
--extra-vars="role_root=${role_root}" \
--connection="${CONNECTION}" \
tests/test.yml
# waitfor 5min
while [[ "${i}" -lt "60" ]]; do
i="$((i + 1))"
if ! curl \
--head \
--silent \
--fail \
--show-error \
"${TARGET_HOST}:8080" 2> /dev/null; then
consolelog "waitfor ${TARGET_HOST}:8080 #${i}"
sleep 5
else
success="1"
break
fi
done
if [[ -z "${success}" ]]; then
consolelog "glassfish unreachable" "error"
exit 1
fi
if [[ "${CONNECTION}" == "local" ]]; then
glassfish-asadmin version
fi