def install_gunicorn(self):
        self.run_virtualenv('pip -q install gunicorn')

        with mode_sudo():
            dir_ensure('/var/log/gunicorn/',
                owner=self.user_name,
                group=self.group_name,
                )

        if self.util.get_package_manager() == 'apt':
            operations.put(
                'gunicorn.conf', 
                '/etc/init/', 
                use_sudo=True, mode=644)
            with mode_sudo():
                file_attribs('/etc/init/gunicorn.conf',
                    mode=700,
                    owner='root',
                    group='root',
                    )
                with settings(warn_only=True):
                    sed('/etc/init/gunicorn.conf', 
                        '\{virtualenv\}', 
                        self.virtualenv_dir,
                        use_sudo = True,
                        )

        operations.put(
            'gunicorn-launcher.sh', 
            self.virtualenv_dir + '/bin/', 
            use_sudo=True, mode=750)
        with mode_sudo():
            file_attribs(self.virtualenv_dir + '/bin/gunicorn-launcher.sh',
                mode=700,
                owner=self.user_name,
                group=self.group_name,
                )
            with settings(warn_only=True):
                sed(self.virtualenv_dir + '/bin/gunicorn-launcher.sh', 
                    '\{virtualenv\}', 
                    self.virtualenv_dir,
                    use_sudo = True,
                    )
                sed(self.virtualenv_dir + '/bin/gunicorn-launcher.sh', 
                    '\{project\}', 
                    self.www_dir,
                    use_sudo = True,
                    )


        # install gevent. This is non-critical and might fail so we go to
        # warn-only mode 
        with settings(warn_only=True):
            package_ensure('libevent-dev')
            self.run_virtualenv('pip -q install gevent')
        
        #   # TODO: add -k gevent to gunicorn launcher script

        # TODO
        upstart_ensure('gunicorn')
Exemple #2
0
def sshd_config():
	puts(green('Setup SSHD config'))

	download_and_upload('ssh/%s-sshd_config', '/etc/ssh/sshd_config')
	cuisine.upstart_ensure('sshd')
	
	puts(green('Success'))
Exemple #3
0
def cloudstack_init(fqdn=None):
	puts(green('CloudStack Initialize'))
	
	if fqdn is None:
		abort('Please set FQDN\n\tex) $ fab .... rolename:"fqdn"')
	
	# 石川さんごめんなさい
	sudo('sed -i -e "s/SELINUX=enforcing/SELINUX=permissive/g" /etc/selinux/config')
	sudo('setenforce permissive')
	
	# Repository for CloudStack
	repository = '[cloudstack]\nname=cloudstack\n'
	repository += 'baseurl=http://cloudstack.apt-get.eu/rhel/4.2/\n'
	repository += 'enabled=1\n'
	repository += 'gpgcheck=0\n'
	cuisine.file_write('/etc/yum.repos.d/CloudStack.repo', repository)
	
	# Setting FQDN
	if not fqdn in cuisine.file_read('/etc/hosts'):
		sudo('sed -i -e "s/localhost/' + fqdn + ' localhost/" /etc/hosts')
	
	# NTP
	install_package('ntp')
	cuisine.upstart_ensure('ntpd')
	sudo('chkconfig ntpd on')
	download_and_upload('ntp/%s-ntp.conf', '/etc/ntp.conf', abort_flg=False)

	puts(green('Success'))



#--------------------------------------#
#                  NFS                 #
#--------------------------------------#
	def nfs(directory):
		puts(green('Setup NFS'))

		if fqdn is None:
			abort('Please set Directory\n\tex) $ fab .... nfsrolename:"/etc/hogehoge"')
	
	# Install
	install_package('nfs-utils')

	# Start
	for name in [ 'rpcbind', 'nfs' ]:
		cuisine.upstart_ensure(name)
		sudo('chkconfig %s on' % name)

	# Create Directory
	cuisine.dir_ensure(directory, recursive=True)

	# Setting /etc/exports
	download_and_upload('nfs/%s-exports', '/etc/exports')
	sudo('exportfs -a')

	# Setting /etc/sysconfig/nfs
	download_and_upload('nfs/%s-nfs', '/etc/sysconfig/nfs')
	
	puts(green('Success'))
Exemple #4
0
def denyhosts():
	puts(green('Setup denyhosts'))
	
	proxy(sudo, 'yum install denyhosts')
	cuisine.upstart_ensure('denyhosts')
	sudo('chkconfig denyhosts on')

	puts(green('Success'))
Exemple #5
0
def iptables():
	puts(green('Setup iptables'))
	
	# Setting(IPv4 and IPv6)
	for service in [ 'iptables', 'ip6tables' ] :
		if not is_running(service) :
			continue
			
		local = 'iptables/%s-' + service
		download_and_upload(local, '/etc/sysconfig/%s' % service)
		cuisine.upstart_ensure(service)
	
	puts(green('Success'))
Exemple #6
0
def deploy(commit_msg=None):
    localpath = os.path.dirname(os.path.realpath(__file__))
    if commit_msg:
        with lcd(localpath):
            with settings(warn_only=True):
                local('git commit -am "{commit_msg}"'.format(
                    commit_msg=commit_msg))

    with lcd(localpath):
        with settings(warn_only=True):
            local('git push')

    with cd('~'):
        if not dir_exists('blogging'):
            run('mkdir blogging')
            with cd('blogging'):
                run('git clone git://github.com/imathis/octopress.git')
                run('git clone git://github.com/tly1980/my_blog.git')

    with cd('~/blogging/octopress'):
        with prefix('source ~/.bash_profile'):
            # install the desire ruby version
            run('bundle install')

    with cd('~/blogging/my_blog'):
        run('git pull')

    with cd('~/blogging/octopress'):
        with settings(warn_only=True):
            run('rm Rakefile _config.yml config.rb source')

        run('ln -s ../my_blog/Rakefile .')
        run('ln -s ../my_blog/_config.yml .')
        run('ln -s ../my_blog/config.rb .')
        run('ln -s ../my_blog/source .')
        run('rake generate')

    with cd('~'):
        with settings(warn_only=True):
            sudo('rm -rvf /srv/keyonly.com')

        sudo('cp -r blogging/octopress/public /srv/keyonly.com')
        sudo('chmod -R 0755 /srv/keyonly.com')

    file_write('/etc/nginx/sites-available/keyonly.com', site_cfg, sudo=True)
    if not file_exists('/etc/nginx/sites-enabled/keyonly.com'):
        sudo(
            'ln -s /etc/nginx/sites-available/keyonly.com /etc/nginx/sites-enabled/keyonly.com'
        )

    upstart_ensure('nginx')
Exemple #7
0
def deploy(commit_msg=None):
    localpath = os.path.dirname(os.path.realpath(__file__))
    if commit_msg:
        with lcd(localpath):
            with settings(warn_only=True):
                local('git commit -am "{commit_msg}"'.format(commit_msg=commit_msg))

    with lcd(localpath):
        with settings(warn_only=True):
            local('git push')

    with cd('~'):
        if not dir_exists('blogging'):
            run('mkdir blogging')
            with cd('blogging'):
                run('git clone git://github.com/imathis/octopress.git')
                run('git clone git://github.com/tly1980/my_blog.git')

    with cd('~/blogging/octopress'):
        with prefix('source ~/.bash_profile'):
            # install the desire ruby version
            run('bundle install')

    with cd('~/blogging/my_blog'):
        run('git pull')

    with cd('~/blogging/octopress'):
        with settings(warn_only=True):
            run('rm Rakefile _config.yml config.rb source')

        run('ln -s ../my_blog/Rakefile .')
        run('ln -s ../my_blog/_config.yml .')
        run('ln -s ../my_blog/config.rb .')
        run('ln -s ../my_blog/source .')
        run('rake generate')

    with cd('~'):
        with settings(warn_only=True):
            sudo('rm -rvf /srv/keyonly.com')

        sudo('cp -r blogging/octopress/public /srv/keyonly.com')
        sudo('chmod -R 0755 /srv/keyonly.com')

    file_write('/etc/nginx/sites-available/keyonly.com', site_cfg, sudo=True)
    if not file_exists('/etc/nginx/sites-enabled/keyonly.com'):
        sudo('ln -s /etc/nginx/sites-available/keyonly.com /etc/nginx/sites-enabled/keyonly.com')

    upstart_ensure('nginx')
Exemple #8
0
def agent():
	puts(green('Setup Agent'))

	# Install
	for package in [ 'qemu-kvm', 'cloudstack-agent', 'bridge-utils', 'vconfig', 'spice-server' ]:
		install_package(package)
	
	# Setting
	sudo('modprobe kvm-intel')
	download_and_upload('agent/%s-cgconfig.conf', '/etc/cgconfig.conf')
	download_and_upload('agent/%s-libvirtd.conf', '/etc/libvirt/libvirtd.conf')
	for service in [ 'cgconfig', 'libvirtd' ]:
		cuisine.upstart_ensure(service)

	# Finish
	puts(green('Success'))
Exemple #9
0
def database():
	puts(green('Setup Database'))

	# Install
	install_package('mysql-server')
	
	# Setting
	download_and_upload('db/%s-my.cnf', '/etc/my.cnf')
	sudo('chkconfig mysqld on')
	cuisine.upstart_ensure('mysqld')

	# Initialize
	puts(yellow('run => mysql_secure_installation <='))
	sudo('mysql_secure_installation')

	puts(green('Success'))
Exemple #10
0
def upgrade_agent():
	puts(green('Upgrade Agent'))

	# Prepare
	upgrade_common()

	# Upgrade
	proxy(sudo, 'yum upgrade cloudstack-agent -y')

	# Verify
	path = '/etc/cloudstack/agent/environment.properties'
	str = 'paths.script=/usr/share/cloudstack-common'
	if not str in cuisine.file_read(path):
		cuisine.file_append(path, '\n%s\n' % str)
	
	# Restart
	cuisine.upstart_stop('cloudstack-agent')
	sudo('killall jsvc', warn_only=True)
	cuisine.upstart_ensure('cloudstack-agent')

	puts(green('Success'))
Exemple #11
0
def network(network_restart=False):
	puts(green('Setup Network'))

	def _network(directory):
		r = re.compile('^ifcfg\-[a-z]+[0-9]+$')

		if not os.path.isdir('./config/' + directory):
			return False
		for name in os.listdir('./config/' + directory):
			if not r.match(name):
				continue
			download_and_upload('%s/%s' % (directory, name), '/etc/sysconfig/network-scripts/' + name)
		return True
	
	tmp = 'network/%s' % env.hosts[0]
	if not _network(tmp + '.ignore'):
		if not _network(tmp):
			abort('Not Found %s' % tmp)

	if network_restart:
		cuisine.upstart_ensure('network')
	else:
		puts(yellow('Please "service network restart"'))
	puts(green('Success'))
Exemple #12
0
def configure_ntp(ntpHost):
    """Change default ntp server to client choice"""
    sudo("sed -i 's/server ntp.ubuntu.com/server %s/g' /etc/ntp.conf" % ntpHost)
    sudo("service ntp stop")
    sudo("ntpdate -u %s" % ntpHost)
    upstart_ensure('ntp')
Exemple #13
0
def set_upstart(name):
    cuisine.upstart_ensure(name)
Exemple #14
0
def management():
	puts(green('Setup Management Server'))

	# Install
	install_package('cloudstack-management')
	
	# Load File
	config = ConfigParser.SafeConfigParser()
	config.read(config_read_path('./config/management/db.ini'))
	
	user = config.get('cloud', 'user')
	password = config.get('cloud', 'password')
	deploy_user = config.get('deploy', 'user')
	deploy_password = config.get('deploy', 'password')
	server = config.get('deploy', 'server')
	
	if None in [ user, password, deploy_user, deploy_password, server ]:
		abort('Check config/agent/db.ini')
	
	# Initialize
	run('cloudstack-setup-databases "%s:%s@%s" "--deploy-as=%s:%s"' % (user, password, server, deploy_user, deploy_password))

	tmp = 'Defaults:cloud !requiretty'
	if not '\n' + tmp in cuisine.file_read('/etc/sudoers'):
		cuisine.file_append('/etc/sudoers', '\nDefaults:cloud !requiretty\n')
	
	run('cloudstack-setup-management')
	sudo('chkconfig cloudstack-management on')
	sudo('chown cloud:cloud /var/log/cloudstack/management/catalina.out')

	# NFS Client
	for service in [ 'rpcbind', 'nfs' ]:
		cuisine.upstart_ensure(service)
		sudo('chkconfig %s on' % service)
	
	# Setting Storage
	cuisine.dir_ensure('/mnt/primary', recursive=True)
	cuisine.dir_ensure('/mnt/secondary', recursive=True)
	
	config.read(config_read_path('./config/management/nfs.ini'))
	nfs_primary_path = config.get('primary', 'path')
	nfs_primary_ip = config.get('primary', 'ipaddr')
	nfs_secondary_path = config.get('secondary', 'path')
	nfs_secondary_ip = config.get('secondary', 'ipaddr')
	
	if None in [ nfs_primary_path, nfs_primary_ip, nfs_secondary_path, nfs_secondary_ip ]:
		abort('Check config/agent/nfs.ini')
	
	sudo('mount -t nfs %s:%s /mnt/primary' % (nfs_primary_ip, nfs_primary_path))
	sleep(5)
	sudo('mount -t nfs %s:%s /mnt/secondary' % (nfs_secondary_ip, nfs_secondary_path))
	sleep(5)
	
	sudo('rm -rf /mnt/primary/*')
	sudo('rm -rf /mnt/secondary/*')
	
	proxy(sudo, '/usr/share/cloudstack-common/scripts/storage/secondary/cloud-install-sys-tmplt -m /mnt/secondary -u http://d21ifhcun6b1t2.cloudfront.net/templates/4.2/systemvmtemplate-2013-06-12-master-kvm.qcow2.bz2 -h kvm -F')
	sudo('sync')
	
	for dir in [ '/mnt/primary', '/mnt/secondary' ]:
		sudo('umount %s' % dir)
		sudo('rmdir %s' % dir)

	puts(green('Success'))
Exemple #15
0
def _restart_daemons():
	puts(green('Restarting Daemons'))
	cuisine.upstart_ensure('apache2')