description "Kontena agent"

start on started docker
stop on stopping docker

respawn

script
  if [ -f /etc/default/$UPSTART_JOB ]; then
    . /etc/default/$UPSTART_JOB
  fi

  DOCKER_GW_IP=$(ifconfig docker0 2>/dev/null|awk '/inet addr:/ {print $2}'|sed 's/addr://')
  echo "nameserver $DOCKER_GW_IP" > /etc/resolvconf/resolv.conf.d/head
  resolvconf -u || true

  DOCKER=/usr/bin/docker
  $DOCKER rm -f kontena-agent || true
  $DOCKER run --name=kontena-agent \
      -e KONTENA_URI=$KONTENA_URI \
      -e KONTENA_TOKEN=$KONTENA_TOKEN \
      -e KONTENA_PEER_INTERFACE=$KONTENA_PEER_INTERFACE \
      -v=/var/run/docker.sock:/var/run/docker.sock \
      --net=host \
      kontena/agent:VERSION
end script
