Ejemplo n.º 1
0
    def start_container(ctx, container_root, manifest):
        """Treadmill container boot process.
        """
        _LOGGER.info('Initializing container: %s', container_root)
        app = app_manifest.read(manifest)

        cgroup = ctx.obj.get('CGROUP')
        try:
            # if cgroups set, we need to remount cgroup path
            # so that from cgroup directory we only see container pids
            # <container_root>/sys/fs/cgroup/memory =>
            #   /sys/fs/cgroup/memory/treadmill/apps/<app-inst-unique>/services
            if cgroup:
                remount_cgroup(container_root, cgroup, ctx.obj['ROOT_CGROUP'])

            pivot_root.make_root(container_root)
            os.chdir('/')
        except Exception as err:  # pylint: disable=broad-except
            event = traceevents.AbortedTraceEvent(
                instanceid=app['name'],
                why=app_abort.AbortedReason.PIVOT_ROOT.value,
                payload=str(err),
            )

            _abort(event, container_root)

            # reraise err to exit start_container
            raise err

        # XXX: Debug info
        _LOGGER.debug('Current mounts: %s',
                      pprint.pformat(fs_linux.list_mounts()))

        subproc.safe_exec(['/services/{}'.format(supervisor.SVC_INIT_FILE)])
Ejemplo n.º 2
0
    def start_container(container_root, manifest):
        """Treadmill container boot process.
        """
        _LOGGER.info('Initializing container: %s', container_root)
        app = app_manifest.read(manifest)

        try:
            pivot_root.make_root(container_root)
            os.chdir('/')
        except Exception as err:  # pylint: disable=broad-except
            event = traceevents.AbortedTraceEvent(
                instanceid=app['name'],
                why=app_abort.AbortedReason.PIVOT_ROOT.value,
                payload=str(err),
            )

            _abort(event, container_root)

            # reraise err to exit start_container
            raise err

        # XXX: Debug info
        _LOGGER.debug('Current mounts: %s',
                      pprint.pformat(fs_linux.list_mounts()))

        # Clean the environ
        # TODO: Remove me once clean environment management is merged in.
        os.environ.pop('PYTHONPATH', None)
        os.environ.pop('LC_ALL', None)
        os.environ.pop('LANG', None)

        # Clear aliases path.
        os.environ.pop('TREADMILL_ALIASES_PATH', None)

        subproc.safe_exec(['s6_svscan', '-s', '/services'])
Ejemplo n.º 3
0
    def start_container(container_root):
        """Treadmill container boot process.
        """
        _LOGGER.info('Initializing container: %s', container_root)

        # We only preserve anything mounted on the container root.
        fs_linux.cleanup_mounts([container_root + '*'], ignore_exc=True)
        # Mount a proc in the new namespaces
        fs_linux.mount_procfs(container_root)
        # remount current proc to /proc
        # new process entering container namespace can see the correct /proc
        fs_linux.mount_procfs('/')

        # Chroot into the container
        os.chroot(container_root)
        os.chdir('/')

        # XXX: Debug info
        _LOGGER.debug('Current mounts: %s',
                      pprint.pformat(fs_linux.list_mounts()))

        # Clean the environ
        # TODO: Remove me once clean environment management is merged in.
        del os.environ['PYTHONPATH']
        del os.environ['LC_ALL']
        del os.environ['LANG']

        subproc.safe_exec(['s6_svscan', '-s', '/services'])
Ejemplo n.º 4
0
def read_mounted_cgroups(filter_by=CGROOT):
    """Read all the currently mounted cgroups and their mount points.

    :params ``str`` filter_by:
        Filter out cgroups mounted outside of this path. Set the None/'' to
        obtain all mountpoints.
    :returns:
        ``dict`` - Map of cgroup subsystems to their mountpoints list.
    """
    availables = _available_subsystems()

    mounts = fs_linux.list_mounts()

    subsys2mnt = {}
    for mount_entry in mounts:
        if mount_entry.fs_type != 'cgroup':
            continue

        for opt in mount_entry.mnt_opts:
            if opt in availables:
                if not filter_by or mount_entry.target.startswith(filter_by):
                    subsys2mnt.setdefault(opt, []).append(mount_entry.target)

    return subsys2mnt