Example #1
0
    def render(self, procfile, options, environment, concurrency):
        commands = []
        port = options.port
        for name, cmd in procfile.commands.items():
            for num in compat.xrange(0, concurrency[name]):
                full_name_parts = [options.app, name]
                env = environment.copy()
                if concurrency[name] > 1:
                    env['PORT'] = str(port + num)
                    full_name_parts.append(str(num))
                else:
                    env['PORT'] = str(port)
                commands.append((
                    name,
                    cmd,
                    '-'.join(full_name_parts),
                    num,
                    [(key, '"%s"' % pipes.quote(value)) for key, value in env.items()]  # quote env values
                ))
            port += 100

        context = {
            'app':         options.app,
            'app_root':    options.app_root,
            'log':         options.log,
            'port':        options.port,
            'user':        options.user,
            'shell':       options.shell,
            'commands':    commands,
            'concurrency': concurrency
        }
        filename = "{0}.conf".format(options.app)
        content = self.get_template("supervisord.conf").render(context)
        return [(filename, content)]
Example #2
0
    def start(self, options):
        "Start the application (or a specific PROCESS)"
        self.set_env(self.read_env(options))
        procfile = self.make_procfile(options.procfile)

        port = int(os.environ.get('PORT', options.port))
        concurrency = self.parse_concurrency(options.concurrency)
        quiet = self.parse_quiet(options.quiet)


        if options.process is not None:
            try:
                commands = {options.process: procfile.commands[options.process]}
            except KeyError:
                raise CommandError("Process type '{0}' does not exist in Procfile".format(options.process))
        else:
            commands = procfile.commands

        for name, cmd in compat.iteritems(commands):
            for i in compat.xrange(concurrency[name]):
                n = '{name}.{num}'.format(name=name, num=i + 1)
                os.environ['PORT'] = str(port + i)
                process_manager.add_process(n, cmd, quiet=(name in quiet))
            port += 100

        sys.exit(process_manager.loop())
Example #3
0
    def render(self, procfile, options, environment, concurrency):
        commands = []
        port = options.port
        for name, cmd in procfile.commands.items():
            for num in compat.xrange(1, concurrency[name] + 1):
                full_name_parts = [options.app, name]
                env = environment.copy()
                if concurrency[name] > 1:
                    env['PORT'] = str(port + num)
                    full_name_parts.append(str(num))
                else:
                    env['PORT'] = str(port)
                commands.append((
                    name,
                    cmd,
                    '-'.join(full_name_parts),
                    num,
                    [(key, '"%s"' % pipes.quote(value)) for key, value in env.items()]  # quote env values
                ))
            port += 100

        context = {
            'app':         options.app,
            'app_root':    options.app_root,
            'log':         options.log,
            'port':        options.port,
            'user':        options.user,
            'shell':       options.shell,
            'commands':    commands,
            'concurrency': concurrency
        }
        filename = "{0}.conf".format(options.app)
        content = self.get_template("supervisord.conf").render(context)
        return [(filename, content)]
Example #4
0
    def render(self, procfile, options, environment, concurrency):
        files = []

        context = {
            'app': options.app,
            'app_root': options.app_root,
            'environment': environment,
            'log': options.log,
            'port': options.port,
            'user': options.user,
            'shell': options.shell
        }

        for name, cmd in procfile.commands.iteritems():
            ctx = context.copy()
            ctx.update({'command': cmd, 'name': name})

            master = "{0}-{1}.conf".format(options.app, name)
            master_content = self.get_template("process_master.conf").render(
                ctx)
            files.append((master, master_content))

            for num in compat.xrange(1, concurrency[name] + 1):
                ctx.update({'num': num})
                process = "{0}-{1}-{2}.conf".format(options.app, name, num)
                process_content = self.get_template("process.conf").render(ctx)
                files.append((process, process_content))

        app = "{0}.conf".format(options.app)
        app_content = self.get_template("master.conf").render(context)

        files.append((app, app_content))

        return files
Example #5
0
    def render(self, procfile, options, environment, concurrency):
        files = []

        context = {
            'app':         options.app,
            'app_root':    options.app_root,
            'environment': environment,
            'log':         options.log,
            'port':        options.port,
            'user':        options.user,
            'shell':       options.shell
        }

        for name, cmd in procfile.commands.iteritems():
            ctx = context.copy()
            ctx.update({'command': cmd,
                        'name':    name})

            master = "{0}-{1}.conf".format(options.app, name)
            master_content = self.get_template("process_master.conf").render(ctx)
            files.append((master, master_content))

            for num in compat.xrange(1, concurrency[name] + 1):
                ctx.update({'num': num})
                process = "{0}-{1}-{2}.conf".format(options.app, name, num)
                process_content = self.get_template("process.conf").render(ctx)
                files.append((process, process_content))

        app = "{0}.conf".format(options.app)
        app_content = self.get_template("master.conf").render(context)

        files.append((app, app_content))

        return files
Example #6
0
    def start(self, options):
        "Start the application (or a specific PROCESS)"
        self.set_env(self.read_env(options))
        procfile = self.make_procfile(options.procfile)

        port = int(os.environ.get('PORT', options.port))
        concurrency = self.parse_concurrency(options.concurrency)
        quiet = self.parse_quiet(options.quiet)


        processes = options.processes

        if len(processes) > 0:
            commands = {}
            for process in processes:
                try:
                    commands[process] = procfile.commands[process]
                except KeyError:
                    raise CommandError("Process type '{0}' does not exist in Procfile".format(process))
        else:
            commands = procfile.commands

        for name, cmd in compat.iteritems(commands):
            for i in compat.xrange(concurrency[name]):
                n = '{name}.{num}'.format(name=name, num=i + 1)
                os.environ['PORT'] = str(port + i)
                process_manager.add_process(n, cmd, quiet=(name in quiet))
            port += 100

        sys.exit(process_manager.loop())
Example #7
0
def command_start(args):
    procfile_path = _procfile_path(args.app_root, args.procfile)
    procfile = _procfile(procfile_path)
    os.environ.update(_read_env(procfile_path, args.env))

    port = int(os.environ.get('PORT', args.port))
    concurrency = _parse_concurrency(args.concurrency)
    quiet = _parse_quiet(args.quiet)

    processes = args.processes

    if len(processes) > 0:
        commands = {}
        for process in processes:
            try:
                commands[process] = procfile.commands[process]
            except KeyError:
                raise CommandError("Process type '{0}' does not exist in Procfile".format(process))
    else:
        commands = procfile.commands

    for name, cmd in compat.iteritems(commands):
        for i in compat.xrange(concurrency[name]):
            n = '{name}.{num}'.format(name=name, num=i + 1)
            os.environ['PORT'] = str(port + i)
            process_manager.add_process(n, cmd, quiet=(name in quiet))
        port += 100

    sys.exit(process_manager.loop())
Example #8
0
def command_start(args):
    procfile_path = _procfile_path(args.app_root, args.procfile)
    procfile = _procfile(procfile_path)
    os.environ.update(_read_env(procfile_path, args.env))

    port = int(os.environ.get('PORT', args.port))
    concurrency = _parse_concurrency(args.concurrency)
    quiet = _parse_quiet(args.quiet)

    processes = args.processes

    if len(processes) > 0:
        commands = {}
        for process in processes:
            try:
                commands[process] = procfile.commands[process]
            except KeyError:
                raise CommandError(
                    "Process type '{0}' does not exist in Procfile".format(
                        process))
    else:
        commands = procfile.commands

    for name, cmd in compat.iteritems(commands):
        for i in compat.xrange(concurrency[name]):
            n = '{name}.{num}'.format(name=name, num=i + 1)
            os.environ['PORT'] = str(port + i)
            process_manager.add_process(n, cmd, quiet=(name in quiet))
        port += 100

    sys.exit(process_manager.loop())
Example #9
0
def test_get_colours():
    gen = colour.get_colours()

    expect = ['cyan', 'yellow', 'green', 'magenta', 'red', 'blue']
    expect = [getattr(colour, x) for x in expect]
    actual = [next(gen) for _ in compat.xrange(6)]

    assert expect == actual
def test_supervisord_concurrency():
    procfile = get_procfile("Procfile.simple")
    render = get_render(procfile, DEFAULT_OPTIONS, DEFAULT_ENV, {"foo": 4})

    assert_equal(1, len(render))
    (fname, contents), = render

    parser = compat.ConfigParser()
    parser.readfp(compat.StringIO(contents))

    for job_index in compat.xrange(4):
        section = "program:app-foo-{0}".format(job_index)
        assert_true(parser.has_section(section))
        assert_equal('PORT="{0}"'.format(DEFAULT_OPTIONS.port + job_index),
                     parser.get(section, "environment"))

    assert_equal(parser.get("group:app", "programs"),
                 ",".join("app-foo-{0}".format(i) for i in compat.xrange(4)))