Files missing License text
[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 CONTAINER_CONFIG=/opt/app/config/conf
35 MAIN=org.onap.dmaap.dbcapi.server.Main 
36
37
38
39 pids() {
40         set -x
41         ps -ef | grep java | grep $MAIN | sed -e 's/[^ ]* *//' -e 's/ .*//'
42         set +x
43 }
44
45 config() {
46         set -x
47         if [ ! -d $APP_ROOT ]
48         then
49                 echo "Expected app root directory $APP_ROOT does not exist"
50                 exit 1
51         fi
52         if [ !  -f $CONTAINER_CONFIG ]
53         then
54                 echo "Expected env file $CONTAINER_CONFIG not found"
55                 exit 1
56         fi
57         cd $APP_ROOT
58         source $CONTAINER_CONFIG
59
60         if [ "$DMAAPBC_WAIT_TO_EXIT" != "Y" ]
61         then
62                 echo "Creating $APP_ROOT/ok_to_exit so no waiting..."
63                 > $APP_ROOT/ok_to_exit
64         else
65                 echo "Not creating $APP_ROOT/ok_to_exit"
66         fi      
67         
68         if [ ! -f $APP_ROOT/misc/cert-client-init.sh ]
69         then
70                 echo "Did not find $APP_ROOT/misc/cert-client-init.sh to append to truststore"
71                 exit 1
72         fi
73         $APP_ROOT/misc/cert-client-init.sh
74         . misc/havecert.tmpl > etc/havecert
75         chmod +x etc/havecert
76         . misc/dmaapbc.properties.tmpl > etc/dmaapbc.properties
77     . misc/PolicyEngineApi.properties.tmpl > config/PolicyEngineApi.properties
78         set +x
79 }
80
81 start() {
82         set -x
83         ID=`id -n -u`
84         GRP=`id -n -g`
85         if [ "$ID" != "$USER" ]
86         then
87                 echo $COMPONENT must be started as user $USER not $ID
88                 exit 1
89         fi
90         if [ "$GRP" != "$USER" ]
91         then
92                 echo $COMPONENT must be started as group $USER not $GRP
93                 exit 1
94         fi
95         cd $APP_ROOT
96
97         if etc/havecert
98         then
99                 echo >/dev/null
100         else
101                 echo No certificate file available.  Cannot start
102                 exit 0
103         fi
104         PIDS=`pids`
105         if [ "$PIDS" != "" ]
106         then
107                 echo $COMPONENT already running
108                 exit 0
109         fi
110         rm -f $APP_ROOT/etc/SHUTDOWN
111
112         # JVM flags
113 #old line from Dockerfile...keep for reference only
114         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"
115         #nohup java $FLAGS $MAIN </dev/null >/dev/null 2>&1 &
116         nohup java $FLAGS $MAIN </dev/null  &
117         sleep 5
118         PIDS=`pids`
119         set +x
120 }
121
122 stop() {
123         ID=`id -n -u`
124         GRP=`id -n -g`
125         if [ "$ID" != "$USER" ]
126         then
127                 echo $COMPONENT must be stopped as user $USER not $ID
128                 exit 1
129         fi
130         if [ "$GRP" != "$USER" ]
131         then
132                 echo $COMPONENT must be stopped as group $USER not $GRP
133                 exit 1
134         fi
135         touch $APP_ROOT/etc/SHUTDOWN
136         PIDS=`pids`
137         if [ "$PIDS" != "" ]
138         then
139                 sleep 5
140                 kill -9 $PIDS
141                 sleep 5
142                 echo $COMPONENT stopped
143         else
144                 echo $COMPONENT not running
145         fi
146 }
147
148 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 -100  $APP_ROOT/logs/ONAP/error.log
187                 echo "------------ tail -100 server.log ---------------"
188                 tail -100  $APP_ROOT/logs/ONAP/server.log
189                 echo "------------ tail -100 application.log ---------------"
190                 tail -100 $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