ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 1 | #!/bin/bash |
dglFromAtt | 39c8bab | 2018-05-09 21:26:55 -0400 | [diff] [blame] | 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 | # |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 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 |
dglFromAtt | dcdbc9c | 2018-10-18 17:53:25 +0000 | [diff] [blame] | 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 |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 37 | MAIN=org.onap.dmaap.dbcapi.server.Main |
| 38 | |
| 39 | |
dglFromAtt | 6d9409c | 2018-04-10 00:38:14 -0400 | [diff] [blame] | 40 | |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 41 | pids() { |
dglFromAtt | 24e3448 | 2018-03-21 08:28:10 -0400 | [diff] [blame] | 42 | set -x |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 43 | ps -ef | grep java | grep $MAIN | sed -e 's/[^ ]* *//' -e 's/ .*//' |
dglFromAtt | 24e3448 | 2018-03-21 08:28:10 -0400 | [diff] [blame] | 44 | set +x |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | config() { |
dglFromAtt | dcdbc9c | 2018-10-18 17:53:25 +0000 | [diff] [blame] | 48 | echo "ENTER config" |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 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 | if [ ! -f $CONTAINER_CONFIG ] |
| 56 | then |
dglFromAtt | 22434bf | 2018-10-16 20:36:59 +0000 | [diff] [blame] | 57 | echo "WARNING: Expected env file $CONTAINER_CONFIG not found. Default behaviors in effect" |
dglFromAtt | 7b7126f | 2018-10-16 18:45:10 +0000 | [diff] [blame] | 58 | find $CONTAINER_ROOT -type f |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 59 | fi |
| 60 | cd $APP_ROOT |
| 61 | source $CONTAINER_CONFIG |
dglFromAtt | 6d9409c | 2018-04-10 00:38:14 -0400 | [diff] [blame] | 62 | |
| 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 |
dglFromAtt | 038b4a4 | 2018-04-24 08:46:34 -0400 | [diff] [blame] | 70 | |
| 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 |
dglFromAtt | 6350b1e | 2018-10-13 18:18:58 +0000 | [diff] [blame] | 79 | |
| 80 | # These files might be better provided in kubernetes configmaps |
dglFromAtt | 7b7126f | 2018-10-16 18:45:10 +0000 | [diff] [blame] | 81 | # so if they are there, use them |
| 82 | if [ -f $CONFIGMAP_PROPS ] |
dglFromAtt | 6350b1e | 2018-10-13 18:18:58 +0000 | [diff] [blame] | 83 | then |
dglFromAtt | 7b7126f | 2018-10-16 18:45:10 +0000 | [diff] [blame] | 84 | PROPS=$CONFIGMAP_PROPS |
| 85 | else |
| 86 | PROPS=etc/dmaapbc.properties |
| 87 | . misc/dmaapbc.properties.tmpl > $PROPS |
dglFromAtt | 6350b1e | 2018-10-13 18:18:58 +0000 | [diff] [blame] | 88 | fi |
| 89 | if [ ! -f config/PolicyEngineApi.properties ] |
| 90 | then |
| 91 | . misc/PolicyEngineApi.properties.tmpl > config/PolicyEngineApi.properties |
| 92 | fi |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 93 | set +x |
| 94 | } |
| 95 | |
| 96 | start() { |
dglFromAtt | dcdbc9c | 2018-10-18 17:53:25 +0000 | [diff] [blame] | 97 | echo "ENTER start" |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 98 | set -x |
| 99 | ID=`id -n -u` |
| 100 | GRP=`id -n -g` |
| 101 | if [ "$ID" != "$USER" ] |
| 102 | then |
| 103 | echo $COMPONENT must be started as user $USER not $ID |
| 104 | exit 1 |
| 105 | fi |
| 106 | if [ "$GRP" != "$USER" ] |
| 107 | then |
| 108 | echo $COMPONENT must be started as group $USER not $GRP |
| 109 | exit 1 |
| 110 | fi |
| 111 | cd $APP_ROOT |
dglFromAtt | dcdbc9c | 2018-10-18 17:53:25 +0000 | [diff] [blame] | 112 | pwd |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 113 | |
dglFromAtt | 038b4a4 | 2018-04-24 08:46:34 -0400 | [diff] [blame] | 114 | if etc/havecert |
| 115 | then |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 116 | echo >/dev/null |
dglFromAtt | 038b4a4 | 2018-04-24 08:46:34 -0400 | [diff] [blame] | 117 | else |
| 118 | echo No certificate file available. Cannot start |
| 119 | exit 0 |
| 120 | fi |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 121 | PIDS=`pids` |
| 122 | if [ "$PIDS" != "" ] |
| 123 | then |
| 124 | echo $COMPONENT already running |
| 125 | exit 0 |
| 126 | fi |
| 127 | rm -f $APP_ROOT/etc/SHUTDOWN |
| 128 | |
| 129 | # JVM flags |
| 130 | #old line from Dockerfile...keep for reference only |
dglFromAtt | d696ab8 | 2018-10-16 21:12:00 +0000 | [diff] [blame] | 131 | 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" |
dglFromAtt | 24e3448 | 2018-03-21 08:28:10 -0400 | [diff] [blame] | 132 | #nohup java $FLAGS $MAIN </dev/null >/dev/null 2>&1 & |
| 133 | nohup java $FLAGS $MAIN </dev/null & |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 134 | sleep 5 |
| 135 | PIDS=`pids` |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 136 | set +x |
| 137 | } |
| 138 | |
| 139 | stop() { |
dglFromAtt | dcdbc9c | 2018-10-18 17:53:25 +0000 | [diff] [blame] | 140 | echo "ENTER stop" |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 141 | ID=`id -n -u` |
| 142 | GRP=`id -n -g` |
| 143 | if [ "$ID" != "$USER" ] |
| 144 | then |
| 145 | echo $COMPONENT must be stopped as user $USER not $ID |
| 146 | exit 1 |
| 147 | fi |
| 148 | if [ "$GRP" != "$USER" ] |
| 149 | then |
| 150 | echo $COMPONENT must be stopped as group $USER not $GRP |
| 151 | exit 1 |
| 152 | fi |
| 153 | touch $APP_ROOT/etc/SHUTDOWN |
| 154 | PIDS=`pids` |
| 155 | if [ "$PIDS" != "" ] |
| 156 | then |
| 157 | sleep 5 |
| 158 | kill -9 $PIDS |
| 159 | sleep 5 |
| 160 | echo $COMPONENT stopped |
| 161 | else |
| 162 | echo $COMPONENT not running |
| 163 | fi |
| 164 | } |
| 165 | |
| 166 | status() { |
dglFromAtt | dcdbc9c | 2018-10-18 17:53:25 +0000 | [diff] [blame] | 167 | echo "ENTER status" |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 168 | PIDS=`pids` |
| 169 | if [ "$PIDS" != "" ] |
| 170 | then |
| 171 | echo $COMPONENT running |
| 172 | else |
| 173 | echo $COMPONENT not running |
| 174 | fi |
| 175 | } |
| 176 | |
dglFromAtt | 9468867 | 2018-08-30 18:09:54 +0000 | [diff] [blame] | 177 | init() { |
dglFromAtt | dcdbc9c | 2018-10-18 17:53:25 +0000 | [diff] [blame] | 178 | echo "ENTER init" |
dglFromAtt | 9468867 | 2018-08-30 18:09:54 +0000 | [diff] [blame] | 179 | if [ ! -d $CONFIGMAP_ROOT ] |
| 180 | then |
| 181 | echo $CONFIGMAP_ROOT does not exist |
| 182 | return |
| 183 | fi |
| 184 | |
dglFromAtt | 65bd8f1 | 2018-09-04 23:52:02 -0400 | [diff] [blame] | 185 | #loop on get /dmaap until we get a good response to indicate other provisioning can continue |
| 186 | rc=999 |
dglFromAtt | a246d95 | 2018-09-24 16:04:21 -0400 | [diff] [blame] | 187 | while [ $rc != "200" ] |
dglFromAtt | 65bd8f1 | 2018-09-04 23:52:02 -0400 | [diff] [blame] | 188 | do |
| 189 | sleep 10 |
Tomasz Golabek | 07fb4c0 | 2018-10-01 16:32:13 +0200 | [diff] [blame] | 190 | rc=`curl -s -o /dev/null -I -w "%{http_code}" -X GET -H "Content-Type: application/json" http://dmaap-bc:8080/webapi/dmaap` |
dglFromAtt | 65bd8f1 | 2018-09-04 23:52:02 -0400 | [diff] [blame] | 191 | echo "get dmaap response=${rc}" |
| 192 | done |
| 193 | |
dglFromAtt | 9468867 | 2018-08-30 18:09:54 +0000 | [diff] [blame] | 194 | cd $CONFIGMAP_ROOT |
dglFromAtt | dcdbc9c | 2018-10-18 17:53:25 +0000 | [diff] [blame] | 195 | pwd |
dglFromAtt | 9468867 | 2018-08-30 18:09:54 +0000 | [diff] [blame] | 196 | # order is important in this next list |
| 197 | for uri in dmaap dcaeLocations mr_clusters topics feeds |
| 198 | do |
| 199 | if [ -d ${uri} ] |
| 200 | then |
| 201 | for j in `ls ${uri}/*.json` |
| 202 | do |
dglFromAtt | dcdbc9c | 2018-10-18 17:53:25 +0000 | [diff] [blame] | 203 | echo "POST $j to $uri" |
| 204 | rc=`curl -v -X POST -w "%{http_code}" -H "Content-Type: application/json" -d @${j} http://dmaap-bc:8080/webapi/${uri}` |
| 205 | echo "response=$rc" |
dglFromAtt | 9468867 | 2018-08-30 18:09:54 +0000 | [diff] [blame] | 206 | done |
| 207 | fi |
| 208 | done |
| 209 | } |
| 210 | |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 211 | set -x |
| 212 | case "$1" in |
| 213 | 'deploy') |
| 214 | config |
| 215 | start |
dglFromAtt | d0a915d | 2019-02-18 18:20:55 +0000 | [diff] [blame] | 216 | #init |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 217 | wait |
| 218 | ;; |
| 219 | 'start') |
| 220 | start |
| 221 | ;; |
| 222 | 'stop') |
| 223 | stop |
| 224 | ;; |
| 225 | 'restart') |
| 226 | stop |
| 227 | sleep 20 |
| 228 | start |
| 229 | ;; |
| 230 | 'status') |
| 231 | status |
| 232 | ;; |
| 233 | *) |
| 234 | echo "Usage: $0 { start | stop | restart }" |
| 235 | exit 1 |
| 236 | ;; |
| 237 | esac |
dglFromAtt | 5d2ddd5 | 2018-04-27 11:11:38 -0400 | [diff] [blame] | 238 | ls -l $APP_ROOT/logs/ONAP |
dglFromAtt | 24e3448 | 2018-03-21 08:28:10 -0400 | [diff] [blame] | 239 | echo "------------ tail -100 error.log ---------------" |
dglFromAtt | 5d2ddd5 | 2018-04-27 11:11:38 -0400 | [diff] [blame] | 240 | tail -100 $APP_ROOT/logs/ONAP/error.log |
dglFromAtt | 24e3448 | 2018-03-21 08:28:10 -0400 | [diff] [blame] | 241 | echo "------------ tail -100 server.log ---------------" |
dglFromAtt | 5d2ddd5 | 2018-04-27 11:11:38 -0400 | [diff] [blame] | 242 | tail -100 $APP_ROOT/logs/ONAP/server.log |
dglFromAtt | 24e3448 | 2018-03-21 08:28:10 -0400 | [diff] [blame] | 243 | echo "------------ tail -100 application.log ---------------" |
dglFromAtt | 5d2ddd5 | 2018-04-27 11:11:38 -0400 | [diff] [blame] | 244 | tail -100 $APP_ROOT/logs/ONAP/application.log |
dglFromAtt | 6d9409c | 2018-04-10 00:38:14 -0400 | [diff] [blame] | 245 | |
| 246 | echo "Check $APP_ROOT/ok_to_exit" |
| 247 | while [ ! -f $APP_ROOT/ok_to_exit ] |
| 248 | do |
| 249 | echo "$APP_ROOT/ok_to_exit does not exist. Sticking around for debugging..." |
| 250 | sleep 10 |
| 251 | done |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 252 | exit 0 |