description "Kontena server haproxy"

start on starting kontena-server-api
stop on stopping kontena-server-api

respawn

script
  if [ -f /etc/default/$UPSTART_JOB ]; then
    . /etc/default/$UPSTART_JOB
  fi
  if [ -n "$SSL_CERT" ]; then
    SSL_CERT=$(awk 1 ORS='\\n' $SSL_CERT)
  else
    SSL_CERT="**None**"
  fi
  DOCKER=/usr/bin/docker
  $DOCKER rm -f kontena-server-haproxy || true
  $DOCKER run --name=kontena-server-haproxy \
    --link kontena-server-api:kontena-server-api \
    -e SSL_CERT="$SSL_CERT" -e BACKEND_PORT=9292 \
    -p 8080:80 -p 8443:443 kontena/haproxy:latest
end script
