示例#1
0
文件: tlnb.py 项目: yurtaev/NewsBlur
def main(role="app", role2="dev", command=None, path=None):
    streams = list()
    if not path:
        path = "/srv/newsblur/logs/newsblur.log"
    if not command:
        command = "tail -f"

    fabfile.do(split=True)
    hosts = fabfile.env.roledefs

    for hostname in set(hosts[role] + hosts[role2]):
        if ':' in hostname:
            hostname, address = hostname.split(':', 1)
        elif isinstance(hostname, tuple):
            hostname, address = hostname[0], hostname[1]
        else:
            address = hostname
        if any(h in hostname for h in IGNORE_HOSTS): continue
        if 'ec2' in hostname:
            s = subprocess.Popen([
                "ssh", "-i",
                os.path.expanduser("~/.ec2/sclay.pem"), address,
                "%s %s" % (command, path)
            ],
                                 stdout=subprocess.PIPE)
        else:
            s = subprocess.Popen(
                ["ssh", address, "%s %s" % (command, path)],
                stdout=subprocess.PIPE)
        s.name = hostname
        streams.append(s)

    try:
        while True:
            r, _, _ = select.select(
                [stream.stdout.fileno() for stream in streams], [], [])
            for fileno in r:
                for stream in streams:
                    if stream.stdout.fileno() != fileno:
                        continue
                    data = os.read(fileno, 4096)
                    if not data:
                        streams.remove(stream)
                        break
                    combination_message = "[%-6s] %s" % (stream.name[:6], data)
                    sys.stdout.write(combination_message)
                    break
    except KeyboardInterrupt:
        print " --- End of Logging ---"
示例#2
0
def create_streams_for_roles(role, role2, command=None, path=None):
    streams = list()
    hosts = fabfile.do(split=True)
    found = set()

    if not path:
        path = "/srv/newsblur/logs/newsblur.log"
    if not command:
        command = "tail -f"

    for hostname in (hosts[role] + hosts[role2]):
        if isinstance(hostname, dict):
            address = hostname['address']
            hostname = hostname['name']
        elif ':' in hostname:
            hostname, address = hostname.split(':', 1)
        elif isinstance(hostname, tuple):
            hostname, address = hostname[0], hostname[1]
        else:
            address = hostname
        if any(h in hostname for h in IGNORE_HOSTS): continue
        if hostname in found: continue
        if 'ec2' in hostname:
            s = subprocess.Popen(["ssh", "-i", os.path.expanduser("~/.ec2/sclay.pem"), 
                                  address, "%s %s" % (command, path)], stdout=subprocess.PIPE)
        else:
            s = subprocess.Popen(["ssh", address, "%s %s" % (command, path)], stdout=subprocess.PIPE)
        s.name = hostname
        streams.append(s)
        found.add(hostname)
        
    return streams
示例#3
0
def main(role="app", role2="dev", command=None, path=None):
    streams = list()
    if not path:
        path = "/srv/newsblur/logs/newsblur.log"
    if not command:
        command = "tail -f"

    fabfile.do(split=True)
    hosts = fabfile.env.roledefs

    for hostname in set(hosts[role] + hosts[role2]):
        if ':' in hostname:
            hostname, address = hostname.split(':', 1)
        elif isinstance(hostname, tuple):
            hostname, address = hostname[0], hostname[1]
        else:
            address = hostname
        if any(h in hostname for h in IGNORE_HOSTS): continue
        if 'ec2' in hostname:
            s = subprocess.Popen(["ssh", "-i", os.path.expanduser("~/.ec2/sclay.pem"), 
                                  address, "%s %s" % (command, path)], stdout=subprocess.PIPE)
        else:
            s = subprocess.Popen(["ssh", address, "%s %s" % (command, path)], stdout=subprocess.PIPE)
        s.name = hostname
        streams.append(s)

    try:
        while True:
            r, _, _ = select.select(
                [stream.stdout.fileno() for stream in streams], [], [])
            for fileno in r:
                for stream in streams:
                    if stream.stdout.fileno() != fileno:
                        continue
                    data = os.read(fileno, 4096)
                    if not data:
                        streams.remove(stream)
                        break
                    combination_message = "[%-6s] %s" % (stream.name[:6], data)
                    sys.stdout.write(combination_message)
                    break
    except KeyboardInterrupt:
        print " --- End of Logging ---"
示例#4
0
文件: zgrep.py 项目: ischma/NewsBlur
def create_streams_for_roles(role, role2, command=None, path=None):
    streams = list()
    hosts = fabfile.do(split=True)
    found = set()

    if not path:
        path = "/srv/newsblur/logs/newsblur.log"
    if not command:
        command = "tail -f"
    for hostname in hosts[role] + hosts[role2]:
        if isinstance(hostname, dict):
            address = hostname["address"]
            hostname = hostname["name"]
        elif ":" in hostname:
            hostname, address = hostname.split(":", 1)
        elif isinstance(hostname, tuple):
            hostname, address = hostname[0], hostname[1]
        else:
            address = hostname
        if any(h in hostname for h in IGNORE_HOSTS):
            continue
        if hostname in found:
            continue
        if "ec2" in hostname:
            s = subprocess.Popen(
                [
                    "ssh",
                    "-i",
                    os.path.expanduser(os.path.join(fabfile.env.SECRETS_PATH, "keys/ec2.pem")),
                    address,
                    "%s %s" % (command, path),
                ],
                stdout=subprocess.PIPE,
            )
        else:
            s = subprocess.Popen(
                [
                    "ssh",
                    "-l",
                    NEWSBLUR_USERNAME,
                    "-i",
                    os.path.expanduser(os.path.join(fabfile.env.SECRETS_PATH, "keys/newsblur.key")),
                    address,
                    "%s %s" % (command, path),
                ],
                stdout=subprocess.PIPE,
            )
        s.name = hostname
        streams.append(s)
        found.add(hostname)

    return streams
示例#5
0
def create_streams_for_roles(role, role2, command=None, path=None):
    streams = list()
    hosts = fabfile.do(split=True)
    found = set()

    if not path:
        path = "/srv/newsblur/logs/newsblur.log"
    if not command:
        command = "tail -f"
    for hostname in (hosts[role] + hosts[role2]):
        if isinstance(hostname, dict):
            address = hostname['address']
            hostname = hostname['name']
        elif ':' in hostname:
            hostname, address = hostname.split(':', 1)
        elif isinstance(hostname, tuple):
            hostname, address = hostname[0], hostname[1]
        else:
            address = hostname
        if any(h in hostname for h in IGNORE_HOSTS): continue
        if hostname in found: continue
        if 'ec2' in hostname:
            s = subprocess.Popen([
                "ssh", "-i",
                os.path.expanduser(
                    os.path.join(fabfile.env.SECRETS_PATH, "keys/ec2.pem")),
                address,
                "%s %s" % (command, path)
            ],
                                 stdout=subprocess.PIPE)
        else:
            s = subprocess.Popen([
                "ssh", "-l", NEWSBLUR_USERNAME, "-i",
                os.path.expanduser(
                    os.path.join(fabfile.env.SECRETS_PATH,
                                 "keys/newsblur.key")), address,
                "%s %s" % (command, path)
            ],
                                 stdout=subprocess.PIPE)
        s.name = hostname
        streams.append(s)
        found.add(hostname)

    return streams
示例#6
0
def create_streams_for_roles(role, role2, command=None, path=None):
    streams = list()
    hosts = fabfile.do(split=True)
    found = set()

    if not path:
        path = "/srv/newsblur/logs/newsblur.log"
    if not command:
        command = "tail -f"
    if role in hosts:
        for hostname in (hosts[role] + hosts[role2]):
            if any(h in hostname for h in IGNORE_HOSTS) and role != 'push': continue
            follow_host(streams, found, hostname, command, path)
    else:
        host = role
        role = re.search(r'([^0-9]+)', host).group()
        for hostname in hosts[role]:
            if hostname['name'] == host:
                follow_host(streams, found, hostname, command, path)

    return streams
示例#7
0
def create_streams_for_roles(role, role2, command=None, path=None):
    streams = list()
    hosts = fabfile.do(split=True)
    found = set()

    if not path:
        path = "/srv/newsblur/logs/newsblur.log"
    if not command:
        command = "tail -f"
    if role in hosts:
        for hostname in (hosts[role] + hosts[role2]):
            if any(h in hostname for h in IGNORE_HOSTS) and role != 'push':
                continue
            follow_host(streams, found, hostname, command, path)
    else:
        host = role
        role = re.search(r'([^0-9]+)', host).group()
        for hostname in hosts[role]:
            if hostname['name'] == host:
                follow_host(streams, found, hostname, command, path)

    return streams