Skip to content
This repository was archived by the owner on Dec 20, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions gantry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from actions import start_action, update_action, list_action, stop_action, kill_action
from config.GantryConfig import Configuration
from runtime.manager import RuntimeManager
from util import report, fail
from util import report, fail, connectDockerClient


ACTIONS = {
Expand Down Expand Up @@ -58,13 +58,18 @@ def run():
parser.add_argument('component_name', help='The name of the component to manage')
parser.add_argument('-m', dest='monitor', action='store_true', help='If specified and the action is "start" or "update", gantry will remain running to monitor components, auto restarting them as necessary')
parser.add_argument('--setconfig', dest='config_overrides', action='append', help='Configuration overrides for the component')
parser.add_argument('-H', '--host', dest='docker_url', default='unix://var/run/docker.sock', help='Set url for docker host, defaults to unix://var/run/docker.sock')

args = parser.parse_args()
component_name = args.component_name
action = args.action
should_monitor = args.monitor
config_file = args.config_file
config_overrides = args.config_overrides
docker_url = args.docker_url

# Connect to docker
connectDockerClient(docker_url)

# Load the config.
config = loadConfig(config_file)
Expand All @@ -78,7 +83,7 @@ def run():
component = manager.getComponent(component_name)
if not component:
raise Exception('Unknown component: ' + component_name)

# Apply the config overrides (if any).
if config_overrides:
component.applyConfigOverrides(config_overrides)
Expand All @@ -102,4 +107,4 @@ def cleanup_monitor(signum, frame):
cleanup_monitor(None, None)

if __name__ == "__main__":
run()
run()
5 changes: 5 additions & 0 deletions gantryd.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,15 @@ def start():
parser.add_argument('-c', help='A component to watch and run', nargs='+', type=str, dest='component')
parser.add_argument('-etcd', help='The etcd endpoint to which the client should connect. Defaults to 127.0.0.1', dest='etcd_host', nargs='?', const=ETCD_HOST)
parser.add_argument('-etcdport', help='The client port of the etcd endpoint. Defaults to 4001.', dest='etcd_port', nargs='?', const=ETCD_PORT)
parser.add_argument('-H', '--host', dest='docker_url', default='unix://var/run/docker.sock', help='Set url for docker host, defaults to unix://var/run/docker.sock')

# Parse the arguments.
args = parser.parse_args()
port = int(args.etcd_port) if args.etcd_port else ETCD_PORT
docker_url = args.docker_url

# Connect to docker
connectDockerClient(docker_url)

# Initialize the gantryd client.
dclient = GantryDClient(args.etcd_host or ETCD_HOST, args.project, port)
Expand Down
10 changes: 8 additions & 2 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ def enum(*sequential, **named):

ReportLevels = enum(BACKGROUND=-2, EXTRA=-1, NORMAL=0, IMPORTANT=1)

client = docker.Client(version='auto')
client = None

def connectDockerClient(docker_url):
global client
client = docker.Client(base_url=docker_url, version='auto')

def pickUnusedPort():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Expand Down Expand Up @@ -47,4 +51,6 @@ def fail(reason, project=None, component=None, exception=None):

def getDockerClient():
""" Returns the docker client. """
return client
if client is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a TODO to have this all moved into a class, as a global is a bit hacky

connectDockerClient('unix://var/run/docker.sock')
return client