Guest User

Untitled

a guest
Jun 18th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. from fabric.api import *
  2.  
  3.  
  4. APTITUDE_CACHE = set()
  5. PIP_CACHE = set()
  6. EASY_INSTALL_CACHE = set()
  7.  
  8. def aptitude(package):
  9. aptitude_update()
  10. if package not in APTITUDE_CACHE:
  11. APTITUDE_CACHE.add(package)
  12. return sudo("aptitude -y install %s" % package)
  13.  
  14. @runs_once
  15. def aptitude_update():
  16. sudo("aptitude update")
  17.  
  18. def easy_install(package):
  19. aptitude("python-setuptools")
  20. if package not in EASY_INSTALL_CACHE:
  21. EASY_INSTALL_CACHE.add(package)
  22. sudo("easy_install %s" % package)
  23.  
  24. def pip(package):
  25. easy_install("pip")
  26. if package not in PIP_CACHE:
  27. PIP_CACHE.add(package)
  28. return sudo("pip install %s" % package)
  29.  
  30. def base():
  31. aptitude("emacs")
  32. aptitude("python-dev")
  33. aptitude("libjpeg-dev")
  34. aptitude("zlib1g-dev")
  35. aptitude("PIL")
  36. pip("virtualenv")
  37. aptitude("python-psycopg2")
  38.  
  39. def nginx():
  40. base()
  41. aptitude("nginx")
  42.  
  43. def apache():
  44. base()
  45. aptitude("apache2")
  46. aptitude("libapache2-mod-wsgi")
  47.  
  48. def celery():
  49. base()
  50.  
  51. def postgres():
  52. aptitude("emacs")
  53. aptitude("postgresql")
  54. password = prompt("Choose a new postgres root passord: ")
  55. sudo("psql -d template1 -c \"ALTER USER postgres with encrypted password '%s'\"" % password, user="postgres")
  56. #chanage pg_hba.conf (first line in perms): 'local all postgres md5 sameuser'
  57. sudo("/etc/init.d/postgresql-8.4 restart")
  58.  
  59. def rabbitmq():
  60. aptitude("rabbitmq-server")
  61.  
  62. def mq_setup():
  63. user = prompt("Enter rabbitMQ user: ")
  64. password = prompt("Enter rabbitMQ password: ")
  65. vhost = prompt("Enter rabbitMQ virtual host: ")
  66. sudo("rabbitmqctl add_user %s %s" % (user, password))
  67. sudo("rabbitmqctl add_vhost %s" % vhost)
  68. sudo("rabbitmqctl set_permissions -p %s %s \"\" \".*\" \".*\"" % (vhost, user))
  69.  
  70. import os
  71. def file_insert_after_line(filename, search_line, insert_line, path=None):
  72. """
  73. Insert a line after the search_line
  74. matches search line with starts_with
  75.  
  76. not great, but first iter works
  77. @@ change search_line to RE
  78. @@ if search_line not found, raise exception
  79. """
  80. if path is not None:
  81. filename = ''.join([path, filename])
  82.  
  83. tmp = filename + "~"
  84. with open(tmp, 'w') as outfile:
  85. with open(filename, 'r') as infile:
  86. rows = iter(infile)
  87. for row in rows:
  88. if row.startswith(search_line):
  89. break
  90. outfile.write(row)
  91. outfile.write(row)
  92. outfile.write(insert_line + "\n")
  93. for row in rows:
  94. outfile.write(row)
  95.  
  96. # @@ do i really have to do this again?
  97. with open(filename, 'w') as outfile:
  98. with open(tmp, 'r') as infile:
  99. rows = iter(infile)
  100. for row in rows:
  101. outfile.write(row)
  102.  
  103. os.remove(tmp)
  104.  
  105. def add_sudo():
  106. """
  107. promting user/pass for now, decide if we hard code, read from
  108. file, etc
  109. """
  110. user = prompt("Please enter a user: ")
  111. passwd = prompt("Please enter a password: ")
  112. run("useradd %s -d /home/%s -p %s" % user, user, password)
  113. file_insert_line('sudoers', '# User privilege specification', '%s ALL=(ALL) ALL' % user)
  114.  
  115. def build_egg():
  116. local("python setup.py bdist_egg")
  117. put("dist/XXXX_XXXX.egg", "/remote/path/to/deploy")
  118.  
  119. def create_repo(repo):
  120. with cd("/var/repo"):
  121. run("mkdir %s" % repo)
  122. with cd("%s" % repo):
  123. run("hg init .")
  124. sudo("find . -exec chown %s:devs {} \;" % env.user)
  125. sudo("find . -exec chmod g+s {} \;")
  126. sudo("find . -exec chmod g+w {} \;")
  127.  
  128. def create_project(repo):
  129. create_repo(repo)
  130. local("hg clone ssh://%s@%s//repo/%s" % (env.user, env.host_string, repo))
  131.  
  132. def tail(file):
  133. sudo("tail -f %s" % file)
  134.  
  135. def reboot():
  136. sudo("reboot")
Add Comment
Please, Sign In to add comment