mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-04-13 09:42:01 +00:00
Auto-naming new app/task servers based on existing servers.
This commit is contained in:
parent
88a099a357
commit
93fdab24da
4 changed files with 36 additions and 2 deletions
|
@ -47,8 +47,10 @@ alias cd..='cd ..'
|
|||
|
||||
alias smtp='python -m smtpd -n -c DebuggingServer 127.0.0.1:1025'
|
||||
alias tlnb='echo "----------------\n"; tail -f logs/newsblur.log'
|
||||
alias sshnb='ssh sclay@app10.newsblur.com'
|
||||
alias sp='~/newsblur/manage.py shell_plus --use-pythonrc'
|
||||
alias cdsg='cd ~/staging'
|
||||
alias cdnb='cd ~/newsblur'
|
||||
alias sshdo=/srv/newsblur/utils/ssh.sh
|
||||
|
||||
cd ~/newsblur
|
18
fabfile.py
vendored
18
fabfile.py
vendored
|
@ -58,6 +58,7 @@ def do_roledefs(*roledefs):
|
|||
droplets = doapi.show_active_droplets()
|
||||
for roledef in roledefs:
|
||||
env.roledefs[roledef] = [droplet.ip_address for droplet in droplets if roledef in droplet.name]
|
||||
return droplets
|
||||
|
||||
# ================
|
||||
# = Environments =
|
||||
|
@ -1010,6 +1011,7 @@ def setup_do(name, size=2):
|
|||
region_id = doapi.regions()[0].id
|
||||
images = dict((s.name, s.id) for s in doapi.images())
|
||||
image_id = images[IMAGE_NAME]
|
||||
name = do_name(name)
|
||||
instance = doapi.create_droplet(name=name,
|
||||
size_id=size_id,
|
||||
image_id=image_id,
|
||||
|
@ -1040,6 +1042,22 @@ def setup_do(name, size=2):
|
|||
time.sleep(10)
|
||||
add_user_to_do()
|
||||
|
||||
def do_name(name):
|
||||
if re.search(r"[0-9]", name):
|
||||
print " ---> Using %s as hostname" % name
|
||||
return name
|
||||
else:
|
||||
hosts = do_roledefs()
|
||||
hostnames = [host.name for host in hosts]
|
||||
existing_hosts = [hostname for hostname in hostnames if name in hostname]
|
||||
for i in range(10, 50):
|
||||
try_host = "%s%02d" % (name, i)
|
||||
if try_host not in existing_hosts:
|
||||
print " ---> %s hosts in %s (%s). %s is unused." % (len(existing_hosts), name,
|
||||
', '.join(existing_hosts), try_host)
|
||||
return try_host
|
||||
|
||||
|
||||
def add_user_to_do():
|
||||
env.user = "root"
|
||||
repo_user = "sclay"
|
||||
|
|
|
@ -3,7 +3,7 @@ import os
|
|||
import dop.client
|
||||
from django.conf import settings
|
||||
|
||||
sys.path.append(os.getcwd())
|
||||
sys.path.append('/srv/newsblur')
|
||||
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
|
||||
|
||||
|
|
|
@ -5,7 +5,12 @@ import select
|
|||
import subprocess
|
||||
import sys
|
||||
import yaml
|
||||
import dop.client
|
||||
from django.conf import settings
|
||||
|
||||
sys.path.append('/srv/newsblur')
|
||||
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
|
||||
|
||||
IGNORE_HOSTS = [
|
||||
'push',
|
||||
|
@ -17,12 +22,21 @@ def main(role="app", role2="dev", command=None, path=None):
|
|||
path = "/srv/newsblur/logs/newsblur.log"
|
||||
if not command:
|
||||
command = "tail -f"
|
||||
|
||||
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 r not in hosts:
|
||||
hosts[r] = []
|
||||
if isinstance(hosts[r], dict):
|
||||
hosts[r] = ["%s:%s" % (hosts[r][k][-1], k) for k in hosts[r].keys()]
|
||||
|
||||
doapi = dop.client.Client(settings.DO_CLIENT_KEY, settings.DO_API_KEY)
|
||||
droplets = doapi.show_active_droplets()
|
||||
for droplet in droplets:
|
||||
if role in droplet.name or role2 in droplet.name:
|
||||
hosts[role].append("%s:%s" % (droplet.name, droplet.ip_address))
|
||||
|
||||
for hostname in set(hosts[role] + hosts[role2]):
|
||||
if any(h in hostname for h in IGNORE_HOSTS): continue
|
||||
|
@ -57,4 +71,4 @@ def main(role="app", role2="dev", command=None, path=None):
|
|||
print " --- End of Logging ---"
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main(*sys.argv[1:])
|
||||
|
|
Loading…
Add table
Reference in a new issue