Skip to content
Browse files

Moving to a single hosts and hosts.yml file, used to control logs, de…

…ployment, firewalls, and communication. Awesome!
  • Loading branch information...
1 parent f6e5f04 commit a4238d20b3903b3ec193664dedac908ba8b8966a @samuelclay committed
Showing with 77 additions and 6 deletions.
  1. +14 −6 fabfile.py
  2. +57 −0 utils/tlnb.py
  3. +6 −0 utils/tlnbt.py
View
20 fabfile.py
@@ -38,8 +38,20 @@
# =========
env.user = 'sclay'
-hosts_path = os.path.expanduser(os.path.join(env.SECRETS_PATH, 'configs/hosts.yml'))
-env.roledefs = yaml.load(open(hosts_path))
+try:
+ hosts_path = os.path.expanduser(os.path.join(env.SECRETS_PATH, 'configs/hosts.yml'))
+ roles = yaml.load(open(hosts_path))
+ for role_name, hosts in roles.items():
+ if isinstance(hosts, dict):
+ roles[role_name] = [hosts[h][0] for h in hosts]
+ env.roledefs = roles
+except:
+ print " ***> No role definitions found in %s. Using default roles." % hosts_path
+ env.roledefs = {
+ 'app' : ['app01.newsblur.com'],
+ 'db' : ['db01.newsblur.com'],
+ 'task' : ['task01.newsblur.com'],
+ }
# ================
# = Environments =
@@ -58,10 +70,6 @@ def dev():
server()
env.roles = ['dev']
-def web():
- server()
- env.roles = ['web']
-
def db():
server()
env.roles = ['db']
View
57 utils/tlnb.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+
+import os
+import re
+import select
+import subprocess
+import sys
+import yaml
+
+
+IGNORE_HOSTS = [
+ 'push',
+]
+
+def main(role="app", role2="app"):
+ streams = list()
+ path = "/srv/newsblur/logs/newsblur.log"
+ hosts_path = os.path.expanduser(os.path.join('../secrets-newsblur/configs/hosts.yml'))
+ hosts = yaml.load(open(hosts_path))
+ for r in [role, role2]:
+ if isinstance(hosts[r], dict):
+ hosts[r] = ["%s:%s" % (hosts[r][k][-1], k) for k in hosts[r].keys()]
+
+ for hostname in set(hosts[role] + hosts[role2]):
+ if any(h in hostname for h in IGNORE_HOSTS): continue
+ if ':' in hostname:
+ hostname, address = hostname.split(':', 1)
+ else:
+ address = hostname
+ if 'ec2' in hostname:
+ s = subprocess.Popen(["ssh", "-i", os.path.expanduser("~/.ec2/sclay.pem"),
+ address, "tail -f " + path], stdout=subprocess.PIPE)
+ else:
+ s = subprocess.Popen(["ssh", address, "tail -f " + 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 ---"
+
+if __name__ == "__main__":
+ main()
View
6 utils/tlnbt.py
@@ -0,0 +1,6 @@
+#!/usr/bin/env python
+
+import tlnb
+
+if __name__ == "__main__":
+ tlnb.main(role="task", role2="ec2task")

0 comments on commit a4238d2

Please sign in to comment.
Something went wrong with that request. Please try again.