Exemplo n.º 1
0
def configure():
    util.start()
    # Have php-fpm use a unix socket
    print('Switching php-fpm to socket')
    sed('/etc/php5/fpm/pool.d/www.conf',
        'listen = 127.0.0.1:9000',
        ';listen = 127.0.0.1:9000\\nlisten = /var/run/php5-fpm.sock',
        use_sudo=True,
        backup='.bak',
        flags='')
    # Enable php for nginx
    print('Routing .php from nginx to php-fpm')
    if exists('/etc/nginx/conf.d/php.conf'):
        sudo('rm /etc/nginx/conf.d/php.conf')
    put(util.template('php.conf'), '/etc/nginx/conf.d/php.conf', use_sudo=True)
    # Add custom php.ini settings
    print('Adding custom php.ini settings')
    if exists('/etc/nginx/conf.d/php.conf'):
        if exists('/etc/php5/fpm/conf.d/php-custom.ini'):
            sudo('rm /etc/php5/fpm/conf.d/php-custom.ini')
    put(util.template('php-custom.ini'),
        '/etc/php5/fpm/conf.d/php-custom.ini',
        use_sudo=True)
    # Reload php-fpm
    sudo('/etc/init.d/php5-fpm restart')
    util.done()
Exemplo n.º 2
0
def configure():
	util.start()
	# Have php-fpm use a unix socket
	print('Switching php-fpm to socket')
	sed('/etc/php5/fpm/pool.d/www.conf',
		'listen = 127.0.0.1:9000',
		';listen = 127.0.0.1:9000\\nlisten = /var/run/php5-fpm.sock',
		use_sudo=True, backup='.bak', flags='')
	# Enable php for nginx
	print('Routing .php from nginx to php-fpm')
	if exists('/etc/nginx/conf.d/php.conf'):
		sudo('rm /etc/nginx/conf.d/php.conf')
	put(util.template('php.conf'), '/etc/nginx/conf.d/php.conf', use_sudo=True)
	# Add custom php.ini settings
	print('Adding custom php.ini settings')
	if exists('/etc/nginx/conf.d/php.conf'):
		if exists('/etc/php5/fpm/conf.d/php-custom.ini'):
			sudo('rm /etc/php5/fpm/conf.d/php-custom.ini')
	put(util.template('php-custom.ini'), '/etc/php5/fpm/conf.d/php-custom.ini', use_sudo=True)
	# Reload php-fpm
	sudo('/etc/init.d/php5-fpm restart')
	util.done()


 	
Exemplo n.º 3
0
def register(git_hostname, username):
    util.start()
    # Copy the deploy private key to the server
    print("Copying deployment private key to server")
    put(util.template('id_rsa_deploy'),
        '/home/%s/.ssh/id_rsa_deploy' % username,
        use_sudo=False,
        mode=0600)
    # Copy ssh config file to server
    put(util.template('ssh_config'),
        '/home/%s/.ssh/config' % username,
        use_sudo=False)
    # Replace tokens in config file
    sed('/home/%s/.ssh/config' % username,
        '\{\{git-server\}\}',
        '%s' % git_hostname,
        use_sudo=False,
        flags='')
    sed('/home/%s/.ssh/config' % username,
        '\{\{home\}\}',
        '%s' % username,
        use_sudo=False,
        flags='')
    util.done()
Exemplo n.º 4
0
def configure():
	util.start()
	# Nginx conf changes
	sed('/etc/nginx/nginx.conf',
		'# server_names_hash_bucket_size 64',
		'server_names_hash_bucket_size 64',
		use_sudo=True, backup='.bak', flags='')
	# Nginx breaks due to 2 port 80 listeners
	sed('/etc/nginx/sites-available/default',
		'listen ',
		'#listen ',
		use_sudo=True, flags='')
	# Restart nginx
	sudo('/etc/init.d/nginx restart')
	# TODO: Load up check.php for Amazon health check
	put(util.template('check.php'), '/usr/share/nginx/html/check.php', use_sudo=True)
	util.done()
Exemplo n.º 5
0
def configure():
    util.start()
    # Create the resque-web directory structure
    sudo('mkdir -p /etc/unicorn')
    sudo('mkdir -p /var/www/resque-web')
    sudo('mkdir -p /var/www/resque-web/shared')
    sudo('mkdir -p /var/www/resque-web/config')
    sudo('mkdir -p /var/www/resque-web/log')
    sudo('mkdir -p /var/www/resque-web/shared')
    sudo('chown -R www-data:www-data /var/www/resque-web')
    sudo('chmod -R 775 /var/www/resque-web')
    put(util.template('etc-init.d-unicorn'),
        '/etc/init.d/unicorn',
        use_sudo=True)
    put(util.template('etc-nginx-resque-web'),
        '/etc/nginx/sites-available/resque-web',
        use_sudo=True)
    put(util.template('etc-unicorn-resque-web.conf'),
        '/etc/unicorn/resque-web.conf',
        use_sudo=True)
    put(util.template('var-www-config.ru'),
        '/var/www/resque-web/config.ru',
        use_sudo=True)
    put(util.template('var-www-unicorn.rb'),
        '/var/www/resque-web/config/unicorn.rb',
        use_sudo=True)
    put(util.template('var-www-resque.rb'),
        '/var/www/resque-web/config/resque.rb',
        use_sudo=True)
    # Munge the server_names to create a unique list
    # TODO: Move to separate function
    server_names = env.config.get('server_names', "")
    if (server_names != "" and server_names['resque'] != ""):
        server_names = server_names['resque']
        server_names.append(env.host_string)
        server_names = set(server_names)
        nginx_server_name = " ".join(server_names)
    else:
        nginx_server_name = env.host_string
    print("Setting nginx server_name: %s" % nginx_server_name)
    sed('/etc/nginx/sites-available/resque-web',
        '\{\{localhost\}\}',
        '%s' % nginx_server_name,
        use_sudo=True,
        backup='.bak',
        flags='')
    # Configure resque to the correct Redis server
    redis_host = 'localhost'
    redis_port = 6379
    redis_password = env.password
    if (env.redis_host and env.redis_host != ''):
        redis_host = env.redis_host
        redis_port = env.redis_port
        redis_password = env.redis_password
        print("Using redis server @ %s:%s" % (redis_host, redis_port))
    sed('/var/www/resque-web/config.ru',
        '\{\{host\}\}',
        '%s' % redis_host,
        use_sudo=True,
        backup='.bak',
        flags='')
    sed('/var/www/resque-web/config.ru',
        '\{\{port\}\}',
        '%s' % redis_port,
        use_sudo=True,
        backup='.bak',
        flags='')
    sed('/var/www/resque-web/config.ru',
        '\{\{password\}\}',
        '%s' % redis_password,
        use_sudo=True,
        backup='.bak',
        flags='')
    # Continue configuring resque server
    sed('/var/www/resque-web/config/resque.rb',
        '\{\{password\}\}',
        '%s' % env.password,
        use_sudo=True,
        backup='.bak',
        flags='')
    if not exists('/etc/nginx/sites-enabled/resque-web'):
        sudo(
            'ln -s /etc/nginx/sites-available/resque-web /etc/nginx/sites-enabled/resque-web'
        )
    sudo('chown root:root /etc/init.d/unicorn')
    sudo('chmod 775 /etc/init.d/unicorn')
    # Have unicorn (resque-web) start on boot
    sudo('update-rc.d unicorn defaults')
    # Restart unicorn and nginx
    sudo('/etc/init.d/unicorn restart')
    sudo('/etc/init.d/nginx restart')
    util.done()
Exemplo n.º 6
0
def configure():
	util.start()
	# Create the resque-web directory structure
	sudo('mkdir -p /etc/unicorn')
	sudo('mkdir -p /var/www/resque-web')
	sudo('mkdir -p /var/www/resque-web/shared')
	sudo('mkdir -p /var/www/resque-web/config')
	sudo('mkdir -p /var/www/resque-web/log')
	sudo('mkdir -p /var/www/resque-web/shared')
	sudo('chown -R www-data:www-data /var/www/resque-web')
	sudo('chmod -R 775 /var/www/resque-web')
	put(util.template('etc-init.d-unicorn'), '/etc/init.d/unicorn', use_sudo=True)
	put(util.template('etc-nginx-resque-web'), '/etc/nginx/sites-available/resque-web', use_sudo=True)
	put(util.template('etc-unicorn-resque-web.conf'), '/etc/unicorn/resque-web.conf', use_sudo=True)
	put(util.template('var-www-config.ru'), '/var/www/resque-web/config.ru', use_sudo=True)
	put(util.template('var-www-unicorn.rb'), '/var/www/resque-web/config/unicorn.rb', use_sudo=True)
	put(util.template('var-www-resque.rb'), '/var/www/resque-web/config/resque.rb', use_sudo=True)
	# Munge the server_names to create a unique list
	# TODO: Move to separate function
	server_names = env.config.get('server_names', "")
	if (server_names != "" and server_names['resque'] != ""):
		server_names = server_names['resque']
		server_names.append(env.host_string)
		server_names = set(server_names)
		nginx_server_name = " ".join(server_names)
	else:
		nginx_server_name = env.host_string
	print("Setting nginx server_name: %s" % nginx_server_name)
	sed('/etc/nginx/sites-available/resque-web',
		'\{\{localhost\}\}', 
		'%s' % nginx_server_name,
		use_sudo=True, backup='.bak', flags='')
	# Configure resque to the correct Redis server
	redis_host = 'localhost'
	redis_port = 6379
	redis_password = env.password
	if (env.redis_host and env.redis_host != ''):
		redis_host = env.redis_host
		redis_port = env.redis_port
		redis_password = env.redis_password
		print("Using redis server @ %s:%s" % (redis_host, redis_port))
	sed('/var/www/resque-web/config.ru',
		'\{\{host\}\}', 
		'%s' % redis_host,
		use_sudo=True, backup='.bak', flags='')
	sed('/var/www/resque-web/config.ru',
		'\{\{port\}\}', 
		'%s' % redis_port,
		use_sudo=True, backup='.bak', flags='')
	sed('/var/www/resque-web/config.ru',
		'\{\{password\}\}', 
		'%s' % redis_password,
		use_sudo=True, backup='.bak', flags='')
	# Continue configuring resque server
	sed('/var/www/resque-web/config/resque.rb',
		'\{\{password\}\}', 
		'%s' % env.password,
		use_sudo=True, backup='.bak', flags='')
	if not exists('/etc/nginx/sites-enabled/resque-web'):
		sudo('ln -s /etc/nginx/sites-available/resque-web /etc/nginx/sites-enabled/resque-web')
	sudo('chown root:root /etc/init.d/unicorn')
	sudo('chmod 775 /etc/init.d/unicorn')
	# Have unicorn (resque-web) start on boot
	sudo('update-rc.d unicorn defaults')
	# Restart unicorn and nginx
	sudo('/etc/init.d/unicorn restart')
	sudo('/etc/init.d/nginx restart')
	util.done()


 	
Exemplo n.º 7
0
def add_host(project_name, 
			 www_root, 
			 host_string,
			 environment = "DEVELOPMENT",
			 server_names = ""):
	util.start()
	project_name = project_name.lower()
	# Add new virtual host
	print('Adding new virtual host: %s' % host_string)
	# Delete old virtual host file
	if exists('/etc/nginx/sites-available/%s' % project_name):
		print('Found old virtual host, archiving')
		orig = '/etc/nginx/sites-available/%s' % project_name
		backup = '/etc/nginx/sites-available/%s' % util.timestamp(project_name)
		sudo('mv %s %s' % (orig, backup))
		#sudo('rm -fR /etc/nginx/sites-available/%s' % project_name)
		sudo('rm -fR /etc/nginx/sites-enabled/%s' % project_name)
	# Deal with SSL portion of site
	if (util.enabled('ssl')):
		# Copy some files from lib/ssl to server
		run('rm -fR ~/ssl')
		run('mkdir ~/ssl')
		put('fabfile/project/ssl/%s.com.bundle.crt' % project_name, 
			'~/ssl/%s.com.bundle.crt' % project_name)
		put('fabfile/project/ssl/%s.com.key' % project_name, 
			'~/ssl/%s.com.key' % project_name)
		nginx_site_file = "nginx-site-ssl";
	else:
		nginx_site_file = "nginx-site";
		print('Copying from local project virtual host')
	put(util.template("%s") % nginx_site_file,
		'/etc/nginx/sites-available/%s' % project_name,
		use_sudo=True)
	print('Replacing some tokens')
	# TODO: Token needs to be sync'd with Vagrantfile share folders
	# TODO: Token needs to by sync'd with dev_chris.py
	# TODO: Token needs to by sync'd with main fabric __init__.py
	sed('/etc/nginx/sites-available/%s' % project_name,
		'\{\{www_root\}\}',
		'%s' % www_root,
		use_sudo=True, backup='.bak', flags='')
	# Munge the server_names to create a unique list
	# TODO: Move to separate function
	if (server_names != "" and server_names['www'] != ""):
		server_names = server_names['www']
		server_names.append(host_string)
		server_names = set(server_names)
		nginx_server_name = " ".join(server_names)
	else:
		nginx_server_name = host_string
	print("Setting nginx server_name: %s" % nginx_server_name)
	sed('/etc/nginx/sites-available/%s' % project_name,
		'\{\{localhost\}\}',
		'%s' % nginx_server_name,
		use_sudo=True, backup='.bak', flags='')
	sed('/etc/nginx/sites-available/%s' % project_name,
		'\{\{environment\}\}',
		'%s' % environment,
		use_sudo=True, backup='.bak', flags='')
	util.done()