corrections for packaging and CSIT
[dmaap/buscontroller.git] / misc / dmaapbc
1 #!/bin/bash
2
3 umask 0022
4 TZ=GMT0
5 COMPONENT=dmaapbc
6 APP_ROOT=/opt/app/$COMPONENT
7 USER=root
8 export TZ
9 PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/java/jdk/jdk180/bin
10 export PATH
11 CLASSPATH=`echo $APP_ROOT/etc $APP_ROOT/lib/*.jar | tr ' ' ':'` 
12 export CLASSPATH
13 CONTAINER_CONFIG=/opt/app/config/conf
14 MAIN=org.onap.dmaap.dbcapi.server.Main 
15
16
17 pids() {
18         #set -x
19         ps -ef | grep java | grep $MAIN | sed -e 's/[^ ]* *//' -e 's/ .*//'
20         #set +x
21 }
22
23 config() {
24         set -x
25         if [ ! -d $APP_ROOT ]
26         then
27                 echo "Expected app root directory $APP_ROOT does not exist"
28                 exit 1
29         fi
30         if [ !  -f $CONTAINER_CONFIG ]
31         then
32                 echo "Expected env file $CONTAINER_CONFIG not found"
33                 exit 1
34         fi
35         cd $APP_ROOT
36         source $CONTAINER_CONFIG
37         if [ ! -f $APP_ROOT/misc/cert-client-init.sh ]
38         then
39                 echo "Did not find $APP_ROOT/misc/cert-client-init.sh to append to truststore"
40                 exit 1
41         fi
42         $APP_ROOT/misc/cert-client-init.sh
43         . misc/dmaapbc.properties.tmpl > etc/dmaapbc.properties
44     . misc/PolicyEngineApi.properties.tmpl > config/PolicyEngineApi.properties
45         set +x
46 }
47
48 start() {
49         set -x
50         ID=`id -n -u`
51         GRP=`id -n -g`
52         if [ "$ID" != "$USER" ]
53         then
54                 echo $COMPONENT must be started as user $USER not $ID
55                 exit 1
56         fi
57         if [ "$GRP" != "$USER" ]
58         then
59                 echo $COMPONENT must be started as group $USER not $GRP
60                 exit 1
61         fi
62         cd $APP_ROOT
63
64 # disable until we use certs
65 #       if etc/havecert
66 #       then
67                 echo >/dev/null
68 #       else
69 #               echo No certificate file available.  Cannot start
70 #               exit 0
71 #       fi
72         PIDS=`pids`
73         if [ "$PIDS" != "" ]
74         then
75                 echo $COMPONENT already running
76                 exit 0
77         fi
78         rm -f $APP_ROOT/etc/SHUTDOWN
79
80         # JVM flags
81 #old line from Dockerfile...keep for reference only
82         FLAGS="-cp etc:lib/* -Dlog4j.configuration=etc/log4j.properties -Ddmaapbc.properties=etc/dmaapbc.properties  -Dhttps.protocols=TLSv1.2 -Dhttps.cipherSuites=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"
83         nohup java $FLAGS $MAIN </dev/null >/dev/null 2>&1 &
84         sleep 5
85         PIDS=`pids`
86         if [ "$PIDS" = "" ]
87         then
88                 echo $COMPONENT startup failed
89                 ls -l $APP_ROOT/logs/EELF
90                 echo "------------ error.log ---------------"
91                 cat $APP_ROOT/logs/EELF/error.log
92                 echo "------------ server.log ---------------"
93                 cat $APP_ROOT/logs/EELF/server.log
94                 echo "------------ tail -100 application.log ---------------"
95                 tail -100 $APP_ROOT/logs/EELF/application.log
96         else
97                 echo $COMPONENT started
98         fi
99         set +x
100 }
101
102 stop() {
103         ID=`id -n -u`
104         GRP=`id -n -g`
105         if [ "$ID" != "$USER" ]
106         then
107                 echo $COMPONENT must be stopped as user $USER not $ID
108                 exit 1
109         fi
110         if [ "$GRP" != "$USER" ]
111         then
112                 echo $COMPONENT must be stopped as group $USER not $GRP
113                 exit 1
114         fi
115         touch $APP_ROOT/etc/SHUTDOWN
116         PIDS=`pids`
117         if [ "$PIDS" != "" ]
118         then
119                 sleep 5
120                 kill -9 $PIDS
121                 sleep 5
122                 echo $COMPONENT stopped
123         else
124                 echo $COMPONENT not running
125         fi
126 }
127
128 status() {
129         PIDS=`pids`
130         if [ "$PIDS" != "" ]
131         then
132                 echo $COMPONENT running
133         else
134                 echo $COMPONENT not running
135         fi
136 }
137
138 set -x
139 case "$1" in
140 'deploy')
141         config
142         start
143         wait
144         ;;
145 'start')
146         start
147         ;;
148 'stop')
149         stop
150         ;;
151 'restart')
152         stop
153         sleep 20
154         start
155         ;;
156 'status')
157         status
158         ;;
159 *)
160         echo "Usage: $0 { start | stop | restart }"
161         exit 1
162         ;;
163 esac
164 exit 0