def mysql_install(): """ Installs mysql. """ if _mysql_is_installed(): puts('Mysql is already installed.') return passwd = _get_root_password() # this way mysql won't ask for a password on installation # see http://serverfault.com/questions/19367/scripted-install-of-mysql-on-ubuntu os = utils.detect_os() system.aptitude_install('debconf-utils') mysql_versions = {'lenny': '5.0', 'squeeze': '5.1', 'maverick': '5.1'} version = mysql_versions[os] debconf_defaults = [ "mysql-server-%s mysql-server/root_password_again password %s" % (version, passwd), "mysql-server-%s mysql-server/root_password password %s" % (version, passwd), ] sudo("echo '%s' | debconf-set-selections" % "\n".join(debconf_defaults)) warn('\n=========\nThe password for mysql "root" user will be set to "%s"\n=========\n' % passwd) system.aptitude_install('mysql-server')
def full_deploy(): """ Prepares server and deploys the project. """ os = utils.detect_os() if not console.confirm("Is the OS detected correctly (%s)?" % os, default=False): abort("Detection fails. Please set env.conf.OS to correct value.") system.prepare_server() deploy_project()
def install_common_software(): """ Installs common system packages. """ common_packages = [ 'python', 'build-essential', 'python-dev', 'python-setuptools', 'python-profiler', 'libjpeg-dev', 'zlib1g-dev', 'libssl-dev', 'libcurl3-dev', 'libxml2-dev', 'libxslt1-dev', # for lxml 'screen', 'locales-all', 'curl', 'memcached', 'subversion', ] extra_packages = { 'lenny': ['libmysqlclient15-dev'], 'squeeze': ['libmysqlclient-dev'], 'maverick': ['libmysqlclient-dev'], } os = utils.detect_os() if os not in extra_packages: fabric_utils.abort('Your OS (%s) is unsupported now.' % os) aptitude_install(" ".join(common_packages + extra_packages[os])) # git and mercurial are outdated in stable Debian Lenny and # don't work with some source repositories on github and bitbucket vcs_options = {'lenny': '-t lenny-backports'} aptitude_install('mercurial git', vcs_options.get(os, "")) aptitude_install('bzr', '--without-recommends') sudo('easy_install -U pip') sudo('pip install -U virtualenv')
def mysql_install(): """ Installs mysql. """ if _mysql_is_installed(): puts('Mysql is already installed.') return passwd = _get_root_password() # this way mysql won't ask for a password on installation # see http://serverfault.com/questions/19367/scripted-install-of-mysql-on-ubuntu os = utils.detect_os() system.aptitude_install('debconf-utils') mysql_versions = {'lenny': '5.0', 'squeeze': '5.1', 'maverick': '5.1'} version = mysql_versions[os] debconf_defaults = [ "mysql-server-%s mysql-server/root_password_again password %s" % (version, passwd), "mysql-server-%s mysql-server/root_password password %s" % (version, passwd), ] sudo("echo '%s' | debconf-set-selections" % "\n".join(debconf_defaults)) warn( '\n=========\nThe password for mysql "root" user will be set to "%s"\n=========\n' % passwd) system.aptitude_install('mysql-server')
def prepare(): """ Prepares server: installs system packages. """ os = utils.detect_os() if os in ['lenny', 'squeeze']: install_sudo() setup_backports() install_software()
def install(self): """ Installs PostgreSQL + postgis. """ os = utils.detect_os() if os == "trusty": packages = 'gdal-bin postgresql-9.3 postgresql-9.3-postgis-2.1 postgresql-server-dev-9.3' else: packages = 'gdal-bin postgresql-8.4-postgis postgresql-server-dev-8.4' system.aptitude_install(packages)
def install(self): """ Installs postgresql. """ os = utils.detect_os() if os == "trusty": packages = 'postgresql-server-dev-9.3 postgresql-9.3' else: packages = 'postgresql-server-dev-8.4 postgresql-8.4' system.aptitude_install(packages)
def prepare_server(): """ Prepares server: installs system packages. """ os = utils.detect_os() if os in ['lenny', 'squeeze']: install_sudo() setup_backports() install_common_software()
def nginx_install(): """ Install nginx. """ if _nginx_is_installed(): fabric.api.warn(fabric.colors.yellow('Nginx is already installed')) return os = detect_os() options = {'lenny': '-t lenny-backports'} fabric.api.sudo('add-apt-repository ppa:nginx/stable') package_update() package_install(['nginx','libxml2','libxml2-dev'], options.get(os,''))
def nginx_install(): """ Install nginx. """ if _nginx_is_installed(): fabric.api.warn(fabric.colors.yellow('Nginx is already installed')) return os = detect_os() options = {'lenny': '-t lenny-backports'} fabric.api.sudo('add-apt-repository ppa:nginx/stable') package_update() package_install(['nginx', 'libxml2', 'libxml2-dev'], options.get(os, ''))
def setup_testing_sources(): """ Adds testing yandex repo to apt sources. """ os = utils.detect_os() debian_repo = "http://mirror.yandex.ru" testing = {"squeeze": "{0}/debian-backports squeeze-backports main".format(debian_repo)} if os not in testing: fabric_utils.puts("Testing sources are not available for " + os) return sudo("echo 'deb %s' > /etc/apt/sources.list.d/backports.list" % testing[os]) with settings(warn_only=True): run("aptitude update")
def mysql_install(): """ Installs MySQL """ if _mysql_is_installed(): fabric.api.warn(fabric.colors.yellow('MySQL is already installed.')) return # Ensure mysql won't ask for a password on installation # See the following: # http://serverfault.com/questions/19367/scripted-install-of-mysql-on-ubuntu # http://www.muhuk.com/2010/05/how-to-install-mysql-with-fabric/ os = detect_os() package_install('debconf-utils') # get the password if 'DB_PASSWD' in fabric.api.env.conf: passwd = fabric.api.env.conf['DB_PASSWD'] else: passwd = fabric.api.prompt('Please enter MySQL root password:'******'lenny': '5.0', 'sqeeze': '5.1', 'lucid': '5.1', 'maverick': '5.1', } version = mysql_versions[os] debconf_defaults = [ "mysql-server-%s mysql-server/root_password password %s" % (version,passwd), "mysql-server-%s mysql-server/root_password_again password %s" % (version,passwd), ] fabric.api.sudo("echo '%s' | debconf-set-selections" % "\n".join(debconf_defaults)) fabric.api.warn(fabric.colors.yellow('The password for mysql "root" user will be set to "%s"' % passwd)) common_packages = [ 'automysqlbackup', 'sendmail', 'mysql-server-%s' % version, 'python-mysqldb', ] extra_packages = { 'lenny' : ['libmysqlclient15-dev',], 'sqeeze' : ['libmysqlclient-dev',], 'lucid' : ['libmysqlclient-dev',], 'maverick': ['libmysqlclient-dev',], } package_install(common_packages + extra_packages[os], "--no-install-recommends")
def setup_backports(): """ Adds backports repo to apt sources. """ os = detect_os() backports = { "lenny": "http://backports.debian.org/debian-backports lenny-backports main contrib non-free", "squeeze": "http://backports.debian.org/debian-backports squeeze-backports main contrib non-free", "lucid": "http://archive.ubuntu.com/ubuntu lucid-backports main universe multiverse restricted", "maverick": "http://archive.ubuntu.com/ubuntu maverick-backports main universe multiverse restricted", } if os in backports: fabric.api.puts(fabric.colors.green("Installing available backports for %s" % os)) return fabric.api.run("echo 'deb %s' > /etc/apt/sources.list.d/backports.sources.list" % backports[os])
def setup_backports(): """ Adds backports repo to apt sources. """ os = utils.detect_os() backports = { 'lenny': 'http://backports.debian.org/debian-backports lenny-backports main contrib non-free', 'squeeze': 'http://backports.debian.org/debian-backports squeeze-backports main contrib non-free', } if os not in backports: fabric_utils.puts("Backports are not available for " + os) return sudo("echo 'deb %s' > /etc/apt/sources.list.d/backports.sources.list" % backports[os]) with settings(warn_only=True): sudo('aptitude update')
def prepare_server(): """ Prepares server: installs system packages. """ os = utils.detect_os() if os in ["lenny", "squeeze"]: system.install_sudo() system.setup_backports() setup_testing_sources() mysql.mysql_install() with settings(hide("warnings", "running", "stdout", "stderr"), warn_only=True): mysql.mysql_create_db() system.install_common_software() redis.redis_install() redis.redis_setup()
def prepare_server(): """ Prepares server: installs system packages. """ os = utils.detect_os() if os in ['lenny', 'squeeze']: system.install_sudo() system.setup_backports() setup_testing_sources() mysql.mysql_install() with settings(hide('warnings', 'running', 'stdout', 'stderr'), warn_only=True): mysql.mysql_create_db() system.install_common_software() redis.redis_install() redis.redis_setup()
def setup_testing_sources(): """ Adds testing yandex repo to apt sources. """ os = utils.detect_os() debian_repo = 'http://mirror.yandex.ru' testing = { 'squeeze': '{0}/debian-backports squeeze-backports main'.format(debian_repo), } if os not in testing: fabric_utils.puts("Testing sources are not available for " + os) return sudo("echo 'deb %s' > /etc/apt/sources.list.d/backports.list" % testing[os]) with settings(warn_only=True): run('aptitude update')
def java_install(): """ Install Sun Java6 Currently it is recommended you do these on the server directly. Fabric has trouble with the prompts that you must answer during installation. """ if _java_is_installed(): fabric.api.warn(fabric.colors.yellow('Sun Java6 JDK is already installed')) return if detect_os() == 'maverick': fabric.api.sudo('add-apt-repository "deb http://archive.canonical.com/ lucid partner"') package_update() package_install(['sun-java6-jdk','sun-java6-jre',])
def setup_backports(): """ Adds backports repo to apt sources. """ os = utils.detect_os() backports = { 'lenny': 'http://backports.debian.org/debian-backports lenny-backports main contrib non-free', 'squeeze': 'http://backports.debian.org/debian-backports squeeze-backports main contrib non-free', 'maverick': 'http://archive.ubuntu.com/ubuntu maverick-backports main universe multiverse restricted', 'lucid': 'http://archive.ubuntu.com/ubuntu lucid-backports main universe multiverse restricted', } if os not in backports: fabric_utils.puts("Backports are not available for " + os) return sudo("echo 'deb %s' > /etc/apt/sources.list.d/backports.sources.list" % backports[os]) with settings(warn_only=True): sudo('aptitude update') env.conf._APTITUDE_UPDATED = True
def mysql_install(): """ Installs MySQL """ if _mysql_is_installed(): fabric.api.warn(fabric.colors.yellow("MySQL is already installed.")) return # Ensure mysql won't ask for a password on installation # See the following: # http://serverfault.com/questions/19367/scripted-install-of-mysql-on-ubuntu # http://www.muhuk.com/2010/05/how-to-install-mysql-with-fabric/ os = detect_os() package_install("debconf-utils") # get the password if "DB_PASSWD" in fabric.api.env.conf: passwd = fabric.api.env.conf["DB_PASSWD"] else: passwd = fabric.api.prompt("Please enter MySQL root password:"******"lenny": "5.0", "sqeeze": "5.1", "lucid": "5.1", "maverick": "5.1", "natty": "5.1"} version = mysql_versions[os] debconf_defaults = [ "mysql-server-%s mysql-server/root_password password %s" % (version, passwd), "mysql-server-%s mysql-server/root_password_again password %s" % (version, passwd), ] fabric.api.sudo("echo '%s' | debconf-set-selections" % "\n".join(debconf_defaults)) fabric.api.warn(fabric.colors.yellow('The password for mysql "root" user will be set to "%s"' % passwd)) common_packages = ["automysqlbackup", "sendmail", "mysql-server-%s" % version, "python-mysqldb"] extra_packages = { "lenny": ["libmysqlclient15-dev"], "sqeeze": ["libmysqlclient-dev"], "lucid": ["libmysqlclient-dev"], "maverick": ["libmysqlclient-dev"], "natty": ["libmysqlclient-dev"], } package_install(common_packages + extra_packages[os], "--no-install-recommends")
def setup_backports(): """ Adds backports repo to apt sources. """ os = detect_os() backports = { 'lenny': 'http://backports.debian.org/debian-backports lenny-backports main contrib non-free', 'squeeze': 'http://backports.debian.org/debian-backports squeeze-backports main contrib non-free', 'lucid': 'http://archive.ubuntu.com/ubuntu lucid-backports main universe multiverse restricted', 'maverick': 'http://archive.ubuntu.com/ubuntu maverick-backports main universe multiverse restricted', } if os in backports: fabric.api.puts( fabric.colors.green("Installing available backports for %s" % os)) return fabric.api.run( "echo 'deb %s' > /etc/apt/sources.list.d/backports.sources.list" % backports[os])
def nginx_install(): """ Installs nginx. """ os = utils.detect_os() options = {'lenny': '-t lenny-backports'} system.aptitude_install('nginx', options.get(os, '')) sudo('rm -f /etc/nginx/sites-enabled/default')
def redis_install(): """ Installs Redis """ os = utils.detect_os() options = {'squeeze': '-t squeeze-backports'} system.aptitude_install('redis-server', options.get(os, ''))
def detect_os(cls): os_name = detect_os() os_class = OS.registry.get(os_name, OS) os = os_class() fab.env.os = os
def imagemagick_install(): """ Installs Image Magick """ os = utils.detect_os() options = {'squeeze': '-t squeeze-backports'} system.aptitude_install('imagemagick', options.get(os, ''))