-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathentrypoint.sh
executable file
·124 lines (110 loc) · 3.92 KB
/
entrypoint.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
#!/bin/sh
trap 'trap " " TERM; kill 0; wait; cleanup' INT TERM
# Make a temporary directory
export SPRING_TMPDIR=$(mktemp -d)
export P12KEYSTORE=${SPRING_TMPDIR}/tls.p12
cleanup () {
if [ -d "${SPRING_TMPDIR}" ]; then
rm -rf ${SPRING_TMPDIR}
fi
}
make_fifo () {
local fifo=$(mktemp -u -p ${SPRING_TMPDIR})
mkfifo -m 600 "${fifo}"
echo "${fifo}"
}
convert_certificate () {
# Openshift/kubernetes provide host certificates in key and crt format.
# Convert on the fly to PKCS12 format, in pipe so that it is used only once.
# A dummy password is included for this operation
TLSDIR=/run/secrets/crest-tls
if [ -e ${TLSDIR}/tls.key ] && [ -e ${TLSDIR}/tls.crt ]; then
echo "Found certificates - converting to PKCS12 format in ${P12KEYSTORE}"
mkfifo -m 600 ${P12KEYSTORE}
openssl pkcs12 -export -out ${P12KEYSTORE} -inkey ${TLSDIR}/tls.key -in ${TLSDIR}/tls.crt -passout pass:dummy_password &
fi
}
print_application_properties () {
if [ -e config/application.properties ] ; then
cat config/application.properties
fi
if [ -e /run/secrets/crest-phys-cond ] ; then
echo "crest.db.password=$(cat /run/secrets/crest-phys-cond)"
fi
if [ -e /run/secrets/crest-trigger-cond ] ; then
echo "crest.triggerdb.password=$(cat /run/secrets/crest-trigger-cond)"
fi
if [ -e /run/secrets/svom-pg-crest ] ; then
echo "crest.db.password=$(cat /run/secrets/svom-pg-crest)"
fi
if [ -e /run/secrets/nats_password ] ; then
echo "svom.nats.password=$(cat /run/secrets/nats_password)"
fi
if [ -e /run/secrets/cool_secret ] ; then
echo "align.cool.writer=$(cat /run/secrets/cool_secret)"
fi
if [ -e /run/secrets/crest-keycloak-secret/client_id ]; then
echo "crest.keycloak.resource=$(cat /run/secrets/crest-keycloak-secret/client_id)"
fi
if [ -e /run/secrets/crest-keycloak-secret/client_secret ]; then
echo "crest.keycloak.secret=$(cat /run/secrets/crest-keycloak-secret/client_secret)"
fi
if [ -e ${P12KEYSTORE} ]; then
echo "server.ssl.key-store-type=PKCS12"
echo "server.ssl.key-store=file:${P12KEYSTORE}"
echo "server.ssl.key-store-password=dummy_password"
#echo "server.ssl.key-alias=FIXME"
echo "server.ssl.enabled=true"
fi
}
## Set working directory
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
if [ -e /usr/local/share/crest ]; then
DIR="$( cd "/usr/local/share/crest" >/dev/null 2>&1 && pwd )"
echo "Use $DIR as working directory"
fi
## Work dir
cd $DIR
## Check if tnsnames is available
echo "Check tnsnames"
if [ -e /etc/tnsnames.ora ]; then
echo "Use local tnsnames version"
else
echo "get tnsnames from service-oracle-tnsnames.web.cern.ch...disabled for now"
if command -v curl >/dev/null 2>&1; then
curl https://service-oracle-tnsnames.web.cern.ch/service-oracle-tnsnames/tnsnames.ora -o ${DIR}/tnsnames.ora
else
echo "Error: curl is not installed. Cannot fetch tnsnames.ora."
fi
fi
## -Dlogging.config=/data/logs/logback.xml
echo "Setting JAVA_OPTS from file javaopts.properties"
joptfile=./javaopts.properties
echo "use opt : "
cat $joptfile
if [ -e $joptfile ]; then
export JAVA_OPTS=
while read line; do JAVA_OPTS="$JAVA_OPTS -D$line"; done < $joptfile
fi
## Set the directory with the JAR file
if [ -e ${DIR}/crest.jar ]; then
crest_dir=$DIR
fi
prj_dir=$crest_dir
if [ -z "$crest_dir" ]; then
prj_dir=$PWD/build/libs
fi
echo "Initialization..."
convert_certificate
print_application_properties
app_properties=${SPRING_TMPDIR}/application.properties
mkfifo -m 600 "${app_properties}"
print_application_properties >> ${app_properties} &
echo "$USER is starting server with JAVA_OPTS : $JAVA_OPTS from user directory $PWD, config from $SPRING_TMPDIR"
if [ x"$1" = x"" ]; then
echo "execute command ${prj_dir}/crest.jar"
exec java $JAVA_OPTS -jar ${prj_dir}/crest.jar --spring.config.location=optional:classpath:/,optional:classpath:/config/,file:${app_properties} 2>>/tmp/err.log
else
sh -c "$@"
fi
cleanup