8f9d084fa8784d61457d1e5946002c3245bd6583
[vfc/nfvo/wfengine.git] / wfenginemgrservice / 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=10550
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 curldata='{"serviceName": "workflow", "version": "v1", "url": "/api/workflow/v1","protocol": "REST", "visualRange": "1", "nodes": [ {"ip": "'$SERVICE_IP'","port": "'$SERVICE_PORT'","ttl": 0}]}'
35
36 curl -v -X POST -H "Accept: Application/json" -H "Content-Type: application/json" -d "${curldata}" http://$OPENPALETTE_MSB_IP:$OPENPALETTE_MSB_PORT/api/microservices/v1/services
37
38 case "$CMD" in  
39   "dev" )
40     ;;
41   "start" )
42     # we can modify files here, using ENV variables passed in 
43     # "docker create" command. It can't be done during build process.
44     exec ./run.sh
45     ;;
46    * )
47     # Run custom command. Thanks to this line we can still use 
48     # "docker run our_image /bin/bash" and it will work
49     exec $CMD ${@:2}
50     ;;
51 esac