def main(tpls):
    """main."""
    main_tpl = tpls[0]
    main_name = os.path.basename(main_tpl).replace('.conf.tpl', '')
    pid_file = os.path.join(TMP_DIR, main_name + '.pid')
    port_name = main_name + '-rpc'

    # first, check if it's already running
    if is_running("supervisor", pid_file, port_name):
        print("Supervisor [%s] already running" % main_name)
        sys.exit(0)

    print("Starting supervisor [%s]" % main_name)

    # get port
    inet_http_server_port, = local.allocate_ports(1)
    local.register_local_port(port_name, inet_http_server_port)

    conf_file_path = write_conf(main_tpl, inet_http_server_port)
    for tpl in tpls[1:]:
        write_conf(tpl, inet_http_server_port)

    os.chdir(ROOT_DIR)
    try:
        os.mkdir(os.path.join(TMP_DIR, main_name + '-childlog'))
    except OSError:
        pass

    os_exec(".env/bin/supervisord", "-c", conf_file_path)
def main(tpls):
    """main."""
    main_tpl = tpls[0]
    main_name = os.path.basename(main_tpl).replace('.conf.tpl', '')
    pid_file = os.path.join(TMP_DIR, main_name + '.pid')
    port_name = main_name + '-rpc'

    # first, check if it's already running
    if is_running("supervisor", pid_file, port_name):
        print "Supervisor [%s] already running" % main_name
        sys.exit(0)

    print "Starting supervisor [%s]" % main_name

    # get port
    inet_http_server_port, = local.allocate_ports(1)
    local.register_local_port(port_name, inet_http_server_port)

    conf_file_path = write_conf(main_tpl, inet_http_server_port)
    for tpl in tpls[1:]:
        write_conf(tpl, inet_http_server_port)

    os.chdir(ROOT_DIR)
    try:
        os.mkdir(os.path.join(TMP_DIR, main_name + '-childlog'))
    except OSError:
        pass

    os_exec("/usr/bin/supervisord", "-c", conf_file_path)
Ejemplo n.º 3
0
def start():
    """Start Postgres."""
    sock_dir = '/dev/shm/pg_magicicada'
    data_dir = os.path.join(sock_dir, "data")
    pidfile = os.path.join(data_dir, "postmaster.pid")

    if is_running("postgres", pidfile, "postgres"):
        print "Postgres already up & running."
        return 0

    pg_bin = None
    for path in ("/usr/lib/postgresql/9.1/bin",):
        if os.path.isdir(path):
            pg_bin = path
            break

    if pg_bin is None:
        print "Cannot find valid parent for PGBINDIR"
        return 1

    pg_port = local.allocate_ports(1)[0]
    local.register_local_port("postgres", pg_port)
    os_exec(os.path.join(pg_bin, "postgres"),
            "-D", data_dir,
            "-k", sock_dir,
            "-i", "-h", "127.0.0.1",
            "-p", str(pg_port))
Ejemplo n.º 4
0
def start():
    """Start Postgres."""
    sock_dir = os.path.join(get_tmpdir(), "db1")
    data_dir = os.path.join(sock_dir, "data")
    pidfile = os.path.join(data_dir, "postmaster.pid")

    if is_running("postgres", pidfile, "postgres"):
        print "Postgres already up & running."
        return 0

    pg_bin = None
    for path in ("/usr/lib/postgresql/9.1/bin", "/usr/lib/postgresql/8.4/bin"):
        if os.path.isdir(path):
            pg_bin = path
            break

    if pg_bin is None:
        print "Cannot find valid parent for PGBINDIR"
        return 1

    pg_port = local.allocate_ports(1)[0]
    local.register_local_port("postgres", pg_port)
    os_exec(os.path.join(pg_bin, "postgres"), "-D", data_dir, "-k", sock_dir,
            "-i", "-h", "127.0.0.1", "-p", str(pg_port))