blob: c44a25bc7978ca9e447f4dad9a757a9b2886e0f2 [file] [log] [blame]
Jonathan Hart2dd29dd2018-02-08 17:18:28 -08001#!/bin/bash
Zack Williams41513bf2018-07-07 20:08:35 -07002# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
Jonathan Hart2dd29dd2018-02-08 17:18:28 -080015
16# Runs VOLTHA using a templatized docker stack file.
17# We need to use a templatized file to configure a few things that docker doesn't
18# make configurable through variables right now, namely number of replicas and
19# volume mounts. This runner script first substites some environment variables
20# in to the tempated stack file, then runs that stack file.
21#
22# Look in the stack file template to see what can be configured through environment
23# variables - these variable should be set in the environment that runs this script.
24
25set -e
26
27TAG=${TAG:-latest}
28STACK_TEMPLATE=${STACK_TEMPLATE:-"voltha-stack.yml.j2"}
29
30start () {
31 SWARM_MANAGER_COUNT=$(docker node ls | grep Ready | egrep "(Leader)|(Reachable)" | wc -l | sed -e "s/ //g")
32 if [ $SWARM_MANAGER_COUNT -lt 1 ]; then
33 echo "No swarm managers found. Run 'docker swarm init' to create a new manager"
34 exit 1
35 fi
36
37 downloaded=0
38 if [ ! -f "$STACK_TEMPLATE" ]; then
39 wget https://raw.githubusercontent.com/opencord/voltha/master/compose/voltha-stack.yml.j2
40 downloaded=1
41 fi
42
43 TMP_STACK_FILE=$(mktemp -u)
44
Jonathan Harta0252ac2018-03-21 09:21:35 -070045 cat $STACK_TEMPLATE 2>&1 | docker run -e CUSTOM_CLI_LABEL=$CUSTOM_CLI_LABEL -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 Hart2dd29dd2018-02-08 17:18:28 -080046 docker stack deploy -c $TMP_STACK_FILE voltha
47
48 rm -f $TMP_STACK_FILE
49
50 if [ $downloaded -eq 1 ]; then
51 rm -f $STACK_TEMPLATE
52 fi
53}
54
55stop () {
56 docker stack rm voltha
57}
58
59status() {
60 if [ -z "$(docker stack ls | grep voltha)" ]; then
61 echo "Stopped"
62 exit
63 fi
64
65 STATUS="Running"
66 for i in $(docker service ls --format '{{.Name}}/{{.Replicas}}' | grep "^voltha_" | grep -v voltha_config_push); do
67 NAME=$(echo $i | cut -d/ -f1)
68 HAVE=$(echo $i | cut -d/ -f2)
69 WANT=$(echo $i | cut -d/ -f3)
70 if [ $HAVE -ne $WANT ]; then
71 echo "$NAME not running: $HAVE of $WANT"
72 STATUS="Incomplete"
73 fi
74 done
75
76 echo $STATUS
77}
78
79case $1 in
80 start)
81 start
82 ;;
83 status)
84 status
85 ;;
86 stop)
87 stop
88 ;;
89 *)
90 echo "Usage: $0 {start|status|stop}" >&2
91 exit 1
92 ;;
David K. Bainbridge60fdad72018-02-20 11:17:38 -050093esac