blob: 0dff4d6c3ac49869939b1ae31c7391fe3b7155ba [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
dglFromAtt94688672018-08-30 18:09:54 +000034CONFIGMAP_ROOT=/opt/app/config
35CONTAINER_CONFIG=$CONFIGMAP_ROOT/conf
ATT default cloud user17b1b972017-08-31 21:34:47 +000036MAIN=org.onap.dmaap.dbcapi.server.Main
37
38
dglFromAtt6d9409c2018-04-10 00:38:14 -040039
ATT default cloud user17b1b972017-08-31 21:34:47 +000040pids() {
dglFromAtt24e34482018-03-21 08:28:10 -040041 set -x
ATT default cloud user17b1b972017-08-31 21:34:47 +000042 ps -ef | grep java | grep $MAIN | sed -e 's/[^ ]* *//' -e 's/ .*//'
dglFromAtt24e34482018-03-21 08:28:10 -040043 set +x
ATT default cloud user17b1b972017-08-31 21:34:47 +000044}
45
46config() {
47 set -x
48 if [ ! -d $APP_ROOT ]
49 then
50 echo "Expected app root directory $APP_ROOT does not exist"
51 exit 1
52 fi
53 if [ ! -f $CONTAINER_CONFIG ]
54 then
55 echo "Expected env file $CONTAINER_CONFIG not found"
56 exit 1
57 fi
58 cd $APP_ROOT
59 source $CONTAINER_CONFIG
dglFromAtt6d9409c2018-04-10 00:38:14 -040060
61 if [ "$DMAAPBC_WAIT_TO_EXIT" != "Y" ]
62 then
63 echo "Creating $APP_ROOT/ok_to_exit so no waiting..."
64 > $APP_ROOT/ok_to_exit
65 else
66 echo "Not creating $APP_ROOT/ok_to_exit"
67 fi
dglFromAtt038b4a42018-04-24 08:46:34 -040068
69 if [ ! -f $APP_ROOT/misc/cert-client-init.sh ]
70 then
71 echo "Did not find $APP_ROOT/misc/cert-client-init.sh to append to truststore"
72 exit 1
73 fi
74 $APP_ROOT/misc/cert-client-init.sh
75 . misc/havecert.tmpl > etc/havecert
76 chmod +x etc/havecert
dglFromAtt6350b1e2018-10-13 18:18:58 +000077
78 # These files might be better provided in kubernetes configmaps
79 # so if they are already there, don't overwrite.
80 if [ ! -f etc/dmaapbc.properties ]
81 then
82 . misc/dmaapbc.properties.tmpl > etc/dmaapbc.properties
83 fi
84 if [ ! -f config/PolicyEngineApi.properties ]
85 then
86 . misc/PolicyEngineApi.properties.tmpl > config/PolicyEngineApi.properties
87 fi
ATT default cloud user17b1b972017-08-31 21:34:47 +000088 set +x
89}
90
91start() {
92 set -x
93 ID=`id -n -u`
94 GRP=`id -n -g`
95 if [ "$ID" != "$USER" ]
96 then
97 echo $COMPONENT must be started as user $USER not $ID
98 exit 1
99 fi
100 if [ "$GRP" != "$USER" ]
101 then
102 echo $COMPONENT must be started as group $USER not $GRP
103 exit 1
104 fi
105 cd $APP_ROOT
106
dglFromAtt038b4a42018-04-24 08:46:34 -0400107 if etc/havecert
108 then
ATT default cloud user17b1b972017-08-31 21:34:47 +0000109 echo >/dev/null
dglFromAtt038b4a42018-04-24 08:46:34 -0400110 else
111 echo No certificate file available. Cannot start
112 exit 0
113 fi
ATT default cloud user17b1b972017-08-31 21:34:47 +0000114 PIDS=`pids`
115 if [ "$PIDS" != "" ]
116 then
117 echo $COMPONENT already running
118 exit 0
119 fi
120 rm -f $APP_ROOT/etc/SHUTDOWN
121
122 # JVM flags
123#old line from Dockerfile...keep for reference only
dglFromAttaac024c2018-04-10 05:33:06 -0400124 FLAGS="-cp etc:lib/* -Dlog4j.configuration=etc/log4j.properties -Ddmaapbc.properties=etc/dmaapbc.properties -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 -0400125 #nohup java $FLAGS $MAIN </dev/null >/dev/null 2>&1 &
126 nohup java $FLAGS $MAIN </dev/null &
ATT default cloud user17b1b972017-08-31 21:34:47 +0000127 sleep 5
128 PIDS=`pids`
ATT default cloud user17b1b972017-08-31 21:34:47 +0000129 set +x
130}
131
132stop() {
133 ID=`id -n -u`
134 GRP=`id -n -g`
135 if [ "$ID" != "$USER" ]
136 then
137 echo $COMPONENT must be stopped as user $USER not $ID
138 exit 1
139 fi
140 if [ "$GRP" != "$USER" ]
141 then
142 echo $COMPONENT must be stopped as group $USER not $GRP
143 exit 1
144 fi
145 touch $APP_ROOT/etc/SHUTDOWN
146 PIDS=`pids`
147 if [ "$PIDS" != "" ]
148 then
149 sleep 5
150 kill -9 $PIDS
151 sleep 5
152 echo $COMPONENT stopped
153 else
154 echo $COMPONENT not running
155 fi
156}
157
158status() {
159 PIDS=`pids`
160 if [ "$PIDS" != "" ]
161 then
162 echo $COMPONENT running
163 else
164 echo $COMPONENT not running
165 fi
166}
167
dglFromAtt94688672018-08-30 18:09:54 +0000168init() {
169 if [ ! -d $CONFIGMAP_ROOT ]
170 then
171 echo $CONFIGMAP_ROOT does not exist
172 return
173 fi
174
dglFromAtt65bd8f12018-09-04 23:52:02 -0400175 #loop on get /dmaap until we get a good response to indicate other provisioning can continue
176 rc=999
dglFromAtta246d952018-09-24 16:04:21 -0400177 while [ $rc != "200" ]
dglFromAtt65bd8f12018-09-04 23:52:02 -0400178 do
179 sleep 10
Tomasz Golabek07fb4c02018-10-01 16:32:13 +0200180 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 -0400181 echo "get dmaap response=${rc}"
182 done
183
dglFromAtt94688672018-08-30 18:09:54 +0000184 cd $CONFIGMAP_ROOT
185 # order is important in this next list
186 for uri in dmaap dcaeLocations mr_clusters topics feeds
187 do
188 if [ -d ${uri} ]
189 then
190 for j in `ls ${uri}/*.json`
191 do
192 curl -v -X POST -H "Content-Type: application/json" -d @${j} http://dmaap-bc:8080/webapi/${uri}
193 done
194 fi
195 done
196}
197
ATT default cloud user17b1b972017-08-31 21:34:47 +0000198set -x
199case "$1" in
200'deploy')
201 config
202 start
dglFromAtt94688672018-08-30 18:09:54 +0000203 init
ATT default cloud user17b1b972017-08-31 21:34:47 +0000204 wait
205 ;;
206'start')
207 start
208 ;;
209'stop')
210 stop
211 ;;
212'restart')
213 stop
214 sleep 20
215 start
216 ;;
217'status')
218 status
219 ;;
220*)
221 echo "Usage: $0 { start | stop | restart }"
222 exit 1
223 ;;
224esac
dglFromAtt5d2ddd52018-04-27 11:11:38 -0400225 ls -l $APP_ROOT/logs/ONAP
dglFromAtt24e34482018-03-21 08:28:10 -0400226 echo "------------ tail -100 error.log ---------------"
dglFromAtt5d2ddd52018-04-27 11:11:38 -0400227 tail -100 $APP_ROOT/logs/ONAP/error.log
dglFromAtt24e34482018-03-21 08:28:10 -0400228 echo "------------ tail -100 server.log ---------------"
dglFromAtt5d2ddd52018-04-27 11:11:38 -0400229 tail -100 $APP_ROOT/logs/ONAP/server.log
dglFromAtt24e34482018-03-21 08:28:10 -0400230 echo "------------ tail -100 application.log ---------------"
dglFromAtt5d2ddd52018-04-27 11:11:38 -0400231 tail -100 $APP_ROOT/logs/ONAP/application.log
dglFromAtt6d9409c2018-04-10 00:38:14 -0400232
233 echo "Check $APP_ROOT/ok_to_exit"
234 while [ ! -f $APP_ROOT/ok_to_exit ]
235 do
236 echo "$APP_ROOT/ok_to_exit does not exist. Sticking around for debugging..."
237 sleep 10
238 done
ATT default cloud user17b1b972017-08-31 21:34:47 +0000239exit 0