def debian_install(packages): """ Install packages for Debian packages is a string with packages' names example: 'nginx python-pip' """ deb.install(packages.split(' '))
def setup_nginx(): print_title('Installing Nginx') deb.install('nginx') server_hosts = [ env.hosts[0], "raspberrypi.local", "{}.local".format(settings.ROOT_NAME) ] server_hosts.append(socket.gethostbyname(env.host)) server_hosts = set(server_hosts) nginx_conf = ''' # the upstream component nginx needs to connect to upstream django {{ server unix:/tmp/{PROJECT_NAME}.sock; }} # configuration of the server server {{ # Block all names not in list i.e. prevent HTTP_HOST errors if ($host !~* ^({SERVER_NAMES})$) {{ return 444; }} listen 80; server_name {SERVER_NAMES}; charset utf-8; # max upload size client_max_body_size 75M; # adjust to taste # Static files #location /static {{ # alias {PROJECT_PATH}static; #}} location = /favicon.ico {{ access_log off; log_not_found off; }} # Finally, send all non-media requests to the server. location / {{ include proxy_params; proxy_pass http://unix:{SOCKET_FILES_PATH}{PROJECT_NAME}.sock; }} }}'''.format(SERVER_NAMES="|".join(server_hosts), PROJECT_NAME=settings.ROOT_NAME, PROJECT_PATH=settings.DIR_CODE, STATIC_FILES_PATH=settings.DIR_CODE, VIRTUALENV_PATH=settings.DIR_VENV, SOCKET_FILES_PATH=settings.DIR_SOCK) sites_available = "/etc/nginx/sites-available/%s" % settings.ROOT_NAME sites_enabled = "/etc/nginx/sites-enabled/%s" % settings.ROOT_NAME files.append(sites_available, nginx_conf, use_sudo=True) # Link to sites enabled if not files.exists(sites_enabled): sudo('ln -s %s %s' % (sites_available, sites_enabled)) # This removes the default configuration profile for Nginx if files.exists('/etc/nginx/sites-enabled/default'): sudo('rm -v /etc/nginx/sites-enabled/default')
def server(mailname): """ Require a Postfix email server. This makes sure that Postfix is installed and started. :: from fabtools import require # Handle incoming email for our domain require.postfix.server('example.com') """ # Ensure the package is installed if not is_installed('postfix'): preseed_package('postfix', { 'postfix/main_mailer_type': ('select', 'Internet Site'), 'postfix/mailname': ('string', mailname), 'postfix/destinations': ('string', '%s, localhost.localdomain, localhost ' % mailname), }) install('postfix') # Ensure the service is started started('postfix')
def setup_personal_server(): # deb.update_index() # deb.upgrade() deb.install([ "vim", "tmux", ])
def devel(): """ Developer tools installation """ #TODO: gitconfig deb.install(['build-essential', 'git']) require.file('/etc/gitconfig', source='files/gitconfig', use_sudo=True)
def server(mailname): """ Require a Postfix email server. This makes sure that Postfix is installed and started. :: from fabtools import require # Handle incoming email for our domain require.postfix.server('example.com') """ # Ensure the package is installed if not is_installed('postfix'): preseed_package( 'postfix', { 'postfix/main_mailer_type': ('select', 'Internet Site'), 'postfix/mailname': ('string', mailname), 'postfix/destinations': ('string', '%s, localhost.localdomain, localhost ' % mailname), }) install('postfix') # Ensure the service is started started('postfix')
def keyrings(): """ Refresh apt keys """ deb.install(['debian-keyring', 'debian-archive-keyring'], options=["-y", "--force-yes"]) sudo('apt-key update')
def install_deps(): # update apt index deb.update_index(quiet=False) # obtain the LSB codename codename = utils.deb.get_release_info().codename packages = NIX_DEPS[codename] for package, version in packages: deb.install(package, version)
def package(pkg_name, update=False): """ Require a deb package to be installed. Example:: from fabtools import require require.deb.package('foo') """ if not is_installed(pkg_name): install(pkg_name, update)
def server(mailname): """ I can haz postfix email server """ # Ensure the package is installed if not is_installed('postfix'): preseed_package('postfix', { 'postfix/main_mailer_type': ('select', 'Internet Site'), 'postfix/mailname': ('string', mailname), 'postfix/destinations': ('string', '%s, localhost.localdomain, localhost ' % mailname), }) install('postfix') # Ensure the service is started started('postfix')
def server(mailname): """ Require a Postfix email server """ # Ensure the package is installed if not is_installed('postfix'): preseed_package('postfix', { 'postfix/main_mailer_type': ('select', 'Internet Site'), 'postfix/mailname': ('string', mailname), 'postfix/destinations': ('string', '%s, localhost.localdomain, localhost ' % mailname), }) install('postfix') # Ensure the service is started started('postfix')
def packages(pkg_list, update=False): """ Require several deb packages to be installed. Example:: from fabtools import require require.deb.packages([ 'foo', 'bar', 'baz', ]) """ pkg_list = [pkg for pkg in pkg_list if not is_installed(pkg)] if pkg_list: install(pkg_list, update)
def package(pkg_name, update=False, version=None): """ Require a deb package to be installed. Example:: from fabtools import require # Require a package require.deb.package('foo') # Require a specific version require.deb.package('firefox', version='11.0+build1-0ubuntu4') """ if not is_installed(pkg_name): install(pkg_name, update=update, version=version)
def query(query, use_sudo=True, **kwargs): """ Run a MySQL query. """ family = distrib_family() if family == 'debian': from fabtools.deb import install, is_installed elif family == 'redhat': from fabtools.rpm import install, is_installed else: raise UnsupportedFamily(supported=['debian', 'redhat']) func = use_sudo and run_as_root or run user = kwargs.get('mysql_user') or env.get('mysql_user') password = kwargs.get('mysql_password') or env.get('mysql_password') func_mysql = 'mysql' mysql_host = kwargs.get('mysql_host') or env.get('mysql_host') options = [ '--batch', '--raw', '--skip-column-names', ] if user: options.append('--user=%s' % quote(user)) if password: if not is_installed('sshpass'): install('sshpass') func_mysql = 'sshpass -p %(password)s mysql' % { 'password': quote(password) } options.append('--password') if mysql_host: options.append('--host=%s' % quote(mysql_host)) options = ' '.join(options) return func('%(cmd)s %(options)s --execute=%(query)s' % { 'cmd': func_mysql, 'options': options, 'query': quote(query), })
def install_postfix(self): # def install_postfix(mailname): """ Require a Postfix email server. This makes sure that Postfix is installed and started. :: from fabtools import require # Handle incoming email for our domain require.postfix.server('example.com') """ self.get_env() self.copy_mailgate_file() # Ensure the package is installed if not is_installed('postfix'): preseed_package( 'postfix', { 'postfix/main_mailer_type': ('select', 'Internet Site'), 'postfix/mailname': ('string', self.postfix_hostname), 'postfix/destinations': ( 'string', '%s, localhost.localdomain, localhost ' % (self.postfix_hostname), ) }) install('postfix') # Update postfix conf custom_sudo("postconf -e 'virtual_alias_domains = regexp:%s'" % (self.virtual_domains_regex_path)) custom_sudo("postconf -e 'virtual_alias_maps = hash:%s'" % (self.virtual_alias_path)) # Restart postfix custom_sudo('service postfix restart') # Ensure the service is started started('postfix')
def query(query, use_sudo=True, **kwargs): """ Run a MySQL query. """ family = distrib_family() if family == 'debian': from fabtools.deb import install, is_installed elif family == 'redhat': from fabtools.rpm import install, is_installed else: raise UnsupportedFamily(supported=['debian', 'redhat']) func = use_sudo and run_as_root or run user = kwargs.get('mysql_user') or env.get('mysql_user') password = kwargs.get('mysql_password') or env.get('mysql_password') func_mysql = 'mysql' mysql_host = kwargs.get('mysql_host') or env.get('mysql_host') options = [ '--batch', '--raw', '--skip-column-names', ] if user: options.append('--user=%s' % quote(user)) if password: if not is_installed('sshpass'): install('sshpass') func_mysql = 'sshpass -p %(password)s mysql' % {'password': password} options.append('--password') options.append('--password=%s' % quote(password)) if mysql_host: options.append('--host=%s' % quote(mysql_host)) options = ' '.join(options) return func('%(cmd)s %(options)s --execute=%(query)s' % { 'cmd': func_mysql, 'options': options, 'query': quote(query), })
def install_packages(pkgs, postfix_cfg): hostname = run('hostname') destination_cfg = '%s.clld.org, %s, localhost.localdomain, localhost', \ (hostname, hostname) deb.preseed_package( 'postfix', { 'postfix/main_mailer_type': ('select', 'Internet Site'), 'postfix/mailname': ('string', hostname + '.clld.org'), 'postfix/destinations': ('string', destination_cfg), }) deb.install(pkgs) def fix_postfix_cfg(): files.sed(postfix_cfg, 'myhostname = ', 'myhostname = ' + hostname + '.gwdg.de', use_sudo=True) fix_postfix_cfg()
def setup_server(): set_language() files.sed("/etc/ssh/sshd_config", "StrictModes yes", "StrictModes no", use_sudo=True) service.restart("ssh") deb.upgrade() deb.install([ "nginx", "uwsgi", "uwsgi-plugin-python", "uwsgi-plugin-python3", "libpq-dev", "postgresql", "postgresql-contrib", "python-virtualenv", "python-dev", "python3-dev" ], update=True) # Increase domain name limit files.sed("/etc/nginx/nginx.conf", "# server_names_hash_bucket_size 64;", "server_names_hash_bucket_size 96;", use_sudo=True) nginx.disable("default")
def install_postfix(self): # def install_postfix(mailname): """ Require a Postfix email server. This makes sure that Postfix is installed and started. :: from fabtools import require # Handle incoming email for our domain require.postfix.server('example.com') """ self.get_env() self.copy_mailgate_file() # Ensure the package is installed if not is_installed('postfix'): preseed_package('postfix', { 'postfix/main_mailer_type': ('select', 'Internet Site'), 'postfix/mailname': ('string', self.postfix_hostname), 'postfix/destinations': ( 'string', '%s, localhost.localdomain, localhost ' % ( self.postfix_hostname),) }) install('postfix') # Update postfix conf custom_sudo("postconf -e 'virtual_alias_domains = regexp:%s'" % ( self.virtual_domains_regex_path)) custom_sudo("postconf -e 'virtual_alias_maps = hash:%s'" % ( self.virtual_alias_path)) # Restart postfix custom_sudo('service postfix restart') # Ensure the service is started started('postfix')
def openerp(): '''This task's goal is to install OpenERP 7 on a freshly installed Ubuntu 12.04 Precise Pangolin machine. It installs PostgreSQL and sets up a base. Then, it installs OpenERP package from the editor.''' ## Because all vagrant users does not live in the USA require.file( '/etc/apt/sources.list', contents=SOURCES_LIST_CONTENT, use_sudo=True ) ## Add OpenERP's editor debian packages repository require.deb.source( 'openerp', 'http://nightly.openerp.com/7.0/nightly/deb/', './' ) ## Installs and configure our PostgreSQL server require.postgres.server() require.postgres.user( 'openerp', password='******', createdb=True, createrole=True, login=True, connection_limit=20 ) require.postgres.database('openerp', 'openerp') ## OpenERP repository provides not signed packages, we can't use ## require.deb.package as it does not permit to force the installation ## of unsigned packages #require.deb.package('openerp') if not deb.is_installed('openerp'): deb.install('openerp', options=['--force-yes'])
def install(): """ Installs Nix""" # Install the Nix package if not deb.is_installed('nix'): execute('nix.install_deps') # obtain the LSB codename codename = utils.deb.get_release_info().codename url = NIX_BUILDS_URL.format(**NIX_BUILDS[codename]) tmp_dir = mkdtemp() with cd(tmp_dir): print(green('Downloading Nix 1.11.2')) run("wget '{}'".format(url)) print(green('Installing Nix')) sudo('dpkg --unpack *.deb') deb.install('nix') rmtree(tmp_dir) # Create Nix build user accounts grp = 'nixbld' if not group.exists(grp): group.create(grp) for n in range(10): usr = "******".format(n) if not user.exists(usr): user.create(usr, comment="Nix build user {}".format(n), group=grp, extra_groups=[grp], system=True, shell='/bin/false') sudo('mkdir -p /etc/nix') sudo('mkdir -p /nix/store') sudo('chown root.nixbld /nix/store') sudo('chmod 1775 /nix/store') sudo('mkdir -p -m 1777 /nix/var/nix/gcroots/per-user') sudo('mkdir -p -m 1777 /nix/var/nix/profiles/per-user') # Configure nix-daemon init_path = '/etc/init.d/' upload_template(os.path.join(TEMPLATES_FOLDER, 'nix-daemon'), init_path, backup=False, mode=0o755, use_sudo=True) sudo('update-rc.d nix-daemon defaults') green('Starting nix-daemon') sudo('/etc/init.d/nix-daemon start') # Setup profile nix_profile = '/etc/profile.d/nix.sh' append(nix_profile, PROFILE_SUFFIX, use_sudo=True) sudo('service nix-daemon restart') # Setup Nix for current user execute('nix.user_setup') green('Done. Remember to log out and back in before using Nix.')
def install_os_packages(): print_title('Installing OS packages') deb.install('nginx uwsgi python3-pip python3-dev python3-psycopg2')
def install_system_packages(): deb.install(env.system_packages.split(' '), update=True)