def docker(cls, service, params): """ Consul Docker Check SERVICE_CHECK_DOCKER=curl --silent --fail example.com """ # https://github.com/cablehead/python-consul/blob/53eb41c4760b983aec878ef73e72c11e0af501bb/consul/base.py#L111 # https://www.consul.io/docs/discovery/checks#docker-interval # # NOTE: consul agent should be able to access docker socket: -v /var/run/docker.sock:/var/run/docker.sock script = cls._value(params, 'docker') if script: # Invoke *script* packaged within a running docker container with # *container_id* at a specified *interval* on the configured # *shell* using the Docker Exec API. Optional *register* after which a # failing service will be automatically deregistered. script = script.replace('$SERVICE_IP', service.ip).replace( '$SERVICE_PORT', str(service.port)) container_id = service.container_id[:12] shell = cls._value(params, 'shell') interval, deregister = cls._common_values(params) ret = Check.docker(container_id, shell, script, interval, deregister=deregister) # FIXME: as 2021/01/24, python-consul2 uses old script instead of args # it was removed in consul 1.1.0 # https://github.com/hashicorp/consul/blob/master/CHANGELOG.md#110-may-11-2018 if cls.consul_version >= (1, 1, 0): ret['args'] = script.split(" ") del ret['script'] return cls._post_process(ret, params) return None