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