def _create_network(name, subnet): tempfile = file.temp() try: definition = _NETWORK_TEMPLATE % dict(name=name, subnet=subnet) file.write(tempfile, definition) core.run("virsh net-define %s" % tempfile) core.run("virsh net-autostart %s" % name) finally: file.remove(tempfile)
def add_upstart(name, content): if name.endswith(".conf"): name = name[:-5] upstart_file = "/etc/init/%s.conf" % name with ctx.sudo(): with ctx.unpatched_state(): file.write(upstart_file, content)
def _install_apc(): installed = run("pecl list | grep -i apc; true") if installed: return run("yes '' | pecl install apc") bin_path = run("phpenv which php") conf_path = bin_path.replace("/bin/php", "/etc/conf.d") file.write(conf_path + "/apc.ini", "extension=apc.so")
def _store_root_cnf(password): cnf_config = """# Config generated by revolver [client] host = localhost user = root password = %s """ % password cnf_dir = "/etc/mysql/" cnf_file = cnf_dir + "root.cnf" with ctx.sudo(): file.write(cnf_file, cnf_config)
def _preseed_server(root_password): seed_config = """# Mysql preseed generated by revolver mysql-server mysql-server/root_password password %(root_password)s mysql-server mysql-server/root_password_again password %(root_password)s """ % {"root_password": root_password} seed_dir = "/var/cache/local/preseeding/" seed_file = seed_dir + "mysql-server.seed" with ctx.sudo(): dir.create(seed_dir, recursive=True) file.write(seed_file, seed_config) sudo("debconf-set-selections %s" % seed_file)
def _upload(self): # TODO Warn if there are local changes tmp_tar = git.create_archive(self.revision) try: core.put(tmp_tar, "deploy.tar.gz") core.run("tar -xzf deploy.tar.gz") file.remove("deploy.tar.gz") with ctx.unpatched_state(): file.write("VERSION", git.revparse(self.revision)) finally: core.local("rm -rf %s" % tmp_tar)
def _upload(owner, upload_dir, revision): tmp_tar = git.create_archive(revision) try: with ctx.cd(upload_dir): with ctx.sudo(): put(tmp_tar, 'deploy.tar.gz') file.attributes('deploy.tar.gz', owner=owner) with ctx.sudo(owner): run('tar -xzf deploy.tar.gz') file.remove('deploy.tar.gz') file.write('VERSION', git.revparse(revision)) finally: local('rm -rf %s' % tmp_tar)
def _store_root_cnf(password): cnf_config = """# Config generated by revolver [client] host = localhost user = root password = %s """ % password cnf_dir = "/etc/mysql/" cnf_file = cnf_dir + "root.cnf" if file.exists(cnf_file): return with ctx.sudo(): file.write(cnf_file, cnf_config) file.link(cnf_file, "/root/.my.cnf")
def install(name=_DEFAULT_NAME, subnet=_DEFAULT_SUBNET, _update=True): packages = ["lxc", "debootstrap", "libvirt-bin"] if _update: package.install(packages) else: package.ensure(packages) networks = _list_networks() if name not in networks: _create_network(name, subnet) core.run("virsh net-start %s" % name) else: if not networks[name]: core.run("virsh net-start %s" % name) with ctx.sudo(): config = _LXC_NETWORK % dict(name=name, subnet=subnet) file.write("/etc/lxc/net-lxc.conf", config, mode="a+r")
def _preseed_server(root_password): seed_config = """# Mysql preseed generated by revolver mysql-server mysql-server/root_password password %(root_password)s mysql-server mysql-server/root_password_again password %(root_password)s mysql-server mysql-server/start_on_boot boolean true """ % { "root_password": root_password } seed_dir = "/var/cache/local/preseeding/" seed_file = seed_dir + "mysql-server.seed" if file.exists(seed_file): return with ctx.sudo(): dir.create(seed_dir, recursive=True) file.write(seed_file, seed_config) sudo("debconf-set-selections %s" % seed_file)
def site_ensure(site, lines): with ctx.sudo(): with ctx.cd('/etc/nginx/sites-available/'): file.write(site, lines) site_enable(site)