-
Notifications
You must be signed in to change notification settings - Fork 0
/
app-setup.sh
executable file
·157 lines (133 loc) · 5.61 KB
/
app-setup.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/bash
FUNCTIONS=(wildfly_start_and_wait
config_keycloak_client
config_oracle_client
config_mariadb_client
wildfly_reload
wildfly_stop)
VARIABLES=(KEYCLOAK_REALM
KEYCLOAK_RESOURCE
KEYCLOAK_SECRET
KEYCLOAK_SERVER_URL
KEYCLOAK_WAR
WILDFLY_APP_HOME)
if [[ $# -eq 0 ]] ; then
echo "Usage: $0 [var file] <optional function>"
echo "The var file arg should be the path to a file with bash variables that will be sourced."
echo "The optional function name arg if provided is the sole function to call, else all functions are invoked sequentially."
printf 'Variables: '
printf '%s ' "${VARIABLES[@]}"
printf '\n'
printf 'Functions: '
printf '%s ' "${FUNCTIONS[@]}"
printf '\n'
exit 0
fi
if [ ! -z "$1" ] && [ -f "$1" ]
then
echo "Loading environment $1"
. $1
fi
# Verify expected env set:
for i in "${!VARIABLES[@]}"; do
var=${VARIABLES[$i]}
[ -z "${!var}" ] && { echo "$var is not set. Exiting."; exit 1; }
done
# Optional params
# - ORACLE_DATASOURCE
# - ORACLE_PASS
# - ORACLE_SERVER
# - ORACLE_SERVICE
# - ORACLE_USER
# - MARIADB_DATASOURCE
# - MARIADB_PASS
# - MARIADB_SERVER
# - MARIADB_DB_NAME
# - MARIADB_USER
# - WILDFLY_SKIP_START
# - WILDFLY_SKIP_STOP
WILDFLY_CLI_PATH=${WILDFLY_APP_HOME}/bin/jboss-cli.sh
wildfly_start_and_wait() {
if [[ ! -z "${WILDFLY_SKIP_START}" ]]; then
echo "Skipping Wildfly start because WILDFLY_SKIP_START defined"
return 0
fi
${WILDFLY_APP_HOME}/bin/standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0 &
until curl http://localhost:8080 -sf -o /dev/null;
do
echo $(date) " Still waiting for Wildfly to start..."
sleep 5
done
echo $(date) " Wildfly started!"
}
config_keycloak_client_dynamic() {
DEPLOYMENT_CONFIG=principal-attribute="preferred_username",ssl-required=EXTERNAL,resource="\${env.KEYCLOAK_RESOURCE:${KEYCLOAK_RESOURCE}}",realm="\${env.KEYCLOAK_REALM:${KEYCLOAK_REALM}}",auth-server-url=\${env.KEYCLOAK_SERVER_URL:${KEYCLOAK_SERVER_URL}}
${WILDFLY_CLI_PATH} -c <<EOF
batch
/subsystem=elytron-oidc-client/secure-deployment="${KEYCLOAK_WAR}"/:add(${DEPLOYMENT_CONFIG})
/subsystem=elytron-oidc-client/secure-deployment="${KEYCLOAK_WAR}"/credential=secret:add(secret="\${env.KEYCLOAK_SECRET:${KEYCLOAK_SECRET}}")
run-batch
EOF
}
config_keycloak_client() {
DEPLOYMENT_CONFIG=principal-attribute="preferred_username",ssl-required=EXTERNAL,resource="${KEYCLOAK_RESOURCE}",realm="${KEYCLOAK_REALM}",auth-server-url=${KEYCLOAK_SERVER_URL}
${WILDFLY_CLI_PATH} -c <<EOF
batch
/subsystem=elytron-oidc-client/secure-deployment="${KEYCLOAK_WAR}"/:add(${DEPLOYMENT_CONFIG})
/subsystem=elytron-oidc-client/secure-deployment="${KEYCLOAK_WAR}"/credential=secret:add(secret="${KEYCLOAK_SECRET}")
run-batch
EOF
}
config_oracle_client_dynamic() {
${WILDFLY_CLI_PATH} -c <<EOF
batch
data-source add --name=jdbc/${ORACLE_DATASOURCE} --driver-name=oracle --jndi-name=java:/jdbc/${ORACLE_DATASOURCE} --connection-url=jdbc:oracle:thin:@//\${env.ORACLE_SERVER:${ORACLE_SERVER}}/\${env.ORACLE_SERVICE:${ORACLE_SERVICE}} --user-name=\${env.ORACLE_USER:${ORACLE_USER}} --password=\${env.ORACLE_PASS:${ORACLE_PASS}} --max-pool-size=3 --min-pool-size=1 --flush-strategy=EntirePool --use-fast-fail=true --blocking-timeout-wait-millis=5000 --query-timeout=30 --idle-timeout-minutes=5 --background-validation=true --background-validation-millis=30000 --validate-on-match=false --check-valid-connection-sql="select 1 from dual" --prepared-statements-cache-size=10 --share-prepared-statements=true
run-batch
EOF
}
config_oracle_client() {
if [[ -z "${ORACLE_DATASOURCE}" ]]; then
echo "Skipping config_oracle_client because ORACLE_DATASOURCE undefined"
return 0
fi
${WILDFLY_CLI_PATH} -c <<EOF
batch
data-source add --name=jdbc/${ORACLE_DATASOURCE} --driver-name=oracle --jndi-name=java:/jdbc/${ORACLE_DATASOURCE} --connection-url=jdbc:oracle:thin:@//${ORACLE_SERVER}/${ORACLE_SERVICE} --user-name=${ORACLE_USER} --password=${ORACLE_PASS} --max-pool-size=3 --min-pool-size=1 --flush-strategy=EntirePool --use-fast-fail=true --blocking-timeout-wait-millis=5000 --query-timeout=30 --idle-timeout-minutes=5 --background-validation=true --background-validation-millis=30000 --validate-on-match=false --check-valid-connection-sql="select 1 from dual" --prepared-statements-cache-size=10 --share-prepared-statements=true
run-batch
EOF
}
config_mariadb_client() {
if [[ -z "${MARIADB_DATASOURCE}" ]]; then
echo "Skipping config_mariadb_client because MARIADB_DATASOURCE undefined"
return 0
fi
${WILDFLY_CLI_PATH} -c <<EOF
batch
data-source add --name=jdbc/${MARIADB_DATASOURCE} --driver-name=mariadb --jndi-name=java:/jdbc/${MARIADB_DATASOURCE} --connection-url=jdbc:mariadb://${MARIADB_SERVER}/${MARIADB_DB_NAME} --user-name=${MARIADB_USER} --password=${MARIADB_PASS} --max-pool-size=3 --min-pool-size=1 --flush-strategy=EntirePool --use-fast-fail=true --blocking-timeout-wait-millis=5000 --query-timeout=30 --idle-timeout-minutes=5 --background-validation=true --background-validation-millis=30000 --validate-on-match=false --check-valid-connection-sql="select 1 from dual" --prepared-statements-cache-size=10 --share-prepared-statements=true
run-batch
EOF
}
wildfly_reload() {
${WILDFLY_CLI_PATH} -c reload
}
wildfly_stop() {
if [[ ! -z "${WILDFLY_SKIP_STOP}" ]]; then
echo "Skipping Wildfly stop because WILDFLY_SKIP_STOP defined"
return 0
fi
${WILDFLY_CLI_PATH} -c shutdown
}
if [ ! -z "$2" ]
then
echo "------------------------"
echo "$2"
echo "------------------------"
$2
else
for i in "${!FUNCTIONS[@]}"; do
echo "------------------------"
echo "${FUNCTIONS[$i]}"
echo "------------------------"
${FUNCTIONS[$i]};
done
fi