Merge "sonar fix: Rsrc handling nokia/CommonUtil"
[vfc/nfvo/driver/vnfm/svnfm.git] / nokiav2 / deployment / src / main / resources / docker-entrypoint.sh
1 #!/bin/bash
2 #
3 # Copyright 2017, Nokia 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
19 CONFIG_LOCATION=/service/application.properties
20
21 function shutdown(){
22   echo "Recieved sutdown signal"
23   if [ ! -e /proc/$PID ] ; then
24     echo "The process already exited $PID"
25     exit
26   fi
27   echo "Sending shutdown signal to $PID"
28   kill -15 $PID
29   for i in `seq 0 20`; do
30     if [ ! -e /proc/$PID ] ; then
31       echo "The driver exited normally $PID"
32       exit 0
33     fi
34     sleep 10
35   done
36   echo "Terminating the driver forcefully $PID"
37   kill -9 $PID
38 }
39
40 function switchLine(){
41   PATTERN=$1
42   REPLACEMENT=$2
43   if [ ! -z $REPLACEMENT ]; then
44     sed -i "s/${PATTERN}.*/${PATTERN}/g" $CONFIG_LOCATION
45     sed -i "s|${PATTERN}|${PATTERN}=${REPLACEMENT}|g" $CONFIG_LOCATION
46   fi
47 }
48
49 function configure(){
50   if [ ! -z "$CONFIGURE" ] ; then
51      switchLine driverMsbExternalIp $EXTERNAL_IP
52      switchLine driverVnfmExternalIp $EXTERNAL_IP
53      switchLine messageBusIp $MSB_IP
54      switchLine cbamCatalogUrl $CBAM_CATALOG_URL
55      switchLine cbamLcnUrl $CBAM_LCN_URL
56      switchLine cbamKeyCloakBaseUrl $CBAM_KEYCLOAK_URL
57      switchLine cbamLcnUrl $CBAM_LCN_URL
58      switchLine cbamUsername $CBAM_USERNAME
59      switchLine cbamPassword $CBAM_PASSWORD
60      switchLine vnfmId $VNFM_ID
61      switchLine ipMap $IP_MAP
62   fi 
63 }
64
65
66 #during shutdown signal the ervice to stop
67 trap shutdown SIGINT SIGTERM 
68
69 #configure if required
70 configure
71
72 #start the service
73 cd /service
74
75 while true ; do
76   echo "Starting server"
77   java -jar driver.war --spring.config.location=file:/service/application.properties &>> /service/service.log &
78   export PID=$!
79   echo "Server process started in background with id $PID"
80   while test -e /proc/$PID; do
81     sleep 10
82   done
83   echo "Server quit (unexpected)"
84 done
85