TOPIC: ODL DOCKER
[genesis.git] / fuel / build / f_odl_docker / puppet / modules / opnfv / scripts / start_odl_container.sh
1 #!/bin/bash
2 #  Ericsson Canada Inc.
3 #  Authoer: Daniel Smith
4 #
5 #   A helper script to install and setup the ODL docker conatiner on the controller
6 #
7 #
8 #   Inputs:  odl_docker_image.tar
9 #
10 #   Usage:  ./start_odl_docker.sh
11
12 # ENVS
13 source ~/.bashrc
14 source ~/openrc
15
16 # VARS
17
18 # Switch for Dev mode - uses apt-get on control to cheat and get docker installed locally rather than from puppet source
19
20 DEV=1
21
22 # Switch for 1:1 port mapping of EXPOSED ports in Docker to the host, if set to 0, then random ports will be used - NOTE: this doesnt work for all web services X port on Host --> Y port in Container,
23 # especially for SSL/HTTPS cases. Be aware.
24
25 MATCH_PORT=1
26
27 LOCALPATH=/opt/opnfv/odl_docker
28 DOCKERBINNAME=docker-latest
29 DOCKERIMAGENAME=odl_docker_image.tar
30 DNS=8.8.8.8
31 HOST_IP=`ifconfig br-fw-admin  | grep -i "inet addr" | awk -F":" '{print $2}' | awk -F" " '{print $1}'`
32
33
34 # Set this to "1" if you want to have your docker container startup into a shell
35
36
37 ENABLE_SHELL=1
38
39
40 echo " Fetching Docker "
41 if [ "$DEV" -eq "1" ];
42 # If testing Locally (on a control node) you can set DEV=1 to enable apt-get based install on the control node (not desired target, but good for testing).
43 then
44         echo "Dev Mode - Fetching from Internet";
45         echo " this wont work in production builds";
46         apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
47         mkdir -p $LOCALPATH
48         wget https://get.docker.com/builds/Linux/x86_64/docker-latest -O $LOCALPATH/$DOCKERBINNAME
49         wget http://ftp.us.debian.org/debian/pool/main/d/docker.io/docker.io_1.3.3~dfsg1-2_amd64.deb
50         chmod 777 $LOCALPATH/$DOCKERBINNAME
51         echo "done ";
52 else
53         echo "Using Binaries delivered from Puppet"
54         echo "Starting Docker in Daemon mode"
55         chmod +x $LOCALPATH/$DOCKERBINNAME
56         $LOCALPATH/$DOCKERBINNAME -d &
57 fi
58
59
60 # We need to perform some cleanup of the Openstack Environment
61 echo "TODO -- This should be automated in the Fuel deployment at some point"
62 echo "However, the timing should come after basic tests are running, since this "
63 echo " part will remove the subnet router association that is deployed automativally"
64 echo " via fuel. Refer to the ODL + Openstack Integration Page "
65
66 # Import the ODL container into docker
67
68 echo "Importing ODL container into docker"
69 $LOCALPATH/$DOCKERBINNAME load -i $LOCALPATH/$DOCKERIMAGENAME
70
71 echo " starting up ODL - DLUX and Mapping Ports"
72 if [ "$MATCH_PORT" -eq "1" ]
73 then
74         echo "Starting up Docker..."
75         docker rm odl_docker
76
77 if [ "$ENABLE_SHELL" -eq "1" ];
78 then
79         echo "Starting Container in Interactive Mode (/bin/bash will be provided, you will need to run ./start_odl_docker.sh inside the container yourself)"
80         docker run --name odl_docker -p 8181:8181 -p 8185:8185 -p 9000:9000 -p 1099:1099 -p 8101:8101 -p 6633:6633 -p 43506:43506 -p 44444:44444 -p 6653:6653 -p 12001:12001 -p 6400:6400 -p 8080:8080 -p 7800:7800 -p 55130:55130 -p 52150:52150 -p 36826:26826 -i -d -t loving_daniel  /bin/bash
81 else
82         echo "Starting Conatiner in Daemon mode - no shell will be provided and docker attach will not provide shell)"
83         docker run --name odl_docker -p 8181:8181 -p 8185:8185 -p 9000:9000 -p 1099:1099 -p 8101:8101 -p 6633:6633 -p 43506:43506 -p 44444:44444 -p 6653:6653 -p 12001:12001 -p 6400:6400 -p 8080:8080 -p 7800:7800 -p 55130:55130 -p 52150:52150 -p 36826:26826 -i -d -t loving_daniel
84         echo "should see the process listed here in docker ps -a"
85         docker ps -a;
86         echo "Match Port  enabled, you can reach the DLUX login at: "
87         echo "http://$HOST_IP:8181/dlux.index.html"
88 fi