summaryrefslogtreecommitdiffstats
path: root/packages/docker/src/main/docker/docker-files/scripts/start-app.sh
blob: 28a3f078ee43b5527b06c45696ac03aa20339490 (plain)
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
#!/bin/sh

if [ `id -u` = 0 ]
then
    # Install certificates found in the /app/ca-certificates volume, if any.

    needUpdate=FALSE

    for certificate in `ls -1 /app/ca-certificates`; do
        echo "Installing $certificate in /usr/local/share/ca-certificates"
        cp /app/ca-certificates/$certificate /usr/local/share/ca-certificates/$certificate
        needUpdate=TRUE
    done

    if [ $needUpdate = TRUE ]; then
        update-ca-certificates --fresh
    fi

    # Re-exec this script as the 'onap' user.
    this=`readlink -f $0`
    exec su so -c  "$this"
fi

touch /app/app.jar

if [ -z "$APP" ]; then
    echo "CONFIG ERROR: APP environment variable not set"
    exit 1
fi

if [ ! -z "$DB_HOST" -a -z "$DB_PORT" ]; then
    export DB_PORT=3306
fi

if [ -z "${CONFIG_PATH}" ]; then
    export CONFIG_PATH=/app/config/override.yaml
fi

if [ -z "${LOG_PATH}" ]; then
    export LOG_PATH="logs/${APP}"
fi

if [ "${SSL_DEBUG}" = "log" ]; then
    export SSL_DEBUG="-Djavax.net.debug=all"
else
    export SSL_DEBUG=
fi

# Set java keystore and truststore options, if specified in the environment.

jksargs=

if [ ! -z "${KEYSTORE}" ]; then
    jksargs="$jksargs -Dmso.load.ssl.client.keystore=true"
    jksargs="$jksargs -Djavax.net.ssl.keyStore=$KEYSTORE"
    jksargs="$jksargs -Djavax.net.ssl.keyStorePassword=${KEYSTORE_PASSWORD}"
fi

if [ ! -z "${TRUSTSTORE}" ]; then
    jksargs="$jksargs -Djavax.net.ssl.trustStore=${TRUSTSTORE}"
    jksargs="$jksargs -Djavax.net.ssl.trustStorePassword=${TRUSTSTORE_PASSWORD}"
fi

if [ -z "${ACTIVE_PROFILE}" ]; then
    export ACTIVE_PROFILE="basic"
fi

jvmargs="${JVM_ARGS} -Dspring.profiles.active=${ACTIVE_PROFILE} -Djava.security.egd=file:/dev/./urandom -Dlogs_dir=${LOG_PATH} -Dlogging.config=/app/logback-spring.xml $jksargs -Dspring.config.additional-location=$CONFIG_PATH ${SSL_DEBUG} ${DISABLE_SNI}"


read_properties(){
    while IFS="=" read -r key value; do
        case "${key}" in
          '#'*) ;;
             *)
               eKey=$(echo $key | tr '[:lower:]' '[:upper:]')
               export "$eKey"="$value"
        esac
    done <<-EOF
	$1
	EOF
}

if [ -n "${AAF_SSL_CERTS_ENABLED}" ]; then
read_properties "$(head -n 4 /app/certs/.passphrases)"
fi

echo "JVM Arguments: ${jvmargs}"

java ${jvmargs} -jar app.jar
rc=$?

echo "Application exiting with status code $rc"

if [ ! -z "${EXIT_DELAY}" -a "${EXIT_DELAY}" != 0 ]; then
    echo "Delaying $APP exit for $EXIT_DELAY seconds"
    sleep $EXIT_DELAY
fi

exit $rc