[AAI-2176] Run container process as non-root
[aai/data-router.git] / src / main / bin / start.sh
1 #!/bin/sh
2
3 MICRO_HOME="/opt/app/data-router"
4
5
6
7 if [ -z "$CONFIG_HOME" ]; then
8         echo "CONFIG_HOME must be set in order to start up process"
9         exit 1
10 fi
11
12 if [ -z "$KEY_STORE_PASSWORD" ]; then
13         echo "KEY_STORE_PASSWORD must be set in order to start up process"
14         exit 1
15 fi
16
17 # Changes related to:AAI-2176
18 # Change aai datarouter  container processes to run as non-root on the host
19 USER_ID=${LOCAL_USER_ID:-9001}
20 GROUP_ID=${LOCAL_GROUP_ID:-9001}
21 DR_LOGS=/var/log/onap/AAI-DR
22
23 if [ $(cat /etc/passwd | grep aaiadmin | wc -l) -eq 0 ]; then
24
25         groupadd aaiadmin -g ${GROUP_ID} || {
26                 echo "Unable to create the group id for ${GROUP_ID}";
27                 exit 1;
28         }
29         useradd --shell=/bin/bash -u ${USER_ID} -g ${GROUP_ID} -o -c "" -m aaiadmin || {
30                 echo "Unable to create the user id for ${USER_ID}";
31                 exit 1;
32         }
33 fi;
34 chown -R aaiadmin:aaiadmin ${MICRO_HOME}
35 chown -R aaiadmin:aaiadmin ${DR_LOGS}
36 find ${MICRO_HOME}  -name "*.sh" -exec chmod +x {} +
37
38 gosu aaiadmin ln -s /logs $MICRO_HOME/logs
39 JAVA_CMD="exec gosu aaiadmin java";
40 ###
41 PROPS="-DAJSC_HOME=${MICRO_HOME}"
42 PROPS="$PROPS -Dlogging.config=${MICRO_HOME}/bundleconfig/etc/logback.xml"
43 PROPS="$PROPS -DCONFIG_HOME=$CONFIG_HOME"
44 PROPS="$PROPS -DKEY_STORE_PASSWORD=$KEY_STORE_PASSWORD"
45
46 if [ ! -z "$TRUST_STORE_PASSWORD" ]; then
47    PROPS="$PROPS -DTRUST_STORE_PASSWORD=${TRUST_STORE_PASSWORD}"
48 fi
49
50 if [ ! -z "$TRUST_STORE_LOCATION" ]; then
51    PROPS="$PROPS -DTRUST_STORE_LOCATION=${TRUST_STORE_LOCATION}"
52 fi
53
54
55 JVM_MAX_HEAP=${MAX_HEAP:-1024}
56
57 cd ${MICRO_HOME}
58 jar uf0 ${MICRO_HOME}/data-router.jar BOOT-INF/lib/* > /dev/null 2>&1
59
60 ${JAVA_CMD}  -Xmx${JVM_MAX_HEAP}m $PROPS -jar ${MICRO_HOME}/data-router.jar