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