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