Example #1
0
def deploy_webservers(version='',patch=False):
    """ Deploy  apache & nginx site configurations to the host """
    if not env.DOMAINS: env.DOMAINS = [root_domain()]
    #TODO - incorrect - check for actual package
    if exists('/etc/apache2/sites-enabled/') and exists('/etc/nginx/sites-enabled'):

        for d in env.DOMAINS:
            a = ApacheWebserver(d,version)
            a.deploy(patch)
            
            n = NginxWebserver(d,version)
            n.deploy(patch)
        set_server_state('deployed_webservers_' + project_fullname())
        return True

    else:
        print env.host,"""WARNING: Apache or Nginx not installed"""
        return False
    return False
Example #2
0
    def stage_local_files(self):
        #a dest_path_postfix is a /url/postfix/ from a django media setting
        #we need to create the full postfix directory on top of the deploy_root (eg STATIC_ROOT+ADMIN_MEDIA_PREFIX)
        #so locally we create a tmp staging directory to rsync from
        staging_dir = '%s_staging_dir'% self.deploy_type
        #ensure this is run only once per deploy_type
        if hasattr(env,staging_dir):
            return env[staging_dir]

        env[staging_dir] = s = tempfile.mkdtemp()

        #for cleanup later
        env.woventempdirs = env.woventempdirs + [s]
        shutil.copytree(self.local_path,os.path.join(s,self.last_postfix))
        #render settings files and replace
        if self.deploy_type == 'project':
            context = {
                'user':env.user,
                'project_name':project_name(),
                'project_fullname':project_fullname(),
                'root_domain':root_domain(),
                
            }
            for d in env.DOMAINS:
                context['domain']=d
                template_file = d.replace('.','_') + '.py'
                template_path = os.path.join(s,'project',project_name(),'sitesettings',template_file)
                f = open(template_path,"r")
                t = f.read()
                f.close()
                t = Template(t)
                rendered = t.render(Context(context))
                f = open(template_path,"w+")
                f.write(rendered)
                f.close()
        return s
Example #3
0
 def deploy(self, patch=False):
     
     if not exists(self.deploy_root):
         run("mkdir -p %s" % self.deploy_root)
     with cd(self.deploy_root):
         u_domain = self.domain.replace('.','_')
         filename = "%s.wsgi"% u_domain
         context = {"user": env.user,
                    "project_name": env.project_name,
                    "u_domain":u_domain,
                    "root_domain":env.root_domain,
                    }
         wsgi_exists = exists(filename)
         if wsgi_exists and not patch: 
             print env.host,"%s already exists on the host %s. Skipping..."% (self.deploy_type,filename)
             return False
         elif not wsgi_exists and patch:
             print env.host,"Error: Cannot patch %s %s. This version does not exist"% (project_fullname(), self.deploy_type)
             return False
         current_version = active_version()
         if current_version == env.project_fullname and not patch:
             print env.host,"Warning: Cannot deploy %s, version %s already active. Increase the version and re-deploy. Skipping.."% (self.deploy_type,env.project_fullname)
             return False
         else: #not exists
             upload_template('woven/'+self.template,
                                 filename,
                                 context,
                             )
             
             #finally set the ownership/permissions
             #We'll use the group to allow www-data execute
             if self.deploy_type == 'wsgi':
                 sudo("chown %s:www-data %s"% (env.user,filename))
                 run("chmod ug+xr %s"% filename)
     set_server_state(self.state+env.project_fullname)