Fix the docker build error for vfc-nfvo-wfengine
[vfc/nfvo/wfengine.git] / activiti-extension / src / main / docker / bin / entrypoint.sh
1 #!/usr/bin/env sh
2 # $0 is a script name, 
3 # $1, $2, $3 etc are passed arguments
4 # $1 is our command
5 CMD=$1
6
7 if [ -z "$SERVICE_IP" ]; then
8     export SERVICE_IP=`hostname -i`
9 fi
10 echo "SERVICE_IP=$SERVICE_IP"
11
12 if [ -z "$SERVICE_PORT" ]; then
13     export SERVICE_PORT=8080
14 fi
15 echo "SERVICE_PORT=$SERVICE_PORT"
16
17 if [ -z "$OPENPALETTE_MSB_IP" ]; then
18     echo "Missing required variable OPENPALETTE_MSB_IP: Microservices Service Bus address <ip>:<port>"
19     exit 1
20 fi
21 if [ -z "$OPENPALETTE_MSB_PORT" ]; then
22     echo "Missing required variable OPENPALETTE_MSB_PORT: Microservices Service Bus address <ip>:<port>"
23     exit 1
24 fi
25 echo "MSB_ADDR=${OPENPALETTE_MSB_IP}:${OPENPALETTE_MSB_PORT}"
26
27 # Wait for MSB initialization
28 echo "Wait for MSB initialization"
29 for i in {1..5}; do
30     curl -sS -m 1 ${OPENPALETTE_MSB_IP}:${OPENPALETTE_MSB_PORT} > /dev/null && break
31     sleep $i
32 done
33
34 curl -X POST --data '{"serviceName": "activiti-rest","version": "v1","url": "/activiti-rest/","path": "/activiti-rest/","protocol": "REST","visualRange": "1","nodes": [{"ip": "${SERVICE_IP}","port": "${SERVICE_PORT}","ttl": 0}]}' http://${OPENPALETTE_MSB_IP}:${OPENPALETTE_MSB_PORT}/api/microservices/v1/services -H "Accept: Application/json" -H "Content-Type:application/json"
35
36 case "$CMD" in  
37   "dev" )
38     ;;
39   "start" )
40     # we can modify files here, using ENV variables passed in 
41     # "docker create" command. It can't be done during build process.
42     exec ./catalina.sh run
43     ;;
44    * )
45     # Run custom command. Thanks to this line we can still use 
46     # "docker run our_image /bin/bash" and it will work
47     exec $CMD ${@:2}
48     ;;
49 esac