示例#1
0
def install_common_packages():
    """ Installs common system packages. """
    common_packages = [
        'ack-grep',
        'build-essential',
        'curl',
        'git-core',
        'gcc',
        'ipython',
        'libcurl3-dev',
        'libjpeg-dev',
        'libssl-dev',
        'mercurial',
        'ntp',
        'psmisc',
        'python2.6',
        'python2.6-dev',
        'python-imaging',
        'python-mysqldb',
        'python-pip',
        'python-setuptools',
        'python-software-properties',
        'python-virtualenv',
        'rsync',
        'screen',
        'subversion',
        'zlib1g-dev',
    ]

    # Install common and extra packages with no recommended packages
    package_install(common_packages, "--no-install-recommends")
示例#2
0
def install_common_packages():
	""" Installs common system packages. """
	common_packages = [
		'ack-grep',
		'build-essential',
		'curl',
		'git-core',
		'gcc',
		'ipython',
		'libcurl3-dev',
		'libjpeg-dev',
		'libssl-dev',
		'mercurial',
		'ntp',
		'psmisc',
		'python2.6',
		'python2.6-dev',
		'python-dev',
		'python-imaging',
		'python-mysqldb',
		'python-pip',
		'python-setuptools',
		'python-software-properties',
		'python-virtualenv',
		'rsync',
		'screen',
		'subversion',
		'zlib1g-dev',
	]

	# Install common and extra packages with no recommended packages
	package_install(common_packages,"--no-install-recommends")
示例#3
0
def redis_install():
	""" Install redis-server. """
	if _redis_is_installed():
		fabric.api.warn(fabric.colors.yellow('Redis-server is already installed'))
		return

	package_install(['redis-server'])
示例#4
0
def save_as_ami(name, arch='i386'):
    config = get_provider_dict()
    # Copy pk and cert to /tmp, somehow
    fabric.api.put(fabric.api.env.conf['AWS_X509_PRIVATE_KEY'], '/tmp/pk.pem')
    fabric.api.put(fabric.api.env.conf['AWS_X509_CERTIFICATE'],
                   '/tmp/cert.pem')

    fabric.contrib.files.sed('/etc/apt/sources.list',
                             'universe$',
                             'universe multiverse',
                             use_sudo=True)
    package_update()
    package_install('ec2-ami-tools', 'ec2-api-tools')

    fabric.api.sudo(
        'ec2-bundle-vol -c /tmp/cert.pem -k /tmp/pk.pem -u %s -s 10240 -r %s' %
        (fabric.api.env.conf['AWS_ID'], arch))
    fabric.api.sudo(
        'ec2-upload-bundle -b %s -m /tmp/image.manifest.xml -a %s -s %s --location %s'
        % (fabric.api.env.conf['AWS_AMI_BUCKET'],
           fabric.api.env.conf['AWS_ACCESS_KEY_ID'],
           fabric.api.env.conf['AWS_SECRET_ACCESS_KEY'],
           config['location'][:-1]))
    result = fabric.api.sudo(
        'ec2-register -C /tmp/cert.pem -K /tmp/pk.pem --region %s %s/image.manifest.xml -n %s'
        %
        (config['location'][:-1], fabric.api.env.conf['AWS_AMI_BUCKET'], name))
    fabric.api.run('rm /tmp/pk.pem')
    fabric.api.run('rm /tmp/cert.pem')

    ami = result.split()[1]
示例#5
0
def install_common_packages():
    """ Installs common system packages. """
    common_packages = [
        "ack-grep",
        "build-essential",
        "curl",
        "git-core",
        "gcc",
        "ipython",
        "libcurl3-dev",
        "libjpeg-dev",
        "libssl-dev",
        "mercurial",
        "ntp",
        "psmisc",
        "python2.6",
        "python2.6-dev",
        "python-imaging",
        "python-mysqldb",
        "python-pip",
        "python-setuptools",
        "python-software-properties",
        "python-virtualenv",
        "rsync",
        "screen",
        "subversion",
        "zlib1g-dev",
    ]

    # Install common and extra packages with no recommended packages
    package_install(common_packages, "--no-install-recommends")
示例#6
0
def sfs_install():
	""" Install SmartFoxServer Pro v.1.6.6 """

	if not _java_is_installed():
		fabric.api.warn(fabric.colors.yellow('Sun Java6 JDK must be installed'))
		return
	
	if _sfs_is_installed():
		fabric.api.warn(fabric.colors.yellow('SmartFoxServer Pro is already installed'))
		return

	# Get SmartFoxServer Pro
	sfs_filename = 'SFSPRO_linux64_1.6.6'
	with fabric.api.cd('/srv'):
		fabric.api.run('wget http://www.smartfoxserver.com/products/download.php?d=77 -O %s.tar.gz' % sfs_filename)
		fabric.api.run('gzip -d %s.tar.gz' % sfs_filename)
		fabric.api.run('tar xf %s.tar'     % sfs_filename)
	
	# Install SmartFoxServer Pro
	with fabric.api.cd('/srv/SmartFoxServer_PRO_1.6.6'):
		fabric.api.run('./install')
	
	# Install the 64-bit wrapper
	with fabric.api.cd('/srv'):
		fabric.api.run('wget http://www.smartfoxserver.com/download/wrapper/wrapper_linux64.zip')
		package_install(['unzip'],"--no-install-recommends")
		fabric.api.run('cp linux64/libwrapper.so  /srv/%s/Server/lib' % (SFS_VERSION))
		fabric.api.run('cp linux64/wrapper.jar    /srv/%s/Server/lib' % (SFS_VERSION))
		fabric.api.run('cp linux64/wrapper        /srv/%s/Server/wrapper_64'  % (SFS_VERSION))
		fabric.api.run('mv /srv/%s/Server/wrapper /srv/%s/Server/wrapper_32'  % (SFS_VERSION))
		link('/srv/%s/Server/wrapper_64' % (SFS_VERSION),dest='/srv/%s/Server/wrapper' % (SFS_VERSION))
示例#7
0
def nodejs_install():
	""" Install nodejs. """
	if _nodejs_nodejs():
		fabric.api.warn(fabric.colors.yellow('nodejs is already installed'))
		return
	package_add_repository('ppa:chris-lea/node.js')
	package_install(['python-software-properties', 'nodejs'])
	fabric.api.sudo('curl http://npmjs.org/install.sh | sudo sh')
示例#8
0
def uwsgi_install(force = False):
	""" Install uWSGI. """
	if _uwsgi_is_installed():
		fabric.api.warn(fabric.colors.yellow('uWSGI is already installed'))
		if not force:
			return

	package_install('libxml2','libxml2-dev')
	fabric.api.sudo('pip install http://projects.unbit.it/downloads/uwsgi-lts.tar.gz')
示例#9
0
def postgresql_client_install():
	if _postgresql_client_is_installed():
		fabric.api.warn(fabric.colors.yellow('The PostgreSQL client is already installed.'))
		return
	
	package_add_repository('ppa:pitti/postgresql')
	package_install(['postgresql-client', 'python-psycopg2'])
	
	# PGPool
	package_install('libpq-dev')
	'http://pgfoundry.org/frs/download.php/2958/pgpool-II-3.0.3.tar.gz'
示例#10
0
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,''))
示例#11
0
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, ''))
示例#12
0
def postgresql_client_install():
    if _postgresql_client_is_installed():
        fabric.api.warn(
            fabric.colors.yellow(
                'The PostgreSQL client is already installed.'))
        return

    package_add_repository('ppa:pitti/postgresql')
    package_install(['postgresql-client', 'python-psycopg2'])

    # PGPool
    package_install('libpq-dev')
    'http://pgfoundry.org/frs/download.php/2958/pgpool-II-3.0.3.tar.gz'
示例#13
0
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")
示例#14
0
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',])
示例#15
0
def save_as_ami(name, arch='i386'):
	config = get_provider_dict()
	# Copy pk and cert to /tmp, somehow
	fabric.api.put(fabric.api.env.conf['AWS_X509_PRIVATE_KEY'], '/tmp/pk.pem')
	fabric.api.put(fabric.api.env.conf['AWS_X509_CERTIFICATE'], '/tmp/cert.pem')
	
	fabric.contrib.files.sed('/etc/apt/sources.list', 'universe$', 'universe multiverse', use_sudo=True)
	package_update()
	package_install('ec2-ami-tools', 'ec2-api-tools')
	
	fabric.api.sudo('ec2-bundle-vol -c /tmp/cert.pem -k /tmp/pk.pem -u %s -s 10240 -r %s' % (fabric.api.env.conf['AWS_ID'], arch))
	fabric.api.sudo('ec2-upload-bundle -b %s -m /tmp/image.manifest.xml -a %s -s %s --location %s' % (fabric.api.env.conf['AWS_AMI_BUCKET'], fabric.api.env.conf['AWS_ACCESS_KEY_ID'], fabric.api.env.conf['AWS_SECRET_ACCESS_KEY'], config['location'][:-1]))
	result = fabric.api.sudo('ec2-register -C /tmp/cert.pem -K /tmp/pk.pem --region %s %s/image.manifest.xml -n %s' % (config['location'][:-1], fabric.api.env.conf['AWS_AMI_BUCKET'], name))
	fabric.api.run('rm /tmp/pk.pem')
	fabric.api.run('rm /tmp/cert.pem')
	
	ami = result.split()[1]
示例#16
0
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")
示例#17
0
def save_as_ami(name, region_id=None, arch='i386'):
	PROVIDER = get_provider_dict()
	if not region_id:
		region_id = PROVIDER['region_id']
	
	# Copy pk and cert to /tmp, somehow
	fabric.api.put(fabric.api.env.conf['AWS_X509_PRIVATE_KEY'], '/tmp/pk.pem')
	fabric.api.put(fabric.api.env.conf['AWS_X509_CERTIFICATE'], '/tmp/cert.pem')
	
	# Edit the sources list to include ec2 tools
	fabric.contrib.files.sed('/etc/apt/sources.list', 'universe$', 'universe multiverse', use_sudo=True)
	package_update()
	package_install('ec2-ami-tools', 'ec2-api-tools')
	
	# Bundle the volume
	fabric.api.sudo(
		'ec2-bundle-vol -c /tmp/cert.pem -k /tmp/pk.pem -u %s -s 10240 -r %s' % (
			fabric.api.env.conf['AWS_ID'], arch))
	fabric.api.sudo(
		'ec2-upload-bundle -b %s -m /tmp/image.manifest.xml -a %s -s %s --location %s' % (
			fabric.api.env.conf['AWS_AMI_BUCKET'], 
			_get_access_secret_keys(), 
			#fabric.api.env.conf['AWS_ACCESS_KEY_ID'], 
			#fabric.api.env.conf['AWS_SECRET_ACCESS_KEY'], 
			region_id))
	
	# Register the key
	result = fabric.api.sudo(
		'ec2-register -C /tmp/cert.pem -K /tmp/pk.pem --region %s %s/image.manifest.xml -n %s' % (
			region_id, 
			fabric.api.env.conf['AWS_AMI_BUCKET'], 
			name))
	
	# Remove the temp files
	fabric.api.run('rm /tmp/pk.pem')
	fabric.api.run('rm /tmp/cert.pem')
	
	# Return the ami object
	ami = result.split()[1]
	return ami
示例#18
0
def apache_install():
	""" Installs apache. """
	package_install(['apache2','libapache2-mod-wsgi','libapache2-mod-rpaf'])
	run('rm -f /etc/apache2/sites-enabled/default')
	run('rm -f /etc/apache2/sites-enabled/000-default')
	apache_setup_locale()
示例#19
0
def postgresql_install(id, node_dict, stage, **options):
    """ Installs postgreSQL """

    if _postgresql_is_installed():
        fabric.api.warn(
            fabric.colors.yellow('PostgreSQL is already installed.'))
        return

    config = get_provider_dict()
    if 'slave' in options:
        master = config['machines'][stage][options['slave']]
        options.update(master['services']['postgresql'])

    package_add_repository('ppa:pitti/postgresql')
    package_install(['postgresql', 'python-psycopg2'])

    # Figure out cluster name
    output = fabric.api.run('pg_lsclusters -h')
    version, cluster = output.split()[:2]

    if 'ec2' in fabric.api.env.conf['PROVIDER']:
        if not options.get('simple'):
            package_install('xfsprogs')
            package_install('mdadm', '--no-install-recommends')

            # Create two ebs volumes
            import boto.ec2
            ec2 = boto.ec2.connect_to_region(
                config['location'][:-1],
                aws_access_key_id=fabric.api.env.conf['AWS_ACCESS_KEY_ID'],
                aws_secret_access_key=fabric.api.env.
                conf['AWS_SECRET_ACCESS_KEY'])

            tag1 = u'%s-1' % id
            tag2 = u'%s-2' % id
            if not any(vol for vol in ec2.get_all_volumes()
                       if vol.tags.get(u'Name') == tag1):
                volume1 = ec2.create_volume(
                    options.get('max-size', 10) / 2, config['location'])
                volume1.add_tag('Name', tag1)
                volume1.attach(node_dict['id'], '/dev/sdf')
            if not any(vol for vol in ec2.get_all_volumes()
                       if vol.tags.get(u'Name') == tag2):
                volume2 = ec2.create_volume(
                    options.get('max-size', 10) / 2, config['location'])
                volume2.add_tag('Name', tag2)
                volume2.attach(node_dict['id'], '/dev/sdg')

            time.sleep(10)

            # RAID 0 together the EBS volumes, and format the result as xfs.  Mount at /data.
            if not fabric.contrib.files.exists('/dev/md0', True):
                fabric.api.sudo(
                    'mdadm --create /dev/md0 --level=0 --raid-devices=2 /dev/sdf /dev/sdg'
                )
                fabric.api.sudo('mkfs.xfs /dev/md0')

            # Add mountpoint
            if not fabric.contrib.files.exists('/data'):
                fabric.api.sudo('mkdir -p /data')
                fabric.api.sudo('chown postgres:postgres /data')
                fabric.api.sudo('chmod 644 /data')

            # Add to fstab and mount
            append('/etc/fstab', '/dev/md0  /data  auto  defaults  0  0', True)
            with fabric.api.settings(warn_only=True):
                fabric.api.sudo('mount /data')

            # Move cluster/dbs to /data
            if fabric.api.run('pg_lsclusters -h').split()[5] != '/data':
                fabric.api.sudo('pg_dropcluster --stop %s %s' %
                                (version, cluster))
                fabric.api.sudo(
                    'pg_createcluster --start -d /data -e UTF-8 %s %s' %
                    (version, cluster))

    else:
        fabric.api.warn(
            fabric.colors.yellow(
                'PostgreSQL advanced drive setup (RAID 0 + XFS) is not currently supported on non-ec2 instances'
            ))

    fabric.api.sudo('service postgresql stop')

    # Set up postgres config files - Allow global listening (have a firewall!) and local ubuntu->your user connections
    pg_dir = '/etc/postgresql/%s/%s/' % (version, cluster)
    fabric.contrib.files.comment(pg_dir + 'postgresql.conf',
                                 'listen_addresses', True)
    append(pg_dir + 'postgresql.conf', "listen_addresses = '*'", True)

    append(pg_dir + 'pg_hba.conf', "host all all 0.0.0.0/0 md5", True)
    fabric.contrib.files.sed(pg_dir + 'pg_hba.conf',
                             "ident",
                             "trust",
                             use_sudo=True)

    # Figure out if we're a master
    if 'slave' not in options and any(
            'slave' in values.get('services', {}).get('postgresql', {})
            for name, values in config['machines'][stage].iteritems()):
        # We're a master!

        append(pg_dir + 'postgresql.conf', [
            'wal_level = hot_standby', 'max_wal_senders = 1',
            'checkpoint_segments = 8', 'wal_keep_segments = 8'
        ], True)

        append(pg_dir + 'pg_hba.conf', "host replication all 0.0.0.0/0 md5",
               True)

    elif 'slave' in options:
        # We're a slave!

        append(pg_dir + 'postgresql.conf', [
            'hot_standby = on', 'checkpoint_segments = 8',
            'wal_keep_segments = 8'
        ], True)

        #fabric.api.sudo('rm -rf /data/*')
        append('/data/recovery.conf', [
            "standby_mode = 'on'",
            "primary_conninfo = 'host=%s port=5432 user=%s password=%s'" %
            (master['public_ip'][0], options['user'], options['password']),
            "trigger_file = '/data/failover'"
        ], True)

        fabric.api.local(
            '''ssh -i %s ubuntu@%s sudo tar czf - /data | ssh -i deploy/nbc-west.pem ubuntu@%s sudo tar xzf - -C /'''
            % (fabric.api.env.key_filename[0], master['public_ip'][0],
               node_dict['public_ip'][0]))
        fabric.api.sudo('chown -R postgres:postgres /data')

    fabric.api.sudo('service postgresql start')
示例#20
0
def postgresql_install(id, node_dict, stage, **options):
	""" Installs postgreSQL """

	if _postgresql_is_installed():
		fabric.api.warn(fabric.colors.yellow('PostgreSQL is already installed.'))
		return
	
	config = get_provider_dict()
	if 'slave' in options:
		master = config['machines'][stage][options['slave']]
		options.update(master['services']['postgresql'])
	
	package_add_repository('ppa:pitti/postgresql')
	package_install(['postgresql', 'python-psycopg2'])
	
	# Figure out cluster name
	output = fabric.api.run('pg_lsclusters -h')
	version, cluster = output.split()[:2]
	
	if 'ec2' in fabric.api.env.conf['PROVIDER']:
		if not options.get('simple'):
			package_install('xfsprogs')
			package_install('mdadm', '--no-install-recommends')
			
			# Create two ebs volumes
			import boto.ec2
			ec2 = boto.ec2.connect_to_region(config['location'][:-1],
								aws_access_key_id = fabric.api.env.conf['AWS_ACCESS_KEY_ID'],
								aws_secret_access_key = fabric.api.env.conf['AWS_SECRET_ACCESS_KEY'])
			
			tag1 = u'%s-1' % id
			tag2 = u'%s-2' % id
			if not any(vol for vol in ec2.get_all_volumes() if vol.tags.get(u'Name') == tag1):
				volume1 = ec2.create_volume(options.get('max-size', 10)/2, config['location'])
				volume1.add_tag('Name', tag1)
				volume1.attach(node_dict['id'], '/dev/sdf')
			if not any(vol for vol in ec2.get_all_volumes() if vol.tags.get(u'Name') == tag2):
				volume2 = ec2.create_volume(options.get('max-size', 10)/2, config['location'])
				volume2.add_tag('Name', tag2)
				volume2.attach(node_dict['id'], '/dev/sdg')
			
			time.sleep(10)
			
			# RAID 0 together the EBS volumes, and format the result as xfs.  Mount at /data.
			if not fabric.contrib.files.exists('/dev/md0', True):
				fabric.api.sudo('mdadm --create /dev/md0 --level=0 --raid-devices=2 /dev/sdf /dev/sdg')
				fabric.api.sudo('mkfs.xfs /dev/md0')
			
			# Add mountpoint
			if not fabric.contrib.files.exists('/data'):
				fabric.api.sudo('mkdir -p /data')
				fabric.api.sudo('chown postgres:postgres /data')
				fabric.api.sudo('chmod 644 /data')
			
			# Add to fstab and mount
			append('/etc/fstab', '/dev/md0  /data  auto  defaults  0  0', True)
			with fabric.api.settings(warn_only = True):
				fabric.api.sudo('mount /data')
	
			# Move cluster/dbs to /data
			if fabric.api.run('pg_lsclusters -h').split()[5] != '/data':
				fabric.api.sudo('pg_dropcluster --stop %s %s' % (version, cluster))
				fabric.api.sudo('pg_createcluster --start -d /data -e UTF-8 %s %s' % (version, cluster))
	
	else:
		fabric.api.warn(fabric.colors.yellow('PostgreSQL advanced drive setup (RAID 0 + XFS) is not currently supported on non-ec2 instances'))

	fabric.api.sudo('service postgresql stop')

	# Set up postgres config files - Allow global listening (have a firewall!) and local ubuntu->your user connections
	pg_dir = '/etc/postgresql/%s/%s/' % (version, cluster)
	fabric.contrib.files.comment(pg_dir + 'postgresql.conf', 'listen_addresses', True)
	append(pg_dir + 'postgresql.conf', "listen_addresses = '*'", True)

	append(pg_dir + 'pg_hba.conf', "host all all 0.0.0.0/0 md5", True)
	fabric.contrib.files.sed(pg_dir + 'pg_hba.conf', "ident", "trust", use_sudo=True)
	
	# Figure out if we're a master
	if 'slave' not in options and any('slave' in values.get('services', {}).get('postgresql', {})
									  for name, values in config['machines'][stage].iteritems()):
		# We're a master!
		
		append(pg_dir + 'postgresql.conf', [
			'wal_level = hot_standby',
			'max_wal_senders = 1',
			'checkpoint_segments = 8',
			'wal_keep_segments = 8'], True)
		
		append(pg_dir + 'pg_hba.conf', "host replication all 0.0.0.0/0 md5", True)
		
	elif 'slave' in options:
		# We're a slave!
		
		append(pg_dir + 'postgresql.conf', [
			'hot_standby = on',
			'checkpoint_segments = 8',
			'wal_keep_segments = 8'], True)
		
		#fabric.api.sudo('rm -rf /data/*')
		append('/data/recovery.conf', [
			"standby_mode = 'on'",
			"primary_conninfo = 'host=%s port=5432 user=%s password=%s'" % (master['public_ip'][0], options['user'], options['password']),
			"trigger_file = '/data/failover'"], True)
		
		fabric.api.local('''ssh -i %s ubuntu@%s sudo tar czf - /data | ssh -i deploy/nbc-west.pem ubuntu@%s sudo tar xzf - -C /''' % (fabric.api.env.key_filename[0], master['public_ip'][0], node_dict['public_ip'][0]))
		fabric.api.sudo('chown -R postgres:postgres /data')
	
	fabric.api.sudo('service postgresql start')
示例#21
0
def apache_install():
    """ Installs apache. """
    package_install(['apache2', 'libapache2-mod-wsgi', 'libapache2-mod-rpaf'])
    run('rm -f /etc/apache2/sites-enabled/default')
    run('rm -f /etc/apache2/sites-enabled/000-default')
    apache_setup_locale()