def deploy(): """Add HAproxy to the <proxy> host.""" fabtools.require.deb.packages([ 'haproxy' ]) servers = [] for i, server in enumerate(env.roledefs['web']): server_s = WEB_SERVER % {'i': i, 'host': server.split('@')[-1], 'port': '80'} servers.append(server_s) fabtools.require.files.template_file( template_source = util.files('haproxy/haproxy.base'), context = {'servers': '\n'.join(servers)}, path = '/etc/haproxy/haproxy.cfg', owner = 'root', group = 'root', mode = '644', use_sudo = True) fabtools.require.files.file( source = util.files('haproxy/default'), path = '/etc/default/haproxy', owner = 'root', group = 'root', mode = '644', use_sudo = True) fabtools.require.service.restarted('haproxy')
def deploy(path=None, use_gunicorn=True): """Put a django site onto the web servers.""" if path is None: path = env.farmboy_django_app fabtools.require.python.package('django', use_sudo=True) project = os.path.basename(path) fabtools.require.directory( path = util.home('www'), owner = env.farmboy_user, group = env.farmboy_user, use_sudo = True) put(local_path = path, remote_path = util.home('www'), use_sudo = True) sudo('chown -R %s:%s /home/%s/www/%s' % (env.farmboy_user, env.farmboy_user, env.farmboy_user, project)) if use_gunicorn: fabtools.require.files.template_file( template_source = util.files('gunicorn/django'), path = '/etc/gunicorn.d/django', context = {'project': project}, owner = 'root', group = 'root', mode = '644', use_sudo = True) gunicorn.restart()
def hosts(): current_role = _current_role() hostsfile = util.files('farmboy/hosts') hosts = [] hosts.append('127.0.0.1 localhost farmboy-%s' % current_role) # TODO(termie): does this break if we use callable roledefs? for role, role_hosts in env.roledefs.iteritems(): if len(role_hosts) == 1: if role == current_role: continue hosts.append('%s farmboy-%s' % (util.host(role_hosts[0]), role)) continue for i, role_host in enumerate(role_hosts): hosts.append('%s farmboy-%s-%s' % (util.host(role_host), role, i)) hosts_str = '\n'.join(hosts) fabtools.require.files.template_file( template_source = hostsfile, context = {'hosts': hosts_str}, path = '/etc/hosts', owner = 'root', group = 'root', mode = '644', use_sudo = True)
def init(): """Locally set up basic files for using Vagrant.""" vagrantfile = util.files('vagrant/Vagrantfile') # TODO(termie): local cp or shutil? local('cp %s %s' % (vagrantfile, './Vagrantfile')) #shutil.copy(vagrantfile, './Vagrantfile') fabfile_context = {'roledefs': repr(DEFAULT_ROLEDEFS), 'keyfile': KEYFILE_S, 'preamble': '', } util.template_file('farmboy/fabfile.py', 'fabfile.py', fabfile_context)
def set_proxy(proxy=None): """Set the <apt> host as the proxy for apt on <all> hosts.""" if proxy is None: proxy = env.farmboy_apt_proxy fabtools.require.files.template_file( template_source = util.files('apt-cacher/01apt-cacher'), context = {'proxy': proxy}, path = '/etc/apt/apt.conf.d/01apt-cacher', owner = 'root', group = 'root', mode = '644', use_sudo = True)
def deploy(): """Deploy apt-cacher to the <apt> host.""" fabtools.require.deb.packages([ 'apt-cacher' ]) fabtools.require.files.file( source = util.files('apt-cacher/default'), path = '/etc/default/apt-cacher', owner = 'root', group = 'root', mode = '644', use_sudo = True) fabtools.require.files.file( source = util.files('apt-cacher/apt-cacher.conf'), path = '/etc/apt-cacher/apt-cacher.conf', owner = 'root', group = 'root', mode = '644', use_sudo = True) fabtools.require.service.restarted('apt-cacher')
def deploy(): """Add nginx to the the <web> hosts.""" fabtools.require.nginx.server() fabtools.require.file( source = util.files('nginx/web'), path = '/etc/nginx/sites-available/web', owner = 'root', group = 'root', mode = '755', use_sudo = True) fabtools.nginx.disable('default') fabtools.nginx.enable('web') fabtools.require.service.restarted('nginx')
def deploy(): """Add mysql to the db hosts.""" # If we don't have a key yet generate one and save it locally if not env.farmboy_mysql_password: new_password = _generate_password() util.update({'farmboy_mysql_password': new_password}) env.farmboy_mysql_password = new_password mysql_password = env.farmboy_mysql_password fabtools.require.mysql.server(password=mysql_password) fabtools.require.files.file( source = util.files('mysql/mysqld.cnf'), path = '/etc/mysql/conf.d/mysqld.cnf', owner = 'root', group = 'root', mode = '644', use_sudo = True) sudo('service mysql restart')