19bb3f7a50e6a36c3325d576eba952f78c34d218
[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         sleep 5
86         PIDS=`pids`
87         if [ "$PIDS" = "" ]
88         then
89                 echo $COMPONENT startup failed
90                 ls -l $APP_ROOT/logs/EELF
91                 echo "------------ error.log ---------------"
92                 cat $APP_ROOT/logs/EELF/error.log
93                 echo "------------ server.log ---------------"
94                 cat $APP_ROOT/logs/EELF/server.log
95                 echo "------------ tail -100 application.log ---------------"
96                 tail -100 $APP_ROOT/logs/EELF/application.log
97         else
98                 echo $COMPONENT started
99         fi
100         set +x
101 }
102
103 stop() {
104         ID=`id -n -u`
105         GRP=`id -n -g`
106         if [ "$ID" != "$USER" ]
107         then
108                 echo $COMPONENT must be stopped as user $USER not $ID
109                 exit 1
110         fi
111         if [ "$GRP" != "$USER" ]
112         then
113                 echo $COMPONENT must be stopped as group $USER not $GRP
114                 exit 1
115         fi
116         touch $APP_ROOT/etc/SHUTDOWN
117         PIDS=`pids`
118         if [ "$PIDS" != "" ]
119         then
120                 sleep 5
121                 kill -9 $PIDS
122                 sleep 5
123                 echo $COMPONENT stopped
124         else
125                 echo $COMPONENT not running
126         fi
127 }
128
129 status() {
130         PIDS=`pids`
131         if [ "$PIDS" != "" ]
132         then
133                 echo $COMPONENT running
134         else
135                 echo $COMPONENT not running
136         fi
137 }
138
139 set -x
140 case "$1" in
141 'deploy')
142         config
143         start
144         wait
145         ;;
146 'start')
147         start
148         ;;
149 'stop')
150         stop
151         ;;
152 'restart')
153         stop
154         sleep 20
155         start
156         ;;
157 'status')
158         status
159         ;;
160 *)
161         echo "Usage: $0 { start | stop | restart }"
162         exit 1
163         ;;
164 esac
165 exit 0