Use the cert generated by AAF
[holmes/rule-management.git] / rulemgt-standalone / src / main / assembly / bin / run.sh
1 #!/bin/sh
2
3 #
4 # Copyright 2017-2020 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 # if deployed using helm, use the helm-generated configuration file.
52 if [ -d /opt/hrmconfig ]; then
53     cp /opt/hrmconfig/rulemgt.yml "$main_path/conf/rulemgt.yml"
54 else
55     sed -i "s|user:.*|user: $JDBC_USERNAME|" "$main_path/conf/rulemgt.yml"
56     sed -i "s|password:.*|password: $JDBC_PASSWORD|" "$main_path/conf/rulemgt.yml"
57     sed -i "s|url:.*|url: jdbc:postgresql://$URL_JDBC/$DB_NAME|" "$main_path/conf/rulemgt.yml"
58 fi
59
60 export SERVICE_IP=`hostname -i`
61 echo SERVICE_IP=${SERVICE_IP}
62
63 if [ ! -z ${TESTING} ] && [ ${TESTING} = 1 ]; then
64     if [ ! -z ${HOST_IP} ]; then
65         export HOSTNAME=${HOST_IP}:9101
66     else
67         export HOSTNAME=${SERVICE_IP}:9101
68     fi
69 fi
70
71 export DB_PORT=5432
72 if [ ! -z ${URL_JDBC} ] && [ `expr index $URL_JDBC :` != 0 ]; then
73     export DB_PORT="${URL_JDBC##*:}"
74 fi
75 echo DB_PORT=$DB_PORT
76
77 if [ -z ${ENABLE_ENCRYPT} ]; then
78     export ENABLE_ENCRYPT=true
79 fi
80 echo ENABLE_ENCRYPT=${ENABLE_ENCRYPT}
81
82 KEY_PATH="$main_path/conf/holmes.keystore"
83 KEY_PASSWORD="holmes"
84
85 if [ -f "/opt/app/osaaf/local/org.onap.holmes-rule-mgmt.p12" ]; then
86     KEY_PATH="/opt/app/osaaf/local/org.onap.holmes-rule-mgmt.p12"
87     KEY_PASSWORD=`head -n1 "/opt/app/osaaf/local/mycreds.prop" | cut -d= -f2`
88 fi
89
90 echo "KEY_PATH=$KEY_PATH"
91 echo "KEY_PASS=$KEY_PASSWORD"
92
93 #HTTPS Configurations
94 sed -i "s|keyStorePath:.*|keyStorePath: $KEY_PATH|" "$main_path/conf/rulemgt.yml"
95 sed -i "s|keyStorePassword:.*|keyStorePassword: $KEY_PASSWORD|" "$main_path/conf/rulemgt.yml"
96
97 if [ ${ENABLE_ENCRYPT} = true ]; then
98     sed -i "s|type:\s*https\?$|type: https|" "$main_path/conf/rulemgt.yml"
99     sed -i "s|#\?keyStorePath|keyStorePath|" "$main_path/conf/rulemgt.yml"
100     sed -i "s|#\?keyStorePassword|keyStorePassword|" "$main_path/conf/rulemgt.yml"
101     sed -i "s|#\?validateCerts|validateCerts|" "$main_path/conf/rulemgt.yml"
102     sed -i "s|#\?validatePeers|validatePeers|" "$main_path/conf/rulemgt.yml"
103 else
104     sed -i 's|type:\s*https\?$|type: http|' "$main_path/conf/rulemgt.yml"
105     sed -i "s|#\?keyStorePath|#keyStorePath|" "$main_path/conf/rulemgt.yml"
106     sed -i "s|#\?keyStorePassword|#keyStorePassword|" "$main_path/conf/rulemgt.yml"
107     sed -i "s|#\?validateCerts|#validateCerts|" "$main_path/conf/rulemgt.yml"
108     sed -i "s|#\?validatePeers|#validatePeers|" "$main_path/conf/rulemgt.yml"
109 fi
110
111
112 ${RUNHOME}/initDB.sh "$JDBC_USERNAME" "$JDBC_PASSWORD" "$DB_NAME" "$DB_PORT" "${URL_JDBC%:*}"
113
114
115 #Register the fronten to MSB
116 #body='{"serviceName":"holmes","version":"v1","url":"/iui/holmes","nodes":[{"ip":"host_ip","port":"9104","lb_server_params":"","checkType":"","checkUrl":"","checkInterval":"","checkTimeOut":"","ttl":"","ha_role":""}],"protocol":"UI","visualRange":"0|1","lb_policy":"","publish_port":"","namespace":"","network_plane_type":"","host":"","path":"","labels":[],"metadata":[]}'
117 #msg_body=${body/host_ip/"${HOSTNAME%:*}"}
118 #curl -X POST -H "Content-Type: application/json" -d ${msg_body} http://${MSB_ADDR}/api/msdiscover/v1/services?is_manual=true
119 #echo Registered UI to MSB.
120
121
122 if [ ${ENABLE_ENCRYPT} = true ]; then
123     nginx -c /etc/nginx/conf.d/nginx-https.conf
124 else
125     nginx -c /etc/nginx/conf.d/nginx-http.conf
126 fi
127 echo nginx started.
128
129 "$JAVA" $JAVA_OPTS -classpath "$class_path" org.onap.holmes.rulemgt.RuleActiveApp server "$main_path/conf/rulemgt.yml"