DMAAP-BC - Update Release Note Date
[dmaap/buscontroller.git] / dmaap-bc / src / main / resources / 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 # Modifications copyright (C) 2021 Nordix Foundation.
8 # ===================================================================
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
12 #
13 #        http://www.apache.org/licenses/LICENSE-2.0
14 #
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
20 # ============LICENSE_END============================================
21 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 #
23
24 umask 0022
25 TZ=GMT0
26 COMPONENT=dmaapbc
27 APP_ROOT=/opt/app/$COMPONENT
28 USER=onap
29 GROUP=onap
30 export TZ
31 PATH=/opt/java/openjdk/bin:/usr/sbin:/usr/bin:/sbin:/bin
32
33 export PATH
34 CLASSPATH=`echo $APP_ROOT/etc $APP_ROOT/lib/*.jar | tr ' ' ':'`
35 export CLASSPATH
36 CONFIGMAP_ROOT=${CONFIGMAP_ROOT:-/opt/app/config}
37 CONFIGMAP_PROPS=${CONFIGMAP_PROPS:-$CONFIGMAP_ROOT/conf/dmaapbc.properties}
38 CONTAINER_CONFIG=$CONFIGMAP_ROOT/conf/buscontroller.env
39 MAIN=org.onap.dmaap.dbcapi.server.Main
40
41 authcheck() {
42         set -x
43         ID=`id -n -u`
44         GRP=`id -n -g`
45         if [ "$ID" != "$USER" ]
46         then
47                 echo $COMPONENT must be started as user $USER not $ID
48                 exit 1
49         fi
50         if [ "$GRP" != "$GROUP" ]
51         then
52                 echo $COMPONENT must be started as group $GROUP not $GRP
53                 exit 1
54         fi
55         set +x
56 }
57
58 pids() {
59         set -x
60         ps -ef | grep java | grep $MAIN | sed -e 's/[^ ]* *//' -e 's/ .*//'
61         set +x
62 }
63
64 config() {
65         echo "ENTER config"
66         set -x
67         if [ ! -d $APP_ROOT ]
68         then
69                 echo "Expected app root directory $APP_ROOT does not exist"
70                 exit 1
71         fi
72
73         cd $APP_ROOT
74         if [ !  -f $CONTAINER_CONFIG ]
75         then
76                 echo "WARNING: Expected env file $CONTAINER_CONFIG not found. Default behaviors in effect"
77                 find $CONTAINER_ROOT -type f
78         else
79           . $CONTAINER_CONFIG
80         fi
81
82         if [ "$DMAAPBC_WAIT_TO_EXIT" != "Y" ]
83         then
84                 echo "Creating $APP_ROOT/ok_to_exit so no waiting..."
85                 > $APP_ROOT/ok_to_exit
86         else
87                 echo "Not creating $APP_ROOT/ok_to_exit"
88         fi
89
90         # These files might be better provided in kubernetes configmaps
91         # so if they are there, use them
92         if [ -f $CONFIGMAP_PROPS ]
93         then
94                 PROPS=$CONFIGMAP_PROPS
95         else
96                 PROPS=etc/dmaapbc.properties
97                 . misc/dmaapbc.properties.tmpl > $PROPS
98         fi
99         if [ ! -f config/PolicyEngineApi.properties ]
100         then
101           . misc/PolicyEngineApi.properties.tmpl > config/PolicyEngineApi.properties
102         fi
103         set +x
104 }
105
106 start() {
107         echo "ENTER start"
108         set -x
109         authcheck
110         cd $APP_ROOT
111         pwd
112
113         PIDS=`pids`
114         if [ "$PIDS" != "" ]
115         then
116                 echo $COMPONENT already running
117                 exit 0
118         fi
119         rm -f $APP_ROOT/etc/SHUTDOWN
120
121   java -classpath $CLASSPATH  $MAIN
122   dmaapjar="$APP_ROOT/lib/dmaap-bc.jar"
123         # JVM flags
124         FLAGS="-cp etc:lib/* -DConfigFile=$PROPS  -Dlogback.configurationFile=etc/logback.xml -Dhttps.protocols=TLSv1.2 -Dhttps.cipherSuites=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"
125         nohup java $FLAGS -jar $dmaapjar </dev/null  &
126         sleep 5
127         PIDS=`pids`
128         set +x
129 }
130
131 stop() {
132         echo "ENTER stop"
133         authcheck
134         touch $APP_ROOT/etc/SHUTDOWN
135         PIDS=`pids`
136         if [ "$PIDS" != "" ]
137         then
138                 sleep 5
139                 kill -9 $PIDS
140                 sleep 5
141                 echo $COMPONENT stopped
142         else
143                 echo $COMPONENT not running
144         fi
145 }
146
147 status() {
148         echo "ENTER status"
149         PIDS=`pids`
150         if [ "$PIDS" != "" ]
151         then
152                 echo $COMPONENT running
153         else
154                 echo $COMPONENT not running
155         fi
156 }
157
158 set -x
159 case "$1" in
160 'deploy')
161         config
162         start
163         wait
164         ;;
165 'start')
166         start
167         ;;
168 'stop')
169         stop
170         ;;
171 'restart')
172         stop
173         sleep 20
174         start
175         ;;
176 'status')
177         status
178         ;;
179 *)
180         echo "Usage: $0 { start | stop | restart }"
181         exit 1
182         ;;
183 esac
184                 ls -l $APP_ROOT/logs/ONAP
185                 echo "------------ tail -100 error.log ---------------"
186                 tail -n 1000  $APP_ROOT/logs/ONAP/error.log
187                 echo "------------ tail -100 server.log ---------------"
188                 tail -n 1000  $APP_ROOT/logs/ONAP/server.log
189                 echo "------------ tail -100 application.log ---------------"
190                 tail -n 1000 $APP_ROOT/logs/ONAP/application.log
191
192                 echo "Check $APP_ROOT/ok_to_exit"
193                 while [ ! -f $APP_ROOT/ok_to_exit ]
194                 do
195                         echo "$APP_ROOT/ok_to_exit does not exist.  Sticking around for debugging..."
196                         sleep 10
197                 done
198 exit 0