Esempio n. 1
0
    def handle_host(self, *args, **kwargs):
        with settings(patch=True):
            deploy_wsgi()
            deploy_webconf()

        activate_sites = [''.join([
                d.name.replace('.', '_'),
                '-',
                state.env.project_version,
                '.conf',
                ]) for d in domain_sites()]
        site_paths = ['/etc/apache2', '/etc/nginx']

        # Activate new sites.
        for path in site_paths:
            for site in activate_sites:
                if not exists('/'.join([path, 'sites-enabled', site])):
                    sudo("chmod 644 %s" % '/'.join(
                            [path, 'sites-available', site]))
                    sudo("ln -s %s/sites-available/%s %s/sites-enabled/%s" % (
                            path, site, path, site))
                    if state.env.verbosity:
                        print " * enabled", "%s/sites-enabled/%s" % (
                                path, site)
        reload_webservers()
Esempio n. 2
0
def activate():
    """
    Activates the version specified in ``env.project_version`` if it is different
    from the current active version.
    
    An active version is just the version that is symlinked.
    """

    env_path = '/'.join([deployment_root(),'env',env.project_fullname])

    if not exists(env_path):
        print env.host,"ERROR: The version",env.project_version,"does not exist at"
        print env_path
        sys.exit(1)

    active = active_version()

    if env.patch or active <> env.project_fullname:
        stop_webservers()
        
    if not env.patch and active <> env.project_fullname:
        
        if env.verbosity:
            print env.host, "ACTIVATING version", env_path
        
        if not env.nomigration:
            sync_db()
        
        #south migration
        if 'south' in env.INSTALLED_APPS and not env.nomigration and not env.manualmigration:
            migration()
            
        if env.manualmigration or env.MANUAL_MIGRATION: manual_migration()
      
        #activate sites
        activate_sites = [''.join([d.replace('.','_'),'-',env.project_version,'.conf']) for d in domain_sites()]
        site_paths = ['/etc/apache2','/etc/nginx']
        
        #disable existing sites
        for path in site_paths:
            for site in _ls_sites('/'.join([path,'sites-enabled'])):
                if site not in activate_sites:
                    sudo("rm %s/sites-enabled/%s"% (path,site))
        
        #activate new sites
        for path in site_paths:
            for site in activate_sites:
                if not exists('/'.join([path,'sites-enabled',site])):
                    sudo("chmod 644 %s" % '/'.join([path,'sites-available',site]))
                    sudo("ln -s %s/sites-available/%s %s/sites-enabled/%s"% (path,site,path,site))
                    if env.verbosity:
                        print " * enabled", "%s/sites-enabled/%s"% (path,site)
        
        #delete existing symlink
        ln_path = '/'.join([deployment_root(),'env',env.project_name])
        run('rm -f '+ln_path)
        run('ln -s %s %s'% (env_path,ln_path))

  
        if env.verbosity:
            print env.host,env.project_fullname, "ACTIVATED"
    else:
        if env.verbosity and not env.patch:
            print env.project_fullname,"is the active version"

    if env.patch or active <> env.project_fullname:
        start_webservers()
        print
    return
Esempio n. 3
0
 def handle_host(self,*args, **options):
     with settings(patch=True):
         deploy_wsgi()
         deploy_webconf()
     
     activate_sites = [''.join([d.name.replace('.','_'),'-',state.env.project_version,'.conf']) for d in domain_sites()]
     site_paths = ['/etc/apache2','/etc/nginx']
     
     #activate new sites
     for path in site_paths:
         for site in activate_sites:
             if not exists('/'.join([path,'sites-enabled',site])):
                 sudo("chmod 644 %s" % '/'.join([path,'sites-available',site]))
                 sudo("ln -s %s/sites-available/%s %s/sites-enabled/%s"% (path,site,path,site))
                 if state.env.verbosity:
                     print " * enabled", "%s/sites-enabled/%s"% (path,site)
     reload_webservers()
Esempio n. 4
0
 def handle_host(self,*args, **options):
     if not hasattr(state.env,'sites_created'):
         local_settings_dir = os.path.join(os.getcwd(),state.env.project_name,'sitesettings')
         sites = _get_django_sites()
         site_ids = sites.keys()
         site_ids.sort()
         for id in site_ids:
             sitesetting_path = os.path.join(state.env.project_name,'sitesettings',''.join([sites[id].replace('.','_'),'.py']))
             if not os.path.exists(sitesetting_path):
                 f = open(sitesetting_path, "w+")
                 f.write("from %s.sitesettings.settings import *"% state.env.project_name)
                 f.write("\nSITE_ID=%s\n"% str(id))
                 f.close()
         state.env.sites_created = True
     created = deploy_sitesettings()
     with settings(patch=True):
         deploy_wsgi()
         deploy_webconf()
     
     #activate sites
     activate_sites = [''.join([d.replace('.','_'),'-',state.env.project_version,'.conf']) for d in domain_sites()]
     site_paths = ['/etc/apache2','/etc/nginx']
     
     #activate new sites
     for path in site_paths:
         for site in activate_sites:
             if not exists('/'.join([path,'sites-enabled',site])):
                 sudo("chmod 644 %s" % '/'.join([path,'sites-available',site]))
                 sudo("ln -s %s/sites-available/%s %s/sites-enabled/%s"% (path,site,path,site))
                 if state.env.verbosity:
                     print " * enabled", "%s/sites-enabled/%s"% (path,site)
     reload_webservers()
Esempio n. 5
0
def activate():
    """
    Activates the version specified in ``env.project_version`` if it is different
    from the current active version.
    
    An active version is just the version that is symlinked.
    """

    env_path = '/'.join([deployment_root(), 'env', env.project_fullname])

    if not exists(env_path):
        print env.host, "ERROR: The version", env.project_version, "does not exist at"
        print env_path
        sys.exit(1)

    active = active_version()
    servers = webserver_list()

    if env.patch or active <> env.project_fullname:
        for s in servers:
            stop_webserver(s)

    if not env.patch and active <> env.project_fullname:

        if env.verbosity:
            print env.host, "ACTIVATING version", env_path

        if not env.nomigration:
            sync_db()

        #south migration
        if 'south' in env.INSTALLED_APPS and not env.nomigration and not env.manualmigration:
            migration()

        if env.manualmigration or env.MANUAL_MIGRATION: manual_migration()

        #activate sites
        activate_sites = [
            ''.join(
                [d.name.replace('.', '_'), '-', env.project_version, '.conf'])
            for d in domain_sites()
        ]
        if 'apache2' in get_packages():
            site_paths = ['/etc/apache2', '/etc/nginx']
        else:
            site_paths = ['/etc/nginx']

        #disable existing sites
        for path in site_paths:
            for site in _ls_sites('/'.join([path, 'sites-enabled'])):
                if site not in activate_sites:
                    sudo("rm %s/sites-enabled/%s" % (path, site))

        #activate new sites
        for path in site_paths:
            for site in activate_sites:
                if not exists('/'.join([path, 'sites-enabled', site])):
                    sudo("chmod 644 %s" %
                         '/'.join([path, 'sites-available', site]))
                    sudo("ln -s %s/sites-available/%s %s/sites-enabled/%s" %
                         (path, site, path, site))
                    if env.verbosity:
                        print " * enabled", "%s/sites-enabled/%s" % (path,
                                                                     site)

        #delete existing symlink
        ln_path = '/'.join([deployment_root(), 'env', env.project_name])
        run('rm -f ' + ln_path)
        #run post deploy hooks
        post_exec_hook('post_deploy')
        #activate
        run('ln -s %s %s' % (env_path, ln_path))

        if env.verbosity:
            print env.host, env.project_fullname, "ACTIVATED"
    else:
        if env.verbosity and not env.patch:
            print env.project_fullname, "is the active version"

    if env.patch or active <> env.project_fullname:
        for s in servers:
            start_webserver(s)
        print
    return