Modify for k8s deployment compatibility
[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         # comment out till certs are available
38         #if [ ! -f $APP_ROOT/misc/cert-client-init.sh ]
39         #then
40         #       echo "Did not find $APP_ROOT/misc/cert-client-init.sh to append to truststore"
41         #       exit 1
42         #fi
43         #$APP_ROOT/misc/cert-client-init.sh
44         . misc/dmaapbc.properties.tmpl > etc/dmaapbc.properties
45     . misc/PolicyEngineApi.properties.tmpl > config/PolicyEngineApi.properties
46         set +x
47 }
48
49 start() {
50         set -x
51         ID=`id -n -u`
52         GRP=`id -n -g`
53         if [ "$ID" != "$USER" ]
54         then
55                 echo $COMPONENT must be started as user $USER not $ID
56                 exit 1
57         fi
58         if [ "$GRP" != "$USER" ]
59         then
60                 echo $COMPONENT must be started as group $USER not $GRP
61                 exit 1
62         fi
63         cd $APP_ROOT
64
65 # disable until we use certs
66 #       if etc/havecert
67 #       then
68                 echo >/dev/null
69 #       else
70 #               echo No certificate file available.  Cannot start
71 #               exit 0
72 #       fi
73         PIDS=`pids`
74         if [ "$PIDS" != "" ]
75         then
76                 echo $COMPONENT already running
77                 exit 0
78         fi
79         rm -f $APP_ROOT/etc/SHUTDOWN
80
81         # JVM flags
82 #old line from Dockerfile...keep for reference only
83         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"
84         #nohup java $FLAGS $MAIN </dev/null >/dev/null 2>&1 &
85         nohup java $FLAGS $MAIN </dev/null  &
86         sleep 5
87         PIDS=`pids`
88         set +x
89 }
90
91 stop() {
92         ID=`id -n -u`
93         GRP=`id -n -g`
94         if [ "$ID" != "$USER" ]
95         then
96                 echo $COMPONENT must be stopped as user $USER not $ID
97                 exit 1
98         fi
99         if [ "$GRP" != "$USER" ]
100         then
101                 echo $COMPONENT must be stopped as group $USER not $GRP
102                 exit 1
103         fi
104         touch $APP_ROOT/etc/SHUTDOWN
105         PIDS=`pids`
106         if [ "$PIDS" != "" ]
107         then
108                 sleep 5
109                 kill -9 $PIDS
110                 sleep 5
111                 echo $COMPONENT stopped
112         else
113                 echo $COMPONENT not running
114         fi
115 }
116
117 status() {
118         PIDS=`pids`
119         if [ "$PIDS" != "" ]
120         then
121                 echo $COMPONENT running
122         else
123                 echo $COMPONENT not running
124         fi
125 }
126
127 set -x
128 case "$1" in
129 'deploy')
130         config
131         start
132         wait
133         ;;
134 'start')
135         start
136         ;;
137 'stop')
138         stop
139         ;;
140 'restart')
141         stop
142         sleep 20
143         start
144         ;;
145 'status')
146         status
147         ;;
148 *)
149         echo "Usage: $0 { start | stop | restart }"
150         exit 1
151         ;;
152 esac
153                 ls -l $APP_ROOT/logs/EELF
154                 echo "------------ tail -100 error.log ---------------"
155                 tail -100  $APP_ROOT/logs/EELF/error.log
156                 echo "------------ tail -100 server.log ---------------"
157                 tail -100  $APP_ROOT/logs/EELF/server.log
158                 echo "------------ tail -100 application.log ---------------"
159                 tail -100 $APP_ROOT/logs/EELF/application.log
160 exit 0