42225a057118412b998e53c3beee5bc1e6be6e76
[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
18 pids() {
19         set -x
20         ps -ef | grep java | grep $MAIN | sed -e 's/[^ ]* *//' -e 's/ .*//'
21         set +x
22 }
23
24 config() {
25         set -x
26         if [ ! -d $APP_ROOT ]
27         then
28                 echo "Expected app root directory $APP_ROOT does not exist"
29                 exit 1
30         fi
31         if [ !  -f $CONTAINER_CONFIG ]
32         then
33                 echo "Expected env file $CONTAINER_CONFIG not found"
34                 exit 1
35         fi
36         cd $APP_ROOT
37         source $CONTAINER_CONFIG
38
39         if [ "$DMAAPBC_WAIT_TO_EXIT" != "Y" ]
40         then
41                 echo "Creating $APP_ROOT/ok_to_exit so no waiting..."
42                 > $APP_ROOT/ok_to_exit
43         else
44                 echo "Not creating $APP_ROOT/ok_to_exit"
45         fi      
46         
47         if [ ! -f $APP_ROOT/misc/cert-client-init.sh ]
48         then
49                 echo "Did not find $APP_ROOT/misc/cert-client-init.sh to append to truststore"
50                 exit 1
51         fi
52         $APP_ROOT/misc/cert-client-init.sh
53         . misc/havecert.tmpl > etc/havecert
54         chmod +x etc/havecert
55         . misc/dmaapbc.properties.tmpl > etc/dmaapbc.properties
56     . misc/PolicyEngineApi.properties.tmpl > config/PolicyEngineApi.properties
57         set +x
58 }
59
60 start() {
61         set -x
62         ID=`id -n -u`
63         GRP=`id -n -g`
64         if [ "$ID" != "$USER" ]
65         then
66                 echo $COMPONENT must be started as user $USER not $ID
67                 exit 1
68         fi
69         if [ "$GRP" != "$USER" ]
70         then
71                 echo $COMPONENT must be started as group $USER not $GRP
72                 exit 1
73         fi
74         cd $APP_ROOT
75
76         if etc/havecert
77         then
78                 echo >/dev/null
79         else
80                 echo No certificate file available.  Cannot start
81                 exit 0
82         fi
83         PIDS=`pids`
84         if [ "$PIDS" != "" ]
85         then
86                 echo $COMPONENT already running
87                 exit 0
88         fi
89         rm -f $APP_ROOT/etc/SHUTDOWN
90
91         # JVM flags
92 #old line from Dockerfile...keep for reference only
93         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"
94         #nohup java $FLAGS $MAIN </dev/null >/dev/null 2>&1 &
95         nohup java $FLAGS $MAIN </dev/null  &
96         sleep 5
97         PIDS=`pids`
98         set +x
99 }
100
101 stop() {
102         ID=`id -n -u`
103         GRP=`id -n -g`
104         if [ "$ID" != "$USER" ]
105         then
106                 echo $COMPONENT must be stopped as user $USER not $ID
107                 exit 1
108         fi
109         if [ "$GRP" != "$USER" ]
110         then
111                 echo $COMPONENT must be stopped as group $USER not $GRP
112                 exit 1
113         fi
114         touch $APP_ROOT/etc/SHUTDOWN
115         PIDS=`pids`
116         if [ "$PIDS" != "" ]
117         then
118                 sleep 5
119                 kill -9 $PIDS
120                 sleep 5
121                 echo $COMPONENT stopped
122         else
123                 echo $COMPONENT not running
124         fi
125 }
126
127 status() {
128         PIDS=`pids`
129         if [ "$PIDS" != "" ]
130         then
131                 echo $COMPONENT running
132         else
133                 echo $COMPONENT not running
134         fi
135 }
136
137 set -x
138 case "$1" in
139 'deploy')
140         config
141         start
142         wait
143         ;;
144 'start')
145         start
146         ;;
147 'stop')
148         stop
149         ;;
150 'restart')
151         stop
152         sleep 20
153         start
154         ;;
155 'status')
156         status
157         ;;
158 *)
159         echo "Usage: $0 { start | stop | restart }"
160         exit 1
161         ;;
162 esac
163                 ls -l $APP_ROOT/logs/ONAP
164                 echo "------------ tail -100 error.log ---------------"
165                 tail -100  $APP_ROOT/logs/ONAP/error.log
166                 echo "------------ tail -100 server.log ---------------"
167                 tail -100  $APP_ROOT/logs/ONAP/server.log
168                 echo "------------ tail -100 application.log ---------------"
169                 tail -100 $APP_ROOT/logs/ONAP/application.log
170
171                 echo "Check $APP_ROOT/ok_to_exit"
172                 while [ ! -f $APP_ROOT/ok_to_exit ]
173                 do
174                         echo "$APP_ROOT/ok_to_exit does not exist.  Sticking around for debugging..."
175                         sleep 10
176                 done
177 exit 0