Merge "Initial delivery of helm charts to deploy mod2 components. Resolved all the...
[dcaegen2/platform.git] / oti / event-handler / run.sh
1 #!/bin/bash
2 # ================================================================================
3 # Copyright (c) 2019-2020 AT&T Intellectual Property. All rights reserved.
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 # ============LICENSE_END=========================================================
17 #
18 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
19
20 mkdir -p logs
21 LOG_FILE=logs/oti_handler.log
22 exec &>> >(tee -a ${LOG_FILE})
23 echo "---------------------------------------------"
24 STARTED=$(date +%Y-%m-%d_%T.%N)
25 echo "${STARTED}: running ${BASH_SOURCE[0]}"
26 export APP_VER=$(python setup.py --version)
27 echo "APP_VER=${APP_VER}"
28 echo "HOSTNAME=${HOSTNAME}"
29 echo "CONSUL_URL=${CONSUL_URL}"
30 (pwd; uname -a; id; echo "ls -lanR:"; ls -lanR; echo "/etc/hosts:"; cat /etc/hosts; openssl version -a)
31 echo "---------------------------------------------"
32
33 export REQUESTS_CA_BUNDLE="/etc/ssl/certs/ca-certificates.crt"
34
35 # create the database tables
36 export PGPASSWORD=$postgres_password
37 psql -h $postgres_ip -U $postgres_user $postgres_db_name -f /tmp/create_schema.sql
38
39 python -m otihandler 2>&1 &
40 PID=$!
41
42 function finish {
43   echo "killing oti_handler ${PID}" $(date +%Y_%m%d-%H:%M:%S.%N)
44   kill -9 ${PID}
45   echo "killed oti_handler ${PID}" $(date +%Y_%m%d-%H:%M:%S.%N)
46 }
47 trap finish SIGHUP SIGINT SIGTERM
48
49 echo "running oti_handler as" ${PID} "log" ${LOG_FILE}
50 #(free -h; df -h; ps afxvw; ss -aepi)
51
52 wait ${PID}
53 exec &>> >(tee -a ${LOG_FILE})
54 echo "---------------------------------------------"
55 rm ${LOG_FILE}.2[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]_[0-9][0-9][0-9][0-9][0-9][0-9]
56 mv ${LOG_FILE} ${LOG_FILE}.$(date +%Y-%m-%d_%H%M%S)