From 5749801bd5a8ffcc175798afb7f5a118dc8301f5 Mon Sep 17 00:00:00 2001 From: Till Maas Date: Apr 16 2019 16:51:16 +0000 Subject: docker: Use is-active to determine docker status Only run `systemctl start docker` when `systemctl is-active docker` fails. The start command is privileged and therefore requires manual authentication if it is run by a non-root user even if the service is already active. The check with is-active is possible without special privileges. This allows to use the inventory file if the current user is in the docker group. --- diff --git a/inventory/standard-inventory-docker b/inventory/standard-inventory-docker index bc3371d..d4ef327 100755 --- a/inventory/standard-inventory-docker +++ b/inventory/standard-inventory-docker @@ -86,13 +86,18 @@ def inv_host(subject, docker_extra_args): raise RuntimeError("Could not parse DOCKER_EXTRA_ARGS") logger.info("Launching Docker container for {0}".format(image)) # Make sure the docker service is running - cmd = [ - "/usr/bin/systemctl", "start", "docker" - ] try: - subprocess.check_call(cmd, stdout=sys.stderr.fileno()) + subprocess.check_call(["/usr/bin/systemctl", "is-active", "--quiet", "docker"], + stdout=sys.stderr.fileno()) except subprocess.CalledProcessError: - raise RuntimeError("Could not start docker service") + try: + cmd = [ + "/usr/bin/systemctl", "start", "docker" + ] + subprocess.check_call(cmd, stdout=sys.stderr.fileno()) + except subprocess.CalledProcessError: + raise RuntimeError("Could not start docker service") + # And launch the actual container cmd = [ "/usr/bin/docker", "run", "--detach", "--cidfile={0}".format(cidfile),