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 | 9468867 | 2018-08-30 18:09:54 +0000 | [diff] [blame^] | 34 | CONFIGMAP_ROOT=/opt/app/config |
| 35 | CONTAINER_CONFIG=$CONFIGMAP_ROOT/conf |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 36 | MAIN=org.onap.dmaap.dbcapi.server.Main |
| 37 | |
| 38 | |
dglFromAtt | 6d9409c | 2018-04-10 00:38:14 -0400 | [diff] [blame] | 39 | |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 40 | pids() { |
dglFromAtt | 24e3448 | 2018-03-21 08:28:10 -0400 | [diff] [blame] | 41 | set -x |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 42 | ps -ef | grep java | grep $MAIN | sed -e 's/[^ ]* *//' -e 's/ .*//' |
dglFromAtt | 24e3448 | 2018-03-21 08:28:10 -0400 | [diff] [blame] | 43 | set +x |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | config() { |
| 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 |
dglFromAtt | 6d9409c | 2018-04-10 00:38:14 -0400 | [diff] [blame] | 60 | |
| 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 |
dglFromAtt | 038b4a4 | 2018-04-24 08:46:34 -0400 | [diff] [blame] | 68 | |
| 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 |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 77 | . misc/dmaapbc.properties.tmpl > etc/dmaapbc.properties |
| 78 | . misc/PolicyEngineApi.properties.tmpl > config/PolicyEngineApi.properties |
| 79 | set +x |
| 80 | } |
| 81 | |
| 82 | start() { |
| 83 | set -x |
| 84 | ID=`id -n -u` |
| 85 | GRP=`id -n -g` |
| 86 | if [ "$ID" != "$USER" ] |
| 87 | then |
| 88 | echo $COMPONENT must be started as user $USER not $ID |
| 89 | exit 1 |
| 90 | fi |
| 91 | if [ "$GRP" != "$USER" ] |
| 92 | then |
| 93 | echo $COMPONENT must be started as group $USER not $GRP |
| 94 | exit 1 |
| 95 | fi |
| 96 | cd $APP_ROOT |
| 97 | |
dglFromAtt | 038b4a4 | 2018-04-24 08:46:34 -0400 | [diff] [blame] | 98 | if etc/havecert |
| 99 | then |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 100 | echo >/dev/null |
dglFromAtt | 038b4a4 | 2018-04-24 08:46:34 -0400 | [diff] [blame] | 101 | else |
| 102 | echo No certificate file available. Cannot start |
| 103 | exit 0 |
| 104 | fi |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 105 | PIDS=`pids` |
| 106 | if [ "$PIDS" != "" ] |
| 107 | then |
| 108 | echo $COMPONENT already running |
| 109 | exit 0 |
| 110 | fi |
| 111 | rm -f $APP_ROOT/etc/SHUTDOWN |
| 112 | |
| 113 | # JVM flags |
| 114 | #old line from Dockerfile...keep for reference only |
dglFromAtt | aac024c | 2018-04-10 05:33:06 -0400 | [diff] [blame] | 115 | 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" |
dglFromAtt | 24e3448 | 2018-03-21 08:28:10 -0400 | [diff] [blame] | 116 | #nohup java $FLAGS $MAIN </dev/null >/dev/null 2>&1 & |
| 117 | nohup java $FLAGS $MAIN </dev/null & |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 118 | sleep 5 |
| 119 | PIDS=`pids` |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 120 | set +x |
| 121 | } |
| 122 | |
| 123 | stop() { |
| 124 | ID=`id -n -u` |
| 125 | GRP=`id -n -g` |
| 126 | if [ "$ID" != "$USER" ] |
| 127 | then |
| 128 | echo $COMPONENT must be stopped as user $USER not $ID |
| 129 | exit 1 |
| 130 | fi |
| 131 | if [ "$GRP" != "$USER" ] |
| 132 | then |
| 133 | echo $COMPONENT must be stopped as group $USER not $GRP |
| 134 | exit 1 |
| 135 | fi |
| 136 | touch $APP_ROOT/etc/SHUTDOWN |
| 137 | PIDS=`pids` |
| 138 | if [ "$PIDS" != "" ] |
| 139 | then |
| 140 | sleep 5 |
| 141 | kill -9 $PIDS |
| 142 | sleep 5 |
| 143 | echo $COMPONENT stopped |
| 144 | else |
| 145 | echo $COMPONENT not running |
| 146 | fi |
| 147 | } |
| 148 | |
| 149 | status() { |
| 150 | PIDS=`pids` |
| 151 | if [ "$PIDS" != "" ] |
| 152 | then |
| 153 | echo $COMPONENT running |
| 154 | else |
| 155 | echo $COMPONENT not running |
| 156 | fi |
| 157 | } |
| 158 | |
dglFromAtt | 9468867 | 2018-08-30 18:09:54 +0000 | [diff] [blame^] | 159 | init() { |
| 160 | if [ ! -d $CONFIGMAP_ROOT ] |
| 161 | then |
| 162 | echo $CONFIGMAP_ROOT does not exist |
| 163 | return |
| 164 | fi |
| 165 | |
| 166 | cd $CONFIGMAP_ROOT |
| 167 | # order is important in this next list |
| 168 | for uri in dmaap dcaeLocations mr_clusters topics feeds |
| 169 | do |
| 170 | if [ -d ${uri} ] |
| 171 | then |
| 172 | for j in `ls ${uri}/*.json` |
| 173 | do |
| 174 | curl -v -X POST -H "Content-Type: application/json" -d @${j} http://dmaap-bc:8080/webapi/${uri} |
| 175 | done |
| 176 | fi |
| 177 | done |
| 178 | } |
| 179 | |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 180 | set -x |
| 181 | case "$1" in |
| 182 | 'deploy') |
| 183 | config |
| 184 | start |
dglFromAtt | 9468867 | 2018-08-30 18:09:54 +0000 | [diff] [blame^] | 185 | init |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 186 | wait |
| 187 | ;; |
| 188 | 'start') |
| 189 | start |
| 190 | ;; |
| 191 | 'stop') |
| 192 | stop |
| 193 | ;; |
| 194 | 'restart') |
| 195 | stop |
| 196 | sleep 20 |
| 197 | start |
| 198 | ;; |
| 199 | 'status') |
| 200 | status |
| 201 | ;; |
| 202 | *) |
| 203 | echo "Usage: $0 { start | stop | restart }" |
| 204 | exit 1 |
| 205 | ;; |
| 206 | esac |
dglFromAtt | 5d2ddd5 | 2018-04-27 11:11:38 -0400 | [diff] [blame] | 207 | ls -l $APP_ROOT/logs/ONAP |
dglFromAtt | 24e3448 | 2018-03-21 08:28:10 -0400 | [diff] [blame] | 208 | echo "------------ tail -100 error.log ---------------" |
dglFromAtt | 5d2ddd5 | 2018-04-27 11:11:38 -0400 | [diff] [blame] | 209 | tail -100 $APP_ROOT/logs/ONAP/error.log |
dglFromAtt | 24e3448 | 2018-03-21 08:28:10 -0400 | [diff] [blame] | 210 | echo "------------ tail -100 server.log ---------------" |
dglFromAtt | 5d2ddd5 | 2018-04-27 11:11:38 -0400 | [diff] [blame] | 211 | tail -100 $APP_ROOT/logs/ONAP/server.log |
dglFromAtt | 24e3448 | 2018-03-21 08:28:10 -0400 | [diff] [blame] | 212 | echo "------------ tail -100 application.log ---------------" |
dglFromAtt | 5d2ddd5 | 2018-04-27 11:11:38 -0400 | [diff] [blame] | 213 | tail -100 $APP_ROOT/logs/ONAP/application.log |
dglFromAtt | 6d9409c | 2018-04-10 00:38:14 -0400 | [diff] [blame] | 214 | |
| 215 | echo "Check $APP_ROOT/ok_to_exit" |
| 216 | while [ ! -f $APP_ROOT/ok_to_exit ] |
| 217 | do |
| 218 | echo "$APP_ROOT/ok_to_exit does not exist. Sticking around for debugging..." |
| 219 | sleep 10 |
| 220 | done |
ATT default cloud user | 17b1b97 | 2017-08-31 21:34:47 +0000 | [diff] [blame] | 221 | exit 0 |