blob: 323a6d4f4f058f1f3278a42bdcca09b98a7fc870 [file] [log] [blame]
Jonathan Harted96bfb2018-02-08 17:18:28 -08001#!/bin/bash
2
3# Runs VOLTHA using a templatized docker stack file.
4# We need to use a templatized file to configure a few things that docker doesn't
5# make configurable through variables right now, namely number of replicas and
6# volume mounts. This runner script first substites some environment variables
7# in to the tempated stack file, then runs that stack file.
8#
9# Look in the stack file template to see what can be configured through environment
10# variables - these variable should be set in the environment that runs this script.
11
12set -e
13
14TAG=${TAG:-latest}
15STACK_TEMPLATE=${STACK_TEMPLATE:-"voltha-stack.yml.j2"}
16
17start () {
18 SWARM_MANAGER_COUNT=$(docker node ls | grep Ready | egrep "(Leader)|(Reachable)" | wc -l | sed -e "s/ //g")
19 if [ $SWARM_MANAGER_COUNT -lt 1 ]; then
20 echo "No swarm managers found. Run 'docker swarm init' to create a new manager"
21 exit 1
22 fi
23
24 downloaded=0
25 if [ ! -f "$STACK_TEMPLATE" ]; then
26 wget https://raw.githubusercontent.com/opencord/voltha/master/compose/voltha-stack.yml.j2
27 downloaded=1
28 fi
29
30 TMP_STACK_FILE=$(mktemp -u)
31
Jonathan Hart93ca1d12018-03-21 09:21:35 -070032 cat $STACK_TEMPLATE 2>&1 | docker run -e RADIUS_ROOT=$RADIUS_ROOT -e CONSUL_ROOT=$CONSUL_ROOT -e VOLTHA_LOGS=$VOLTHA_LOGS -e SWARM_MANAGER_COUNT=$SWARM_MANAGER_COUNT -e ONOS_CONFIG=$ONOS_CONFIG --rm -i ${REGISTRY}${REPOSITORY}voltha-j2:${TAG} - 2>&1 > $TMP_STACK_FILE
Jonathan Harted96bfb2018-02-08 17:18:28 -080033 docker stack deploy -c $TMP_STACK_FILE voltha
34
35 rm -f $TMP_STACK_FILE
36
37 if [ $downloaded -eq 1 ]; then
38 rm -f $STACK_TEMPLATE
39 fi
40}
41
42stop () {
43 docker stack rm voltha
44}
45
46status() {
47 if [ -z "$(docker stack ls | grep voltha)" ]; then
48 echo "Stopped"
49 exit
50 fi
51
52 STATUS="Running"
53 for i in $(docker service ls --format '{{.Name}}/{{.Replicas}}' | grep "^voltha_" | grep -v voltha_config_push); do
54 NAME=$(echo $i | cut -d/ -f1)
55 HAVE=$(echo $i | cut -d/ -f2)
56 WANT=$(echo $i | cut -d/ -f3)
57 if [ $HAVE -ne $WANT ]; then
58 echo "$NAME not running: $HAVE of $WANT"
59 STATUS="Incomplete"
60 fi
61 done
62
63 echo $STATUS
64}
65
66case $1 in
67 start)
68 start
69 ;;
70 status)
71 status
72 ;;
73 stop)
74 stop
75 ;;
76 *)
77 echo "Usage: $0 {start|status|stop}" >&2
78 exit 1
79 ;;
Jonathan Hart93ca1d12018-03-21 09:21:35 -070080esac