Created
December 8, 2015 19:49
-
-
Save safanaj/dc756a1f132b5f5d2dce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys | |
import os | |
import re | |
from subprocess import Popen, PIPE | |
cfg_compose_file = None | |
containers = None | |
pchilds = None | |
DOCKER_COMPOSE_CMD = '/usr/bin/docker-compose' | |
DOCKER_CMD = '/usr/bin/docker' | |
def get_composed_containsers(cfg_file): | |
out, err = Popen([DOCKER_COMPOSE_CMD, '-f', cfg_file, 'ps', '-q'], stdout=PIPE, stderr=PIPE).communicate() | |
return out.splitlines() | |
def start_docker_logs(container_id): | |
global pchilds | |
if pchilds is None: | |
pchilds = [] | |
p = Popen([DOCKER_CMD, 'logs', '-f', container_id], stdout=sys.stdout, stderr=sys.stderr, stdin=PIPE) | |
pchilds.append(p) | |
p.stdin.close() | |
if __name__ == "__main__": | |
if not os.path.exists(sys.argv[1]): | |
sys,exit(1) | |
cfg_compose_file = sys.argv[1] | |
containers = get_composed_containsers(cfg_compose_file) | |
for c_id in containers: | |
start_docker_logs(c_id) | |
pid, rc = os.wait() | |
for p in pchilds: | |
if p.poll() is None: | |
p.kill() | |
p.poll() ## just read rc | |
sys.exit(rc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment