blob: b2a253a289015985a32c0919b35eba6684629b26 [file] [log] [blame]
ATT default cloud user17b1b972017-08-31 21:34:47 +00001#!/bin/bash
dglFromAtt39c8bab2018-05-09 21:26:55 -04002#
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#
ATT default cloud user17b1b972017-08-31 21:34:47 +000023
24umask 0022
25TZ=GMT0
26COMPONENT=dmaapbc
27APP_ROOT=/opt/app/$COMPONENT
28USER=root
29export TZ
30PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/java/jdk/jdk180/bin
31export PATH
32CLASSPATH=`echo $APP_ROOT/etc $APP_ROOT/lib/*.jar | tr ' ' ':'`
33export CLASSPATH
dglFromAtt7b7126f2018-10-16 18:45:10 +000034CONFIGMAP_ROOT=${CONFIGMAP_ROOT:-/opt/app/config/conf}
35CONFIGMAP_PROPS=${CONFIGMAP_PROPS:-/opt/app/config/dmaapbc.properties}
36CONTAINER_CONFIG=$CONFIGMAP_ROOT/buscontroller.env
ATT default cloud user17b1b972017-08-31 21:34:47 +000037MAIN=org.onap.dmaap.dbcapi.server.Main
38
39
dglFromAtt6d9409c2018-04-10 00:38:14 -040040
ATT default cloud user17b1b972017-08-31 21:34:47 +000041pids() {
dglFromAtt24e34482018-03-21 08:28:10 -040042 set -x
ATT default cloud user17b1b972017-08-31 21:34:47 +000043 ps -ef | grep java | grep $MAIN | sed -e 's/[^ ]* *//' -e 's/ .*//'
dglFromAtt24e34482018-03-21 08:28:10 -040044 set +x
ATT default cloud user17b1b972017-08-31 21:34:47 +000045}
46
47config() {
48 set -x
49 if [ ! -d $APP_ROOT ]
50 then
51 echo "Expected app root directory $APP_ROOT does not exist"
52 exit 1
53 fi
54 if [ ! -f $CONTAINER_CONFIG ]
55 then
56 echo "Expected env file $CONTAINER_CONFIG not found"
dglFromAtt7b7126f2018-10-16 18:45:10 +000057 find $CONTAINER_ROOT -type f
ATT default cloud user17b1b972017-08-31 21:34:47 +000058 exit 1
59 fi
60 cd $APP_ROOT
61 source $CONTAINER_CONFIG
dglFromAtt6d9409c2018-04-10 00:38:14 -040062
63 if [ "$DMAAPBC_WAIT_TO_EXIT" != "Y" ]
64 then
65 echo "Creating $APP_ROOT/ok_to_exit so no waiting..."
66 > $APP_ROOT/ok_to_exit
67 else
68 echo "Not creating $APP_ROOT/ok_to_exit"
69 fi
dglFromAtt038b4a42018-04-24 08:46:34 -040070
71 if [ ! -f $APP_ROOT/misc/cert-client-init.sh ]
72 then
73 echo "Did not find $APP_ROOT/misc/cert-client-init.sh to append to truststore"
74 exit 1
75 fi
76 $APP_ROOT/misc/cert-client-init.sh
77 . misc/havecert.tmpl > etc/havecert
78 chmod +x etc/havecert
dglFromAtt6350b1e2018-10-13 18:18:58 +000079
80 # These files might be better provided in kubernetes configmaps
dglFromAtt7b7126f2018-10-16 18:45:10 +000081 # so if they are there, use them
82 if [ -f $CONFIGMAP_PROPS ]
dglFromAtt6350b1e2018-10-13 18:18:58 +000083 then
dglFromAtt7b7126f2018-10-16 18:45:10 +000084 PROPS=$CONFIGMAP_PROPS
85 else
86 PROPS=etc/dmaapbc.properties
87 . misc/dmaapbc.properties.tmpl > $PROPS
dglFromAtt6350b1e2018-10-13 18:18:58 +000088 fi
89 if [ ! -f config/PolicyEngineApi.properties ]
90 then
91 . misc/PolicyEngineApi.properties.tmpl > config/PolicyEngineApi.properties
92 fi
ATT default cloud user17b1b972017-08-31 21:34:47 +000093 set +x
94}
95
96start() {
97 set -x
98 ID=`id -n -u`
99 GRP=`id -n -g`
100 if [ "$ID" != "$USER" ]
101 then
102 echo $COMPONENT must be started as user $USER not $ID
103 exit 1
104 fi
105 if [ "$GRP" != "$USER" ]
106 then
107 echo $COMPONENT must be started as group $USER not $GRP
108 exit 1
109 fi
110 cd $APP_ROOT
111
dglFromAtt038b4a42018-04-24 08:46:34 -0400112 if etc/havecert
113 then
ATT default cloud user17b1b972017-08-31 21:34:47 +0000114 echo >/dev/null
dglFromAtt038b4a42018-04-24 08:46:34 -0400115 else
116 echo No certificate file available. Cannot start
117 exit 0
118 fi
ATT default cloud user17b1b972017-08-31 21:34:47 +0000119 PIDS=`pids`
120 if [ "$PIDS" != "" ]
121 then
122 echo $COMPONENT already running
123 exit 0
124 fi
125 rm -f $APP_ROOT/etc/SHUTDOWN
126
127 # JVM flags
128#old line from Dockerfile...keep for reference only
dglFromAtt7b7126f2018-10-16 18:45:10 +0000129 FLAGS="-cp etc:lib/* -Dlog4j.configuration=etc/log4j.properties -Ddmaapbc.properties=$PROPS -Dlogback.configurationFile=etc/logback.xml -Dhttps.protocols=TLSv1.2 -Dhttps.cipherSuites=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"
dglFromAtt24e34482018-03-21 08:28:10 -0400130 #nohup java $FLAGS $MAIN </dev/null >/dev/null 2>&1 &
131 nohup java $FLAGS $MAIN </dev/null &
ATT default cloud user17b1b972017-08-31 21:34:47 +0000132 sleep 5
133 PIDS=`pids`
ATT default cloud user17b1b972017-08-31 21:34:47 +0000134 set +x
135}
136
137stop() {
138 ID=`id -n -u`
139 GRP=`id -n -g`
140 if [ "$ID" != "$USER" ]
141 then
142 echo $COMPONENT must be stopped as user $USER not $ID
143 exit 1
144 fi
145 if [ "$GRP" != "$USER" ]
146 then
147 echo $COMPONENT must be stopped as group $USER not $GRP
148 exit 1
149 fi
150 touch $APP_ROOT/etc/SHUTDOWN
151 PIDS=`pids`
152 if [ "$PIDS" != "" ]
153 then
154 sleep 5
155 kill -9 $PIDS
156 sleep 5
157 echo $COMPONENT stopped
158 else
159 echo $COMPONENT not running
160 fi
161}
162
163status() {
164 PIDS=`pids`
165 if [ "$PIDS" != "" ]
166 then
167 echo $COMPONENT running
168 else
169 echo $COMPONENT not running
170 fi
171}
172
dglFromAtt94688672018-08-30 18:09:54 +0000173init() {
174 if [ ! -d $CONFIGMAP_ROOT ]
175 then
176 echo $CONFIGMAP_ROOT does not exist
177 return
178 fi
179
dglFromAtt65bd8f12018-09-04 23:52:02 -0400180 #loop on get /dmaap until we get a good response to indicate other provisioning can continue
181 rc=999
dglFromAtta246d952018-09-24 16:04:21 -0400182 while [ $rc != "200" ]
dglFromAtt65bd8f12018-09-04 23:52:02 -0400183 do
184 sleep 10
Tomasz Golabek07fb4c02018-10-01 16:32:13 +0200185 rc=`curl -s -o /dev/null -I -w "%{http_code}" -X GET -H "Content-Type: application/json" http://dmaap-bc:8080/webapi/dmaap`
dglFromAtt65bd8f12018-09-04 23:52:02 -0400186 echo "get dmaap response=${rc}"
187 done
188
dglFromAtt94688672018-08-30 18:09:54 +0000189 cd $CONFIGMAP_ROOT
190 # order is important in this next list
191 for uri in dmaap dcaeLocations mr_clusters topics feeds
192 do
193 if [ -d ${uri} ]
194 then
195 for j in `ls ${uri}/*.json`
196 do
197 curl -v -X POST -H "Content-Type: application/json" -d @${j} http://dmaap-bc:8080/webapi/${uri}
198 done
199 fi
200 done
201}
202
ATT default cloud user17b1b972017-08-31 21:34:47 +0000203set -x
204case "$1" in
205'deploy')
206 config
207 start
dglFromAtt94688672018-08-30 18:09:54 +0000208 init
ATT default cloud user17b1b972017-08-31 21:34:47 +0000209 wait
210 ;;
211'start')
212 start
213 ;;
214'stop')
215 stop
216 ;;
217'restart')
218 stop
219 sleep 20
220 start
221 ;;
222'status')
223 status
224 ;;
225*)
226 echo "Usage: $0 { start | stop | restart }"
227 exit 1
228 ;;
229esac
dglFromAtt5d2ddd52018-04-27 11:11:38 -0400230 ls -l $APP_ROOT/logs/ONAP
dglFromAtt24e34482018-03-21 08:28:10 -0400231 echo "------------ tail -100 error.log ---------------"
dglFromAtt5d2ddd52018-04-27 11:11:38 -0400232 tail -100 $APP_ROOT/logs/ONAP/error.log
dglFromAtt24e34482018-03-21 08:28:10 -0400233 echo "------------ tail -100 server.log ---------------"
dglFromAtt5d2ddd52018-04-27 11:11:38 -0400234 tail -100 $APP_ROOT/logs/ONAP/server.log
dglFromAtt24e34482018-03-21 08:28:10 -0400235 echo "------------ tail -100 application.log ---------------"
dglFromAtt5d2ddd52018-04-27 11:11:38 -0400236 tail -100 $APP_ROOT/logs/ONAP/application.log
dglFromAtt6d9409c2018-04-10 00:38:14 -0400237
238 echo "Check $APP_ROOT/ok_to_exit"
239 while [ ! -f $APP_ROOT/ok_to_exit ]
240 do
241 echo "$APP_ROOT/ok_to_exit does not exist. Sticking around for debugging..."
242 sleep 10
243 done
ATT default cloud user17b1b972017-08-31 21:34:47 +0000244exit 0