コード例 #1
0
ファイル: network.py プロジェクト: classp-io/datacats
def wait_for_service_available(container, url, timeout):
    """
    Wait up to timeout seconds for service at host:port
    to start.

    Returns True if service becomes available, False if the
    container stops or raises ServiceTimeout if timeout is
    reached.
    """
    start = time.time()
    remaining = timeout
    while True:
        remaining = start + timeout - time.time()
        if remaining < 0:
            raise ServiceTimeout
        try:
            response = get(url,
                timeout=min(remaining, REQUEST_TIMEOUT_SECONDS))
            if 500 <= response.status_code < 600:
                return False
            return True
        except (ConnectionError, Timeout):
            pass
        if not inspect_container(container)['State']['Running']:
            return False

        remaining = start + timeout - time.time()
        delay = max(0, min(RETRY_DELAY_SECONDS, remaining))
        time.sleep(delay)

    raise ServiceTimeout
コード例 #2
0
def wait_for_service_available(container, url, timeout):
    """
    Wait up to timeout seconds for service at host:port
    to start.

    Returns True if service becomes available, False if the
    container stops or raises ServiceTimeout if timeout is
    reached.
    """
    start = time.time()
    remaining = timeout
    while True:
        remaining = start + timeout - time.time()
        if remaining < 0:
            raise ServiceTimeout
        try:
            response = get(url,
                           timeout=min(remaining, REQUEST_TIMEOUT_SECONDS))
            if 500 <= response.status_code < 600:
                return False
            return True
        except (ConnectionError, Timeout):
            pass
        if not inspect_container(container)['State']['Running']:
            return False

        remaining = start + timeout - time.time()
        delay = max(0, min(RETRY_DELAY_SECONDS, remaining))
        time.sleep(delay)

    raise ServiceTimeout
コード例 #3
0
ファイル: migrate.py プロジェクト: zoek1/datacats
def _two_to_one(datadir):
    """After this command, your environment will be converted to format version {}
and will not work with Datacats versions beyond and including 1.0.0.
This format version doesn't support multiple sites, and after this only your
"primary" site will be usable, though other sites will be maintained if you
wish to do a migration back to a version which supports multisite.

Would you like to continue the migration? (y/n) [n]:"""
    _, env_name = _split_path(datadir)

    print 'Making sure that containers are stopped...'
    # New-style names
    remove_container('datacats_web_{}_primary'.format(env_name))
    remove_container('datacats_postgres_{}_primary'.format(env_name))
    remove_container('datacats_solr_{}_primary'.format(env_name))

    print 'Doing conversion...'

    if exists(path_join(datadir, '.version')):
        os.remove(path_join(datadir, '.version'))

    to_move = (['files', 'passwords.ini', 'run', 'solr'] +
               (['postgres'] if not is_boot2docker() else []))

    web_command(
        command=['/scripts/migrate.sh',
                 '/project/data/sites/primary',
                 '/project/data'] + to_move,
        ro={scripts.get_script_path('migrate.sh'): '/scripts/migrate.sh'},
        rw={datadir: '/project/data'}
    )

    pgdata_name = 'datacats_pgdata_{}_primary'.format(env_name)
    if is_boot2docker() and inspect_container(pgdata_name):
        rename_container(pgdata_name, 'datacats_pgdata_{}'.format(env_name))

    print 'Doing cleanup...'
    with open(path_join(datadir, 'project-dir')) as pd:
        datacats_env_location = path_join(pd.read(), '.datacats-environment')

    cp = SafeConfigParser()
    cp.read(datacats_env_location)

    # We need to move the port OUT of site_primary section and INTO datacats
    cp.set('datacats', 'port', cp.get('site_primary', 'port'))
    cp.remove_section('site_primary')

    with open(datacats_env_location, 'w') as config:
        cp.write(config)

    cp = SafeConfigParser()
    cp.read(path_join(datadir, 'passwords.ini'))

    # This isn't needed in this version
    cp.remove_option('passwords', 'beaker_session_secret')

    with open(path_join(datadir, 'passwords.ini'), 'w') as config:
        cp.write(config)
コード例 #4
0
ファイル: task.py プロジェクト: dborzov/datacats
def containers_running(get_container_name):
    """
    Return a list of containers tracked by this environment that are running
    """
    running = []
    for n in ['web', 'postgres', 'solr', 'datapusher', 'redis']:
        info = docker.inspect_container(get_container_name(n))
        if info and not info['State']['Running']:
            running.append(n + '(halted)')
        elif info:
            running.append(n)
    return running
コード例 #5
0
ファイル: task.py プロジェクト: poguez/datacats
def containers_running(get_container_name):
    """
    Return a list of containers tracked by this environment that are running
    """
    running = []
    for n in ['web', 'postgres', 'solr', 'datapusher', 'redis']:
        info = docker.inspect_container(get_container_name(n))
        if info and not info['State']['Running']:
            running.append(n + '(halted)')
        elif info:
            running.append(n)
    return running
コード例 #6
0
ファイル: task.py プロジェクト: mchelen/datacats
def containers_running(get_container_name):
    """
    Return a list of containers tracked by this environment that are running
    """
    running = []
    for n in ["web", "postgres", "solr", "datapusher", "redis"]:
        info = docker.inspect_container(get_container_name(n))
        if info and not info["State"]["Running"]:
            running.append(n + "(halted)")
        elif info:
            running.append(n)
    return running
コード例 #7
0
ファイル: environment.py プロジェクト: classp-io/datacats
 def containers_running(self):
     """
     Return a list including 0 or more of ['web', 'data', 'search']
     for containers tracked by this project that are running
     """
     running = []
     for n in ['web', 'postgres', 'solr']:
         info = inspect_container('datacats_' + n + '_' + self.name)
         if info and not info['State']['Running']:
             running.append(n + '(halted)')
         elif info:
             running.append(n)
     return running
コード例 #8
0
ファイル: task.py プロジェクト: mchelen/datacats
def data_complete(datadir, sitedir, get_container_name):
    """
    Return True if the directories and containers we're expecting
    are present in datadir, sitedir and containers
    """
    if any(not path.isdir(sitedir + x) for x in ("/files", "/run", "/solr")):
        return False

    if docker.is_boot2docker():
        # Inspect returns None if the container doesn't exist.
        return all(docker.inspect_container(get_container_name(x)) for x in ("pgdata", "venv"))

    return path.isdir(datadir + "/venv") and path.isdir(sitedir + "/postgres")
コード例 #9
0
 def containers_running(self):
     """
     Return a list including 0 or more of ['web', 'data', 'search']
     for containers tracked by this project that are running
     """
     running = []
     for n in ['web', 'postgres', 'solr']:
         info = inspect_container('datacats_' + n + '_' + self.name)
         if info and not info['State']['Running']:
             running.append(n + '(halted)')
         elif info:
             running.append(n)
     return running
コード例 #10
0
 def _current_web_port(self):
     """
     return just the port number for the web container, or None if
     not running
     """
     info = inspect_container(self._get_container_name('web'))
     if info is None:
         return None
     try:
         if not info['State']['Running']:
             return None
         return info['NetworkSettings']['Ports']['5000/tcp'][0]['HostPort']
     except TypeError:
         return None
コード例 #11
0
ファイル: environment.py プロジェクト: dborzov/datacats
 def _current_web_port(self):
     """
     return just the port number for the web container, or None if
     not running
     """
     info = inspect_container(self._get_container_name('web'))
     if info is None:
         return None
     try:
         if not info['State']['Running']:
             return None
         return info['NetworkSettings']['Ports']['5000/tcp'][0]['HostPort']
     except TypeError:
         return None
コード例 #12
0
ファイル: task.py プロジェクト: poguez/datacats
def data_complete(datadir, sitedir, get_container_name):
    """
    Return True if the directories and containers we're expecting
    are present in datadir, sitedir and containers
    """
    if any(not path.isdir(sitedir + x) for x in ('/files', '/run', '/solr')):
        return False

    if docker.is_boot2docker():
        # Inspect returns None if the container doesn't exist.
        return all(
            docker.inspect_container(get_container_name(x))
            for x in ('pgdata', 'venv'))

    return path.isdir(datadir + '/venv') and path.isdir(sitedir + '/postgres')