diff options
Diffstat (limited to 'hostsdns/event-watcher.py')
-rwxr-xr-x | hostsdns/event-watcher.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/hostsdns/event-watcher.py b/hostsdns/event-watcher.py index b51ec76..3446777 100755 --- a/hostsdns/event-watcher.py +++ b/hostsdns/event-watcher.py @@ -1,16 +1,19 @@ #!/usr/bin/env python -import os -import sys +import os, sys, json, re import docker -import json -import re +import argparse -if os.path.exists("/.dockerenv"): +parser = argparse.ArgumentParser( description="Manage host entries for docker containers") +parser.add_argument('-n', '--native', help='run service on docker host', action='store_true' , dest='NATIVE_MODE') +parser.add_argument('-o','-1', '--once', help='run once and exit (no continuous polling)', action='store_true', dest='ONCE_MODE') +args = parser.parse_args() + +if not args.NATIVE_MODE and os.path.exists("/.dockerenv"): print "Found /.dockerenv... reading from /tmp/hosts" HOSTS_FILE="/tmp/hosts" else: - print "No /.dockerenv found... reading from /etc/hosts" + print "Running in native mode... reading from /etc/hosts" HOSTS_FILE="/etc/hosts" if os.environ.get("DOCKER_HOST"): @@ -93,6 +96,9 @@ def container_remove(name): for container in client.containers.list(): container_add(container.name) +if args.ONCE_MODE: + sys.exit(0) + # calling events will basically poll forever, so after this we're # essentially in not-quite-a-daemon mode for event_json in client.events(): |