bugfix - nginx fails to start up
[holmes/rule-management.git] / rulemgt-standalone / src / main / assembly / bin / run.sh
1 #!/usr/bin/env bash
2
3 #
4 # Copyright 2017-2022 ZTE Corporation.
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 #     http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18
19 DIRNAME=`dirname $0`
20 RUNHOME=`cd $DIRNAME/; pwd`
21 echo @RUNHOME@ $RUNHOME
22
23 echo @JAVA_HOME@ $JAVA_HOME
24 JAVA="$JAVA_HOME/bin/java"
25 echo @JAVA@ $JAVA
26 main_path=$RUNHOME/..
27 cd $main_path
28 JAVA_OPTS="-Xms256m -Xmx1g"
29 port=9201
30 #JAVA_OPTS="$JAVA_OPTS -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=*:$port,server=y,suspend=n"
31 echo @JAVA_OPTS@ $JAVA_OPTS
32
33 class_path="$main_path/lib/*"
34 echo @class_path@ $class_path
35
36 if [ -z ${JDBC_USERNAME} ]; then
37     export JDBC_USERNAME=holmes
38     echo "No user name is specified for the database. Use the default value \"$JDBC_USERNAME\"."
39 fi
40
41 if [ -z ${JDBC_PASSWORD} ]; then
42     export JDBC_PASSWORD=holmespwd
43     echo "No password is specified for the database. Use the default value \"$JDBC_PASSWORD\"."
44 fi
45
46 if [ -z ${DB_NAME} ]; then
47     export DB_NAME=holmes
48     echo "No database is name is specified. Use the default value \"$DB_NAME\"."
49 fi
50
51 export DB_PORT=5432
52 if [ ! -z ${URL_JDBC} ] && [ `expr index $URL_JDBC :` != 0 ]; then
53     export DB_PORT="${URL_JDBC##*:}"
54 fi
55 echo DB_PORT=$DB_PORT
56
57 # if deployed using helm, use the helm-generated configuration file.
58 if [ -d /opt/hrmconfig ]; then
59     cp /opt/hrmconfig/application.yaml "$main_path/conf/application.yaml"
60 else
61     sed -i "s|username:.*|username: $JDBC_USERNAME|" "$main_path/conf/application.yaml"
62     sed -i "s|password:.*|password: $JDBC_PASSWORD|" "$main_path/conf/application.yaml"
63     sed -i "s|url:.*|url: jdbc:postgresql://$URL_JDBC:$DB_PORT/$DB_NAME|" "$main_path/conf/application.yaml"
64 fi
65
66 export SERVICE_IP=`hostname -i | awk '{print $1}'`
67 echo SERVICE_IP=${SERVICE_IP}
68
69 if [ ! -z ${HOST_IP} ]; then
70     export HOSTNAME=${HOST_IP}:9101
71 else
72     export HOSTNAME=${SERVICE_IP}:9101
73 fi
74
75 if [ -z ${ENABLE_ENCRYPT} ]; then
76     export ENABLE_ENCRYPT=true
77 fi
78 echo ENABLE_ENCRYPT=${ENABLE_ENCRYPT}
79
80 KEY_PATH="$main_path/conf/holmes.keystore"
81 KEY_PASSWORD="holmes"
82
83 if [ -f "/opt/app/osaaf/local/org.onap.holmes-rule-mgmt.p12" ]; then
84     KEY_PATH="/opt/app/osaaf/local/org.onap.holmes-rule-mgmt.p12"
85     KEY_PASSWORD=`head -n1 "/opt/app/osaaf/local/mycreds.prop" | cut -d= -f2`
86 fi
87
88 echo "KEY_PATH=$KEY_PATH"
89 echo "KEY_PASS=$KEY_PASSWORD"
90
91 #HTTPS Configurations
92 sed -i "s|key-store:.*|key-store: $KEY_PATH|" "$main_path/conf/application.yaml"
93 sed -i "s|key-store-password:.*|key-store-password: $KEY_PASSWORD|" "$main_path/conf/application.yaml"
94
95 if [ "${ENABLE_ENCRYPT}"x = "true"x ]; then
96     sed -i "s|#\?ssl:|ssl:|" "$main_path/conf/application.yaml"
97     sed -i "s|#\?key-store|key-store|" "$main_path/conf/application.yaml"
98     sed -i "s|#\?key-store-password|key-store-password|" "$main_path/conf/application.yaml"
99     sed -i "s|#\?key-store-type|key-store-type|" "$main_path/conf/application.yaml"
100 else
101     sed -i 's|#\?ssl:|#ssl:|' "$main_path/conf/application.yaml"
102     sed -i "s|#\?key-store|#key-store|" "$main_path/conf/application.yaml"
103     sed -i "s|#\?key-store-password|#key-store-password|" "$main_path/conf/application.yaml"
104     sed -i "s|#\?key-store-type|#key-store-type|" "$main_path/conf/application.yaml"
105 fi
106
107 ${RUNHOME}/initDB.sh "$JDBC_USERNAME" "$JDBC_PASSWORD" "$DB_NAME" "$DB_PORT" "${URL_JDBC%:*}"
108
109
110 if [ -f "/opt/app/osaaf/local/org.onap.holmes-rule-mgmt.crt" ]; then
111     sed -i "s|/etc/ssl/certs/holmes-frontend-selfsigned.crt|/opt/app/osaaf/local/org.onap.holmes-rule-mgmt.crt|" "/etc/nginx/conf.d/nginx-https.conf"
112     sed -i "s|/etc/ssl/private/holmes-frontend.key|/opt/app/osaaf/local/org.onap.holmes-rule-mgmt.key|" "/etc/nginx/conf.d/nginx-https.conf"
113 fi
114
115 if [ "$MSB_IAG_SERVICE_PORT"x = "443"x ]; then
116     sed -i "s|http://msb-iag.onap|https://$MSB_IAG_SERVICE_HOST:$MSB_IAG_SERVICE_PORT|g" /etc/nginx/conf.d/nginx-http*.conf
117 else
118     sed -i "s|http://msb-iag.onap|http://$MSB_IAG_SERVICE_HOST:$MSB_IAG_SERVICE_PORT|g" /etc/nginx/conf.d/nginx-http*.conf
119 fi
120
121 if [ "${ENABLE_ENCRYPT}"x = "true"x ]; then
122     nginx -c /etc/nginx/conf.d/nginx-https.conf
123 else
124     nginx -c /etc/nginx/conf.d/nginx-http.conf
125 fi
126 echo nginx started.
127
128 cat "$main_path/conf/application.yaml"
129
130 JAR=`ls -lt $main_path/lib | grep -e "holmes-rulemgt-.*jar$" | awk '{print $9}'`
131 "$JAVA" $JAVA_OPTS -jar "$main_path/lib/$JAR" -classpath "$class_path" --spring.config.location="$main_path/conf/application.yaml"