如何防止类似多米诺骨牌的“已停止”任务产生影响,这是一个好主意吗?

时间:2019-08-06 19:52:01

标签: amazon-ecs aws-fargate

当我使用ecs-cli compose --file <...> --project-name <...> --aws-profile <...> service up --create-log-groups --cluster <...> --launch-type FARGATE --region eu-west-1启动AWS ECS任务定义修订版时,某些任务会从PENDING变为RUNNING状态。问题是,如果一个容器进入STOPPED状态,其余的容器似乎会自动进入类似的STOPPED状态。有没有办法防止这种情况,只让特定的容器独立崩溃,还是“反模式”?

所有容器同时崩溃会使调试更加困难。

这是为ecs-cli compose service up提供的Dockerfile:

services:
  ...-file-api:
    environment:
      ...     
    image: ...
    logging:
      driver: awslogs
      options:
        awslogs-group: /ecs/log
        awslogs-region: eu-west-1
        awslogs-stream-prefix: ...-file-api
    ports:
      - 3054:3054
    restart: always
  ...-frontend:
    image: ...
    logging:
      driver: awslogs
      options:
        awslogs-group: /ecs/log
        awslogs-region: eu-west-1
        awslogs-stream-prefix: ...-frontend
    ports:
      - 80:80
    restart: always
  ...-help-api:
    environment:
      ...
    image: ...
    logging:
      driver: awslogs
      options:
        awslogs-group: /ecs/log
        awslogs-region: eu-west-1
        awslogs-stream-prefix: ...-help-api
    ports:
      - 3059:3059
    restart: always
  ...-login-api:
    environment:
      ...
    image: ...
    logging:
      driver: awslogs
      options:
        awslogs-group: /ecs/log
        awslogs-region: eu-west-1
        awslogs-stream-prefix: ...-login-api
    ports:
      - 3055:3055
    restart: always
  ...-login-frontend:
    image: ...
    logging:
      driver: awslogs
      options:
        awslogs-group: /ecs/log
        awslogs-region: eu-west-1
        awslogs-stream-prefix: ...-login-frontend
    ports:
      - 8080:8080
    restart: always
  ...-mail-api:
    environment:
      ...
    image: ...
    logging:
      driver: awslogs
      options:
        awslogs-group: /ecs/log
        awslogs-region: eu-west-1
        awslogs-stream-prefix: ...-mail-api
    ports:
      - 3063:3063
    restart: always
  ...-main-api:
    environment:
      ...
    image: ...
    logging:
      driver: awslogs
      options:
        awslogs-group: /ecs/log
        awslogs-region: eu-west-1
        awslogs-stream-prefix: ...-main-api
    ports:
      - 3053:3053
    restart: always
  ...-mongo:
    image: mongo:3.4.20-xenial
    logging:
      driver: awslogs
      options:
        awslogs-group: /ecs/log
        awslogs-region: eu-west-1
        awslogs-stream-prefix: ...-mongo
    restart: always
  ...-plan-api:
    environment:
      ...
    image: ...
    logging:
      driver: awslogs
      options:
        awslogs-group: /ecs/log
        awslogs-region: eu-west-1
        awslogs-stream-prefix: ...-plan-api
    ports:
      - 3058:3058
    restart: always
  ...-redis:
    image: redis:4.0.14-alpine
    logging:
      driver: awslogs
      options:
        awslogs-group: /ecs/log
        awslogs-region: eu-west-1
        awslogs-stream-prefix: ...-redis
    restart: always
version: '3'

作为一个示例“崩溃”,...-main-api服务将获得一个Error: Redis connection to localhost:6379 failed - connect ECONNREFUSED,在CloudWatch -> Logs -> Insights下可见。记录例如...-mongo-另一项服务-不可用,但仍适用于STOPPED状态。

预期:由于一个或多个其他容器停止运行,因此剩余的容器不应进入即时STOPPED状态。如果它们独立崩溃,则它们应仅进入STOPPED状态。

当前:所有容器显然都停止了。

1 个答案:

答案 0 :(得分:0)

您可以尝试在任务定义中将名为user.id的参数设置为guild.id,应该这样做。

Task Definition Parameters

  

基本

     

类型:布尔值

     

必填:否

     

如果容器的基本参数标记为true,并且该容器由于任何原因失败或停止,则作为任务一部分的所有其他容器也将停止。如果将容器的基本参数标记为false,则其失败不会影响任务中其余的容器。如果省略此参数,则假定容器是必不可少的。

     

所有任务必须至少具有一个基本容器。如果您的应用程序由多个容器组成,则应将用于通用目的的容器分组为组件,然后将不同的组件分为多个任务定义。有关更多信息,请参见应用程序体系结构。

     

“基本”:true | false