title: AWS ECS tasks keep starting and stopping
body: <p>I am trying to use ECS for deployment with travis.
  At one point everything was working but now it stopped.</p>
  
  <p>I am following this tutorial <a href="https://testdriven.io/part-five-ec2-container-service/" rel="nofollow noreferrer">https://testdriven.io/part-five-ec2-container-service/</a></p>
  
  <p>There are 2 tasks that keep stopping and starting.</p>
  
  <p>These are the messages I see in tasks:</p>
  
  <pre><code>STOPPED (CannotStartContainerError: API error (500): oci ru)
  
  STOPPED (Essential container in task exited)
  </code></pre>
  
  <p>These are the messages I see in the logs:</p>
  
  <pre><code>FATAL: could not write to file "pg_wal/xlogtemp.28": No space left on device
  
  container_linux.go:262: starting container process caused "exec: \"./entrypoint.sh\": permission denied"
  </code></pre>
  
  <p>Why is ECS stopping and starting so many new tasks? This was not happening before.</p>
  
  <p>This is my docker_deploy.sh from my main microservice which I am calling via travis.</p>
  
  <pre><code>#!/bin/sh
  
  
  if [ -z "$TRAVIS_PULL_REQUEST" ] || [ "$TRAVIS_PULL_REQUEST" == "false" ];
  then
  
      if [ "$TRAVIS_BRANCH" == "staging" ];
      then
          JQ="jq --raw-output --exit-status"
  
          configure_aws_cli() {
              aws --version
              aws configure set default.region us-east-1
              aws configure set default.output json
              echo "AWS Configured!"
          }
  
          make_task_def() {
              task_template=$(cat ecs_taskdefinition.json)
              task_def=$(printf "$task_template" $AWS_ACCOUNT_ID $AWS_ACCOUNT_ID)
              echo "$task_def"
          }
  
          register_definition() {
              if revision=$(aws ecs register-task-definition --cli-input-json "$task_def" --family $family | $JQ '.taskDefinition.taskDefinitionArn');
              then
                  echo "Revision: $revision"
              else
                  echo "Failed to register task definition"
                  return 1
              fi
          }
  
          deploy_cluster() {
  
              family="testdriven-staging"
              cluster="ezasdf-staging"
              service="ezasdf-staging"
  
              make_task_def
              register_definition
  
              if [[ $(aws ecs update-service --cluster $cluster --service $service --task-definition $revision | $JQ '.service.taskDefinition') != $revision ]];
              then
                  echo "Error updating service."
                  return 1
              fi
  
          }
  
          configure_aws_cli
          deploy_cluster
  
      fi
  fi
  </code></pre>
  
  <p>This is my Dockerfile from my users microservice:</p>
  
  <pre><code>FROM python:3.6.2
  
  # install environment dependencies
  RUN apt-get update -yqq \
      &amp;&amp; apt-get install -yqq --no-install-recommends \
          netcat \
      &amp;&amp; apt-get -q clean
  
  # set working directory
  RUN mkdir -p /usr/src/app
  WORKDIR /usr/src/app
  
  # add requirements (to leverage Docker cache)
  ADD ./requirements.txt /usr/src/app/requirements.txt
  
  # install requirements
  RUN pip install -r requirements.txt
  
  # add entrypoint.sh
  ADD ./entrypoint.sh /usr/src/app/entrypoint.sh
  RUN chmod +x /usr/src/app/entrypoint.sh
  
  # add app
  ADD . /usr/src/app
  
  # run server
  CMD ["./entrypoint.sh"]
  </code></pre>
  
  <p>entrypoint.sh:</p>
  
  <pre><code>#!/bin/sh
  
  
  echo "Waiting for postgres..."
  
  while ! nc -z users-db 5432;
  do
      sleep 0.1
  done
  
  echo "PostgreSQL started"
  
  python manage.py recreate_db
  python manage.py seed_db
  gunicorn -b 0.0.0.0:5000 manage:app
  </code></pre>
  
  <p>I tried deleting my cluster and deregistering my tasks and restarting but ECS still continuously stops and starts new tasks now.</p>
  
  <p>When it was working fine: the difference was that instead of the <code>CMD ["./entrypoint.sh"]</code> in my Dockerfile, I had</p>
  
  <pre><code>RUN python manage.py recreate_db
  RUN python manage.py seed_db
  CMD gunicorn -b 0.0.0.0:5000 manage:app
  </code></pre>
  
  <p>travis is passing.</p>