ab30d73057f344ed72b564ace3dd7a62b094f0f5
[dmaap/buscontroller.git] / 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=root
29 export TZ
30 PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/java/jdk/jdk180/bin
31 export PATH
32 CLASSPATH=`echo $APP_ROOT/etc $APP_ROOT/lib/*.jar | tr ' ' ':'` 
33 export CLASSPATH
34 CONFIGMAP_ROOT=${CONFIGMAP_ROOT:-/opt/app/config}
35 CONFIGMAP_PROPS=${CONFIGMAP_PROPS:-$CONFIGMAP_ROOT/conf/dmaapbc.properties}
36 CONTAINER_CONFIG=$CONFIGMAP_ROOT/conf/buscontroller.env
37 MAIN=org.onap.dmaap.dbcapi.server.Main 
38
39
40
41 pids() {
42         echo "ENTER pids"
43         set -x
44         ps -ef | grep java | grep $MAIN | sed -e 's/[^ ]* *//' -e 's/ .*//'
45         set +x
46 }
47
48 config() {
49         echo "ENTER config"
50         set -x
51         if [ ! -d $APP_ROOT ]
52         then
53                 echo "Expected app root directory $APP_ROOT does not exist"
54                 exit 1
55         fi
56         if [ !  -f $CONTAINER_CONFIG ]
57         then
58                 echo "WARNING: Expected env file $CONTAINER_CONFIG not found. Default behaviors in effect"
59                 find $CONTAINER_ROOT -type f
60         fi
61         cd $APP_ROOT
62         source $CONTAINER_CONFIG
63
64         if [ "$DMAAPBC_WAIT_TO_EXIT" != "Y" ]
65         then
66                 echo "Creating $APP_ROOT/ok_to_exit so no waiting..."
67                 > $APP_ROOT/ok_to_exit
68         else
69                 echo "Not creating $APP_ROOT/ok_to_exit"
70         fi      
71         
72         if [ ! -f $APP_ROOT/misc/cert-client-init.sh ]
73         then
74                 echo "Did not find $APP_ROOT/misc/cert-client-init.sh to append to truststore"
75                 exit 1
76         fi
77         $APP_ROOT/misc/cert-client-init.sh
78         . misc/havecert.tmpl > etc/havecert
79         chmod +x etc/havecert
80
81         # These files might be better provided in kubernetes configmaps
82         # so if they are there, use them
83         if [ -f $CONFIGMAP_PROPS ]
84         then
85                 PROPS=$CONFIGMAP_PROPS
86         else
87                 PROPS=etc/dmaapbc.properties
88                 . misc/dmaapbc.properties.tmpl > $PROPS
89         fi
90         if [ ! -f config/PolicyEngineApi.properties ]
91         then
92                 . misc/PolicyEngineApi.properties.tmpl > config/PolicyEngineApi.properties
93         fi
94         set +x
95 }
96
97 start() {
98         echo "ENTER start"
99         set -x
100         ID=`id -n -u`
101         GRP=`id -n -g`
102         if [ "$ID" != "$USER" ]
103         then
104                 echo $COMPONENT must be started as user $USER not $ID
105                 exit 1
106         fi
107         if [ "$GRP" != "$USER" ]
108         then
109                 echo $COMPONENT must be started as group $USER not $GRP
110                 exit 1
111         fi
112         cd $APP_ROOT
113         pwd
114
115         if etc/havecert
116         then
117                 echo >/dev/null
118         else
119                 echo No certificate file available.  Cannot start
120                 exit 0
121         fi
122         PIDS=`pids`
123         if [ "$PIDS" != "" ]
124         then
125                 echo $COMPONENT already running
126                 exit 0
127         fi
128         rm -f $APP_ROOT/etc/SHUTDOWN
129
130         # JVM flags
131 #old line from Dockerfile...keep for reference only
132         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"
133         #nohup java $FLAGS $MAIN </dev/null >/dev/null 2>&1 &
134         nohup java $FLAGS $MAIN </dev/null  &
135         sleep 5
136         PIDS=`pids`
137         set +x
138 }
139
140 stop() {
141         echo "ENTER stop"
142         ID=`id -n -u`
143         GRP=`id -n -g`
144         if [ "$ID" != "$USER" ]
145         then
146                 echo $COMPONENT must be stopped as user $USER not $ID
147                 exit 1
148         fi
149         if [ "$GRP" != "$USER" ]
150         then
151                 echo $COMPONENT must be stopped as group $USER not $GRP
152                 exit 1
153         fi
154         touch $APP_ROOT/etc/SHUTDOWN
155         PIDS=`pids`
156         if [ "$PIDS" != "" ]
157         then
158                 sleep 5
159                 kill -9 $PIDS
160                 sleep 5
161                 echo $COMPONENT stopped
162         else
163                 echo $COMPONENT not running
164         fi
165 }
166
167 status() {
168         echo "ENTER status"
169         PIDS=`pids`
170         if [ "$PIDS" != "" ]
171         then
172                 echo $COMPONENT running
173         else
174                 echo $COMPONENT not running
175         fi
176 }
177
178 init() {
179         echo "ENTER init"
180         if [ ! -d $CONFIGMAP_ROOT ]
181         then
182                 echo $CONFIGMAP_ROOT does not exist
183                 return
184         fi
185
186         #loop on get /dmaap until we get a good response to indicate other provisioning can continue
187         rc=999
188         while [ $rc != "200" ]
189         do
190                 sleep 10
191                 rc=`curl -s -o /dev/null -I -w "%{http_code}" -X GET -H "Content-Type: application/json" http://dmaap-bc:8080/webapi/dmaap`
192                 echo "get dmaap response=${rc}"
193         done
194
195         cd $CONFIGMAP_ROOT
196         pwd
197         # order is important in this next list
198         for uri in dmaap dcaeLocations mr_clusters topics feeds
199         do
200                 if [ -d ${uri} ]
201                 then
202                         for j in `ls ${uri}/*.json`
203                         do
204                                 echo "POST $j to $uri"
205                                 rc=`curl -v -X POST -w "%{http_code}" -H "Content-Type: application/json" -d @${j} http://dmaap-bc:8080/webapi/${uri}`
206                                 echo "response=$rc"
207                         done
208                 fi
209         done
210 }
211
212 set -x
213 case "$1" in
214 'deploy')
215         config
216         start
217         init
218         wait
219         ;;
220 'start')
221         start
222         ;;
223 'stop')
224         stop
225         ;;
226 'restart')
227         stop
228         sleep 20
229         start
230         ;;
231 'status')
232         status
233         ;;
234 *)
235         echo "Usage: $0 { start | stop | restart }"
236         exit 1
237         ;;
238 esac
239                 ls -l $APP_ROOT/logs/ONAP
240                 echo "------------ tail -100 error.log ---------------"
241                 tail -100  $APP_ROOT/logs/ONAP/error.log
242                 echo "------------ tail -100 server.log ---------------"
243                 tail -100  $APP_ROOT/logs/ONAP/server.log
244                 echo "------------ tail -100 application.log ---------------"
245                 tail -100 $APP_ROOT/logs/ONAP/application.log
246
247                 echo "Check $APP_ROOT/ok_to_exit"
248                 while [ ! -f $APP_ROOT/ok_to_exit ]
249                 do
250                         echo "$APP_ROOT/ok_to_exit does not exist.  Sticking around for debugging..."
251                         sleep 10
252                 done
253 exit 0