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