def command(): """ Require the git command-line tool. Example:: from fabric.api import run from fabtools import require require.git.command() run('git --help') """ from fabtools.require.deb import package as require_deb_package from fabtools.require.pkg import package as require_pkg_package from fabtools.require.rpm import package as require_rpm_package from fabtools.require.portage import package as require_portage_package from fabtools.system import distrib_family res = run('git --version', quiet=True) if res.failed: family = distrib_family() if family == 'debian': require_deb_package('git-core') elif family == 'redhat': require_rpm_package('git') elif family == 'sun': require_pkg_package('scmgit-base') elif family == 'gentoo': require_portage_package('dev-vcs/git') else: raise NotImplementedError()
def command(): """ Require the ``bzr`` command-line tool. Example:: from fabric.api import run from fabtools import require require.bazaar.command() run('bzr --help') """ from fabtools.require.deb import package as require_deb_package from fabtools.require.rpm import package as require_rpm_package from fabtools.require.portage import package as require_portage_package from fabtools.system import distrib_family res = run('bzr --version', quiet=True) if res.failed: family = distrib_family() if family == 'debian': require_deb_package('bzr') elif family == 'gentoo': require_portage_package('bzr') elif family == 'redhat': require_rpm_package('bzr') else: raise UnsupportedFamily(supported=['debian', 'redhat', 'gentoo'])
def setuptools(version=MIN_SETUPTOOLS_VERSION, python_cmd='python'): """ Require `setuptools`_ to be installed. If setuptools is not installed, or if a version older than *version* is installed, the latest version will be installed. .. _setuptools: http://pythonhosted.org/setuptools/ """ from fabtools.require.deb import package as require_deb_package from fabtools.require.rpm import package as require_rpm_package if not is_setuptools_installed(python_cmd=python_cmd): family = distrib_family() if family == 'debian': require_deb_package('python-dev') elif family == 'redhat': require_rpm_package('python-devel') elif family == 'arch': pass # ArchLinux installs header with base package else: raise UnsupportedFamily(supported=['debian', 'redhat', 'arch']) install_setuptools(python_cmd=python_cmd)
def setuptools(version=MIN_SETUPTOOLS_VERSION, python_cmd='python'): """ Require `setuptools`_ to be installed. If setuptools is not installed, or if a version older than *version* is installed, the latest version will be installed. .. _setuptools: http://pythonhosted.org/setuptools/ """ from fabtools.require.deb import package as require_deb_package from fabtools.require.rpm import package as require_rpm_package if not is_setuptools_installed(python_cmd=python_cmd): family = distrib_family() if family == 'debian': require_deb_package('python-dev') elif family == 'redhat': require_rpm_package('python-devel') elif family == 'arch': pass # ArchLinux installs header with base package else: raise UnsupportedFamily(supported=['debian', 'redhat']) install_setuptools(python_cmd=python_cmd)
def command(): """ Require the curl command-line tool. Example:: from fabric.api import run from fabtools import require require.curl.command() run('curl --help') """ from fabtools.require.deb import package as require_deb_package from fabtools.require.rpm import package as require_rpm_package family = distrib_family() if family == 'debian': require_deb_package('curl') elif family == 'redhat': require_rpm_package('curl') else: raise UnsupportedFamily(supported=['debian', 'redhat'])
def core(): """ Require the docker core installation. Example:: from fabtools import require require.docker.core() """ from fabtools.require.deb import package as require_deb_package from fabtools.require.rpm import package as require_rpm_package family = distrib_family() # Check if sudo command exists if not files.exists('/usr/bin/sudo'): raise Exception( "Please install the sudo package and execute adduser %s sudo" % env.user) if not files.exists('/usr/bin/docker'): if family == 'debian': require_deb_package('curl') elif family == 'redhat': require_rpm_package('curl') else: raise UnsupportedFamily(supported=['debian', 'redhat']) # Download docker installation run_as_root('curl -sSL https://get.docker.com/ | sh')
def command(): """ Require the ``hg`` command-line tool. Example:: from fabric.api import run from fabtools import require require.mercurial.command() run('hg --help') """ from fabtools.require.deb import package as require_deb_package from fabtools.require.rpm import package as require_rpm_package from fabtools.require.portage import package as require_portage_package res = run('hg --version', quiet=True) if res.failed: family = distrib_family() if family == 'debian': require_deb_package('mercurial') elif family == 'gentoo': require_portage_package('mercurial') elif family == 'redhat': require_rpm_package('mercurial') else: raise UnsupportedFamily(supported=['debian', 'redhat', 'gentoo'])
def core(): """ Require the docker core installation. Example:: from fabtools import require require.docker.core() """ from fabtools.require.deb import package as require_deb_package from fabtools.require.rpm import package as require_rpm_package family = distrib_family() # Check if sudo command exists if not files.exists('/usr/bin/sudo'): raise Exception("Please install the sudo package and execute adduser %s sudo" % env.user) if not files.exists('/usr/bin/docker'): if family == 'debian': require_deb_package('curl') elif family == 'redhat': require_rpm_package('curl') else: raise UnsupportedFamily(supported=['debian', 'redhat']) # Download docker installation run_as_root('curl -sSL https://get.docker.com/ | sh')
def command(): """ Require the curl command-line tool. Example:: from fabric.api import run from fabtools import require require.curl.command() run('curl --help') """ from fabtools.require.deb import package as require_deb_package from fabtools.require.rpm import package as require_rpm_package from fabtools.require.arch import package as require_arch_package family = distrib_family() if family == 'debian': require_deb_package('curl') elif family == 'redhat': require_rpm_package('curl') elif family == 'arch': require_arch_package('curl') else: raise UnsupportedFamily(supported=['arch', 'debian', 'redhat'])
def test_install_debian_package_in_guest_context_manager(container): from fabtools.deb import update_index from fabtools.openvz import guest from fabtools.require.deb import package as require_deb_package with guest(container): update_index() require_deb_package("htop") assert is_file("/usr/bin/htop")
def _server_debian(version): from fabtools.require.deb import package as require_deb_package if version: pkg_name = 'postgresql-%s' % version else: pkg_name = 'postgresql' require_deb_package(pkg_name)
def _server_debian(version): from fabtools.require.deb import package as require_deb_package if version: pkg_name = "postgresql-%s" % version else: pkg_name = "postgresql" require_deb_package(pkg_name) started(_service_name(version))
def firewall(zones=None, interfaces=None, policy=None, rules=None, routestopped=None, masq=None): """ Ensure that a firewall is configured. Example:: from fabtools.shorewall import * from fabtools import require # We need a firewall with some custom rules require.shorewall.firewall( rules=[ Ping(), SSH(), HTTP(), HTTPS(), SMTP(), rule(port=1234, source=hosts(['example.com'])), ] ) """ family = distrib_family() if family != 'debian': raise UnsupportedFamily(supported=['debian']) require_deb_package('shorewall') with watch(CONFIG_FILES) as config: _zone_config(zones) _interfaces_config(interfaces) _policy_config(policy) _rules_config(rules) _routestopped_config(routestopped) _masq_config(masq) if config.changed: puts("Shorewall configuration changed") if is_started(): restart('shorewall') with settings(hide('running'), shell_env()): sed('/etc/default/shorewall', 'startup=0', 'startup=1', use_sudo=True)
def firewall(zones=None, interfaces=None, policy=None, rules=None, routestopped=None, masq=None): """ Ensure that a firewall is configured. Example:: from fabtools.shorewall import * from fabtools import require # We need a firewall with some custom rules require.shorewall.firewall( rules=[ Ping(), SSH(), HTTP(), HTTPS(), SMTP(), rule(port=1234, source=hosts(['example.com'])), ] ) """ family = distrib_family() if family != "debian": raise UnsupportedFamily(supported=["debian"]) require_deb_package("shorewall") with watch(CONFIG_FILES) as config: _zone_config(zones) _interfaces_config(interfaces) _policy_config(policy) _rules_config(rules) _routestopped_config(routestopped) _masq_config(masq) if config.changed: puts("Shorewall configuration changed") if is_started(): restart("shorewall") with settings(hide("running"), shell_env()): sed("/etc/default/shorewall", "startup=0", "startup=1", use_sudo=True)
def _server_debian(version, password): from fabtools.deb import is_installed, preseed_package from fabtools.require.deb import package as require_deb_package if version: pkg_name = 'mysql-server-%s' % version else: pkg_name = 'mysql-server' if not is_installed(pkg_name): if password is None: password = prompt('Please enter password for MySQL user "root":') with settings(hide('running')): preseed_package('mysql-server', { 'mysql-server/root_password': ('password', password), 'mysql-server/root_password_again': ('password', password), }) require_deb_package(pkg_name) started('mysql')
def server(package_name='nginx'): """ Require the nginx web server to be installed and running. You can override the system package name, if you need to install a specific variant such as `nginx-extras` or `nginx-light`. :: from fabtools import require require.nginx.server() """ family = distrib_family() if family == 'debian': require_deb_package(package_name) elif family == 'redhat': require_rpm_package(package_name) elif distrib_id() is 'Archlinux': require_arch_package(package_name) require_started('nginx')
def _server_debian(version, password): from fabtools.deb import is_installed, preseed_package from fabtools.require.deb import package as require_deb_package if version: pkg_name = 'mysql-server-%s' % version else: pkg_name = 'mysql-server' if not is_installed(pkg_name): if password is None: password = prompt('Please enter password for MySQL user "root":') with settings(hide('running')): preseed_package( 'mysql-server', { 'mysql-server/root_password': ('password', password), 'mysql-server/root_password_again': ('password', password), }) require_deb_package(pkg_name) started('mysql')
def _server_debian(): from fabtools.require.deb import package as require_deb_package require_deb_package('apache2') require_started('apache2')
def _server_debian(package_name): from fabtools.require.deb import package as require_deb_package require_deb_package(package_name) require_started('nginx')
def process(name, **kwargs): """ Require a supervisor process to be running. Keyword arguments will be used to build the program configuration file. Some useful arguments are: - ``command``: complete command including arguments (**required**) - ``directory``: absolute path to the working directory - ``user``: run the process as this user - ``stdout_logfile``: absolute path to the log file You should refer to the `supervisor documentation`_ for the complete list of allowed arguments. .. note:: the default values for the following arguments differs from the ``supervisor`` defaults: - ``autorestart``: defaults to ``true`` - ``redirect_stderr``: defaults to ``true`` Example:: from fabtools import require require.supervisor.process('myapp', command='/path/to/venv/bin/myapp --config production.ini --someflag', directory='/path/to/working/dir', user='******', stdout_logfile='/path/to/logs/myapp.log', ) .. _supervisor documentation: http://supervisord.org/configuration.html#program-x-section-values """ from fabtools.require import file as require_file from fabtools.require.deb import package as require_deb_package from fabtools.require.rpm import package as require_rpm_package from fabtools.require.arch import package as require_arch_package from fabtools.require.service import started as require_started family = distrib_family() if family == 'debian': require_deb_package('supervisor') require_started('supervisor') elif family == 'redhat': require_rpm_package('supervisor') require_started('supervisord') elif family == 'arch': require_arch_package('supervisor') require_started('supervisord') else: raise UnsupportedFamily(supported=['debian', 'redhat', 'arch']) # Set default parameters params = {} params.update(kwargs) params.setdefault('autorestart', 'true') params.setdefault('redirect_stderr', 'true') # Build config file from parameters lines = [] lines.append('[program:%(name)s]' % locals()) for key, value in sorted(params.items()): lines.append("%s=%s" % (key, value)) # Upload config file if family == 'debian': filename = '/etc/supervisor/conf.d/%(name)s.conf' % locals() elif family == 'redhat': filename = '/etc/supervisord.d/%(name)s.ini' % locals() elif family == 'arch': filename = '/etc/supervisor.d/%(name)s.ini' % locals() with watch(filename, callback=update_config, use_sudo=True): require_file(filename, contents='\n'.join(lines), use_sudo=True) # Start the process if needed if process_status(name) == 'STOPPED': start_process(name)