DMAAP-BC - Update Release Note Date
[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             . $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         echo Check for certificate
93         TZ=GMT0
94         cd /opt/app/dmaapbc;
95         KEYSTORE=${DMAAPBC_KSTOREFILE:-etc/keystore}
96         echo "KEYSTORE=$KEYSTORE"
97         d=`dirname $KEYSTORE`
98         ls -l $d
99         if [ -f ${KEYSTORE} ]
100         then
101                 echo "Goodness: Found ${KEYSTORE}"
102         else
103                 EMSG="`date '+%F %T,000'` WARN Certificate file $KEYSTORE is missing"
104                 echo $EMSG
105                 echo $EMSG >>${DMAAPBC_LOGS:-logs}/dmaapbc.log
106         fi
107
108
109         # These files might be better provided in kubernetes configmaps
110         # so if they are there, use them
111         if [ -f $CONFIGMAP_PROPS ]
112         then
113                 PROPS=$CONFIGMAP_PROPS
114         else
115                 PROPS=etc/dmaapbc.properties
116                 . misc/dmaapbc.properties.tmpl > $PROPS
117         fi
118         if [ ! -f config/PolicyEngineApi.properties ]
119         then
120                 . misc/PolicyEngineApi.properties.tmpl > config/PolicyEngineApi.properties
121         fi
122         set +x
123 }
124
125 start() {
126         echo "ENTER start"
127         set -x
128         authcheck
129         cd $APP_ROOT
130         pwd
131
132         if [ -f "$KEYSTORE" ]
133         then
134                 echo >/dev/null
135         else
136                 echo No certificate file available.  Cannot start
137                 exit 0
138         fi
139         PIDS=`pids`
140         if [ "$PIDS" != "" ]
141         then
142                 echo $COMPONENT already running
143                 exit 0
144         fi
145         rm -f $APP_ROOT/etc/SHUTDOWN
146
147         # JVM flags
148 #old line from Dockerfile...keep for reference only
149         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"
150         #nohup java $FLAGS $MAIN </dev/null >/dev/null 2>&1 &
151         nohup java $FLAGS $MAIN </dev/null  &
152         sleep 5
153         PIDS=`pids`
154         set +x
155 }
156
157 stop() {
158         echo "ENTER stop"
159         authcheck
160         touch $APP_ROOT/etc/SHUTDOWN
161         PIDS=`pids`
162         if [ "$PIDS" != "" ]
163         then
164                 sleep 5
165                 kill -9 $PIDS
166                 sleep 5
167                 echo $COMPONENT stopped
168         else
169                 echo $COMPONENT not running
170         fi
171 }
172
173 status() {
174         echo "ENTER status"
175         PIDS=`pids`
176         if [ "$PIDS" != "" ]
177         then
178                 echo $COMPONENT running
179         else
180                 echo $COMPONENT not running
181         fi
182 }
183
184 init() {
185         echo "ENTER init"
186         if [ ! -d $CONFIGMAP_ROOT ]
187         then
188                 echo $CONFIGMAP_ROOT does not exist
189                 return
190         fi
191
192         #loop on get /dmaap until we get a good response to indicate other provisioning can continue
193         rc=999
194         while [ $rc != "200" ]
195         do
196                 sleep 10
197                 rc=`curl -s -o /dev/null -I -w "%{http_code}" -X GET -H "Content-Type: application/json" http://dmaap-bc:8080/webapi/dmaap`
198                 echo "get dmaap response=${rc}"
199         done
200
201         cd $CONFIGMAP_ROOT
202         pwd
203         # order is important in this next list
204         for uri in dmaap dcaeLocations mr_clusters topics feeds
205         do
206                 if [ -d ${uri} ]
207                 then
208                         for j in `ls ${uri}/*.json`
209                         do
210                                 echo "POST $j to $uri"
211                                 rc=`curl -v -X POST -w "%{http_code}" -H "Content-Type: application/json" -d @${j} http://dmaap-bc:8080/webapi/${uri}`
212                                 echo "response=$rc"
213                         done
214                 fi
215         done
216 }
217
218 set -x
219 case "$1" in
220 'deploy')
221         config
222         start
223         #init
224         wait
225         ;;
226 'start')
227         start
228         ;;
229 'stop')
230         stop
231         ;;
232 'restart')
233         stop
234         sleep 20
235         start
236         ;;
237 'status')
238         status
239         ;;
240 *)
241         echo "Usage: $0 { start | stop | restart }"
242         exit 1
243         ;;
244 esac
245                 ls -l $APP_ROOT/logs/ONAP
246                 echo "------------ tail -100 error.log ---------------"
247                 tail -100  $APP_ROOT/logs/ONAP/error.log
248                 echo "------------ tail -100 server.log ---------------"
249                 tail -100  $APP_ROOT/logs/ONAP/server.log
250                 echo "------------ tail -100 application.log ---------------"
251                 tail -100 $APP_ROOT/logs/ONAP/application.log
252
253                 echo "Check $APP_ROOT/ok_to_exit"
254                 while [ ! -f $APP_ROOT/ok_to_exit ]
255                 do
256                         echo "$APP_ROOT/ok_to_exit does not exist.  Sticking around for debugging..."
257                         sleep 10
258                 done
259 exit 0