Tighten up due to using new image
[dmaap/buscontroller.git] / dmaap-bc / misc / dmaapbc
1 #!/bin/bash
2 #
3 # ============LICENSE_START==========================================
4 # org.onap.dmaap
5 # ===================================================================
6 # Copyright © 2018 AT&T Intellectual Property. All rights reserved.
7 # ===================================================================
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 #        http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 # ============LICENSE_END============================================
20 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
21 #
22 #
23
24 umask 0022
25 TZ=GMT0
26 COMPONENT=dmaapbc
27 APP_ROOT=/opt/app/$COMPONENT
28 USER=dbc
29 GROUP=onap
30 export TZ
31 PATH=/usr/local/openjdk-11/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
32
33 export PATH
34 CLASSPATH=`echo $APP_ROOT/etc $APP_ROOT/lib/*.jar | tr ' ' ':'` 
35 export CLASSPATH
36 CONFIGMAP_ROOT=${CONFIGMAP_ROOT:-/opt/app/config}
37 CONFIGMAP_PROPS=${CONFIGMAP_PROPS:-$CONFIGMAP_ROOT/conf/dmaapbc.properties}
38 CONTAINER_CONFIG=$CONFIGMAP_ROOT/conf/buscontroller.env
39 MAIN=org.onap.dmaap.dbcapi.server.Main 
40
41 authcheck() {
42         set -x
43         ID=`id -n -u`
44         GRP=`id -n -g`
45         if [ "$ID" != "$USER" ]
46         then
47                 echo $COMPONENT must be started as user $USER not $ID
48                 exit 1
49         fi
50         if [ "$GRP" != "$GROUP" ]
51         then
52                 echo $COMPONENT must be started as group $GROUP not $GRP
53                 exit 1
54         fi
55         set +x
56 }
57
58 pids() {
59         set -x
60         ps -ef | grep java | grep $MAIN | sed -e 's/[^ ]* *//' -e 's/ .*//'
61         set +x
62 }
63
64 config() {
65         echo "ENTER config"
66         set -x
67         if [ ! -d $APP_ROOT ]
68         then
69                 echo "Expected app root directory $APP_ROOT does not exist"
70                 exit 1
71         fi
72
73         cd $APP_ROOT
74         if [ !  -f $CONTAINER_CONFIG ]
75         then
76                 echo "WARNING: Expected env file $CONTAINER_CONFIG not found. Default behaviors in effect"
77                 find $CONTAINER_ROOT -type f
78         else 
79             source $CONTAINER_CONFIG
80         fi
81
82         if [ "$DMAAPBC_WAIT_TO_EXIT" != "Y" ]
83         then
84                 echo "Creating $APP_ROOT/ok_to_exit so no waiting..."
85                 > $APP_ROOT/ok_to_exit
86         else
87                 echo "Not creating $APP_ROOT/ok_to_exit"
88         fi      
89         
90         . misc/havecert.tmpl > etc/havecert
91         chmod +x etc/havecert
92
93         # These files might be better provided in kubernetes configmaps
94         # so if they are there, use them
95         if [ -f $CONFIGMAP_PROPS ]
96         then
97                 PROPS=$CONFIGMAP_PROPS
98         else
99                 PROPS=etc/dmaapbc.properties
100                 . misc/dmaapbc.properties.tmpl > $PROPS
101         fi
102         if [ ! -f config/PolicyEngineApi.properties ]
103         then
104                 . misc/PolicyEngineApi.properties.tmpl > config/PolicyEngineApi.properties
105         fi
106         set +x
107 }
108
109 start() {
110         echo "ENTER start"
111         set -x
112         authcheck
113         cd $APP_ROOT
114         pwd
115
116         if etc/havecert
117         then
118                 echo >/dev/null
119         else
120                 echo No certificate file available.  Cannot start
121                 exit 0
122         fi
123         PIDS=`pids`
124         if [ "$PIDS" != "" ]
125         then
126                 echo $COMPONENT already running
127                 exit 0
128         fi
129         rm -f $APP_ROOT/etc/SHUTDOWN
130
131         # JVM flags
132 #old line from Dockerfile...keep for reference only
133         FLAGS="-cp etc:lib/* -Dlog4j.configuration=etc/log4j.properties -DConfigFile=$PROPS  -Dlogback.configurationFile=etc/logback.xml -Dhttps.protocols=TLSv1.2 -Dhttps.cipherSuites=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"
134         #nohup java $FLAGS $MAIN </dev/null >/dev/null 2>&1 &
135         nohup java $FLAGS $MAIN </dev/null  &
136         sleep 5
137         PIDS=`pids`
138         set +x
139 }
140
141 stop() {
142         echo "ENTER stop"
143         authcheck
144         touch $APP_ROOT/etc/SHUTDOWN
145         PIDS=`pids`
146         if [ "$PIDS" != "" ]
147         then
148                 sleep 5
149                 kill -9 $PIDS
150                 sleep 5
151                 echo $COMPONENT stopped
152         else
153                 echo $COMPONENT not running
154         fi
155 }
156
157 status() {
158         echo "ENTER status"
159         PIDS=`pids`
160         if [ "$PIDS" != "" ]
161         then
162                 echo $COMPONENT running
163         else
164                 echo $COMPONENT not running
165         fi
166 }
167
168 init() {
169         echo "ENTER init"
170         if [ ! -d $CONFIGMAP_ROOT ]
171         then
172                 echo $CONFIGMAP_ROOT does not exist
173                 return
174         fi
175
176         #loop on get /dmaap until we get a good response to indicate other provisioning can continue
177         rc=999
178         while [ $rc != "200" ]
179         do
180                 sleep 10
181                 rc=`curl -s -o /dev/null -I -w "%{http_code}" -X GET -H "Content-Type: application/json" http://dmaap-bc:8080/webapi/dmaap`
182                 echo "get dmaap response=${rc}"
183         done
184
185         cd $CONFIGMAP_ROOT
186         pwd
187         # order is important in this next list
188         for uri in dmaap dcaeLocations mr_clusters topics feeds
189         do
190                 if [ -d ${uri} ]
191                 then
192                         for j in `ls ${uri}/*.json`
193                         do
194                                 echo "POST $j to $uri"
195                                 rc=`curl -v -X POST -w "%{http_code}" -H "Content-Type: application/json" -d @${j} http://dmaap-bc:8080/webapi/${uri}`
196                                 echo "response=$rc"
197                         done
198                 fi
199         done
200 }
201
202 set -x
203 case "$1" in
204 'deploy')
205         config
206         start
207         #init
208         wait
209         ;;
210 'start')
211         start
212         ;;
213 'stop')
214         stop
215         ;;
216 'restart')
217         stop
218         sleep 20
219         start
220         ;;
221 'status')
222         status
223         ;;
224 *)
225         echo "Usage: $0 { start | stop | restart }"
226         exit 1
227         ;;
228 esac
229                 ls -l $APP_ROOT/logs/ONAP
230                 echo "------------ tail -100 error.log ---------------"
231                 tail -100  $APP_ROOT/logs/ONAP/error.log
232                 echo "------------ tail -100 server.log ---------------"
233                 tail -100  $APP_ROOT/logs/ONAP/server.log
234                 echo "------------ tail -100 application.log ---------------"
235                 tail -100 $APP_ROOT/logs/ONAP/application.log
236
237                 echo "Check $APP_ROOT/ok_to_exit"
238                 while [ ! -f $APP_ROOT/ok_to_exit ]
239                 do
240                         echo "$APP_ROOT/ok_to_exit does not exist.  Sticking around for debugging..."
241                         sleep 10
242                 done
243 exit 0