Simple initialization calls at deploy
[dmaap/buscontroller.git] / 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=/opt/app/config
35 CONTAINER_CONFIG=$CONFIGMAP_ROOT/conf
36 MAIN=org.onap.dmaap.dbcapi.server.Main 
37
38
39
40 pids() {
41         set -x
42         ps -ef | grep java | grep $MAIN | sed -e 's/[^ ]* *//' -e 's/ .*//'
43         set +x
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
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      
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
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
98         if etc/havecert
99         then
100                 echo >/dev/null
101         else
102                 echo No certificate file available.  Cannot start
103                 exit 0
104         fi
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
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"
116         #nohup java $FLAGS $MAIN </dev/null >/dev/null 2>&1 &
117         nohup java $FLAGS $MAIN </dev/null  &
118         sleep 5
119         PIDS=`pids`
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
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
180 set -x
181 case "$1" in
182 'deploy')
183         config
184         start
185         init
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
207                 ls -l $APP_ROOT/logs/ONAP
208                 echo "------------ tail -100 error.log ---------------"
209                 tail -100  $APP_ROOT/logs/ONAP/error.log
210                 echo "------------ tail -100 server.log ---------------"
211                 tail -100  $APP_ROOT/logs/ONAP/server.log
212                 echo "------------ tail -100 application.log ---------------"
213                 tail -100 $APP_ROOT/logs/ONAP/application.log
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
221 exit 0