Esempio n. 1
0
    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')
Esempio n. 2
0
def provision_file_upload(path, **kwargs):
    """ Find the file in the deploy dir, upload it and set attributes """
    f = os.path.join(env.local_path, env.provision_dir, env.role, path[1:])
    if not os.path.exists(f):
        abort('Local file not found: %s' % f)
    file_upload(path, f)
    file_attribs(path, **kwargs)
Esempio n. 3
0
def utils_fix_hook():
    """
    Fix permissions on the hook.log
    """
    with cd(env.directory):
        with cuisine.mode_sudo():
            cuisine.file_attribs("{}/hook.log".format(env.virtualenvs), owner=env.user, group=env.user)
Esempio n. 4
0
 def testAttribs(self):
     tmpdir = tempfile.mkdtemp()
     try:
         dir1_path = os.path.join(tmpdir, 'dir1')
         cuisine.dir_ensure(dir1_path)
         file1_path = os.path.join(dir1_path, 'file1')
         cuisine.file_write(file1_path, 'test', mode='666')
         cuisine.file_attribs(tmpdir, mode=644, recursive=True)
         attribs = cuisine.file_attribs_get(file1_path)
         self.assertEqual(attribs.get('mode'), '644')
     finally:
         cuisine.dir_remove(tmpdir, recursive=True)
Esempio n. 5
0
def copy_source():
    local('git archive $(git symbolic-ref HEAD 2>/dev/null) '
            '| bzip2 > /tmp/app_name.tar.bz2')
    remote_filename = '/tmp/app_name.tar.bz2'
    code_dir = '~/app_name'
    sudo('rm -rf %s' % code_dir)
    if cuisine.file_exists(remote_filename):
        sudo('rm %s' % remote_filename)
    cuisine.file_upload(remote_filename, '/tmp/app_name.tar.bz2')
    with cuisine.mode_sudo():
        run('mkdir -p %s' % code_dir)
        cuisine.file_attribs(remote_filename)
        run('tar jxf %s -C %s' % (remote_filename, code_dir))
        run('rm %s' % (remote_filename,))
Esempio n. 6
0
def copy_source():
    '''archive the git source and copy it'''
    local('git archive $(git symbolic-ref HEAD 2>/dev/null)'
          ' | bzip2 > /tmp/%s.tar.bz2' % APP_NAME)
    remote_filename = '/tmp/%s.tar.bz2' % APP_NAME
    code_dir = '/home/%s/CODE' % APP_NAME
    sudo('rm -rf %s' % code_dir)
    if cuisine.file_exists(remote_filename):
        sudo('rm %s' % remote_filename)
    cuisine.file_upload(
        remote_filename, '/tmp/%s.tar.bz2' % APP_NAME)
    with cuisine.mode_sudo():
        run('mkdir -p %s' % code_dir)
        cuisine.file_attribs(remote_filename)
        run('tar jxf %s -C %s' % (remote_filename, code_dir))
        run('rm %s' % (remote_filename,))
Esempio n. 7
0
def utils_ssl_cert_install():
    """
    Create the ssl directory, upload the certs and create a combined cert
    """
    source_dir = prompt("ssl key file directory")
    dest_dir = "/svr/ssl"
    source_file_list = local("ls {}".format(source_dir), capture=True).split("\n")

    cmd_crt_comb = "cat {dest_dir}/{site_name}.crt {}/geo_trust_intermediate.crt > {dest_dir}/{site_name}.crt"
    with cuisine.mode_sudo():

        cuisine.dir_ensure("/svr/ssl/", recursive=True)
        cuisine.dir_attribs(dest_dir, mode="0400")
        for fl in source_file_list:
            cuisine.file_upload(dest_dir, "{}/{}".format(source_dir, fl))
            cuisine.file_attribs("{}/{}".format(dest_dir, fl), mode="0400")

        sudo(cmd_crt_comb.format(dest_dir=dest_dir, site_name=env.site_name))
Esempio n. 8
0
    def push_file(self, local_name, remote_name, owner, group, perms=None):
        '''
        Copy a file to a remote server if the file is different or doesn't
        exist.

        :type local_name: string
        :param local_name: path within packages dir of file to upload (path + filename)
        :type remote_name: string
        :param remote_name: remote path to write file to (path + filename)
        :type owner: string
        :param owner: owner of the file
        :type group: string
        :param group: group of the file
        :type perms: string
        :param perms: permissions for the file, ie. '655'
        '''
        local_name = os.path.join(self.settings["package_dir"], local_name)
        cuisine.file_upload(remote_name, local_name)
        if not perms:
            perms = self.get_local_file_perms(local_name)
        cuisine.file_attribs(
            remote_name, mode=perms, owner=owner, group=group)
Esempio n. 9
0
def copy_confs():
    nginx_conf_path = '/etc/nginx/sites-available/default'
    sprvsr_conf_path = '/etc/supervisor/conf.d/moback.conf'
    pghba_path = '/etc/postgresql/9.1/main/pg_hba.conf'
    put('confs/nginx_default.conf',
        nginx_conf_path, True)
    put('confs/supervisord.conf', sprvsr_conf_path,
        True, mode=0644)
    put('confs/pg_hba.conf', pghba_path, True)
    with cuisine.mode_sudo():
        cuisine.file_attribs(
            nginx_conf_path, owner='root', group='root')
        cuisine.file_attribs(
            sprvsr_conf_path, owner='root', group='root')
        cuisine.file_attribs(
            pghba_path, owner='root', group='root')
Esempio n. 10
0
 def attribs(self):
     cuisine.file_write("/tmp/cuisine.attribs.text")
     cuisine.file_attribs("/tmp/cuisine.attribs.text", "777")
     cuisine.file_unlink("/tmp/cuisine.attribs.text")
Esempio n. 11
0
	def attribs( self ):
		cuisine.file_write("/tmp/cuisine.attribs.text")
		cuisine.file_attribs("/tmp/cuisine.attribs.text", "777")
		cuisine.file_unlink("/tmp/cuisine.attribs.text")