#!/bin/bash

usage="$0 start/stop"
if [ $# -ne 1 ]; then
    echo USAGE: $usage
    exit 1
fi

case $1 in
start)
    set -e

    /usr/bin/docker run --rm \
      -p 10000:{{ auth_proxy_port }} \
      --net=host --name=auth-proxy \
      -e NO_NETMASTER_STARTUP_CHECK=1 \
      -v /var/contiv:/var/contiv:z \
      {{ auth_proxy_image }} \
      --tls-key-file={{ auth_proxy_key }} \
      --tls-certificate={{ auth_proxy_cert }} \
      --data-store-address={{ auth_proxy_datastore }} \
      --netmaster-address={{ service_vip }}:9999 \
      --listen-address=:10000 
    ;;

stop)
    # don't stop on error
    /usr/bin/docker stop auth-proxy
    /usr/bin/docker rm -f -v  auth-proxy
    ;;

*)
    echo USAGE: $usage
    exit 1
    ;;
esac
