Example #1
0
def create(site, force=False):
    #create db
    logger.info("create: ")

    if not is_clean(site) and not force:
        logger.info("create: forced")
        return (False, "Destination site is not clean.")

    if _create_site_database(site) or force:

        logger.info("create: sitedir: %s" % (site.site_dir(), ))
        if _create_site_dirs(site) or force:

            # 'not installed' sites don't use the shared tables. this is necessary when installing.
            # after installed, use the shared tables so cas users may log in.
            site.set_flag('not installed')
            site.save()
            settings = _create_settings_php(site)

            if settings:
                install_status, output, err = _remote_drush(
                    site,
                    "site-install -y --site-name='%s' --sites-subdir='%s' --site-mail='%s' %s"
                    % (site.long_name, 'default' if site.short_name
                       == 'default' else site.platform.host + '.' +
                       site.short_name, site.contact_email, site.profile))
                if install_status == 0:
                    site.unset_flag('not installed')
                    site.set_flag('unqueried')
                    site.save()
                    # this updated settings.php uses the shared tables.
                    settings = _create_settings_php(site)
                    perm = _set_site_permissions(site)
                    return (True, output)
                site.set_flag('error')
                site.save()

                return (False, str(output) + str(err))

            else:
                logger.error("create(): create site failed. %s" % (output, ))
        else:
            logger.error("create(): create sitedirs failed")

            wipe_site(site)

    else:
        logger.error('create database failed %s' % (site.database, ))
        return (False, "creating database failed.")

    #drush --uri=http://localhost/foo site-install --sites-subdir=localhost.foo  --site-name=foo psu_primary

    logger.info("create: leave")
    return (True, "unknown")
Example #2
0
def create(site, force=False):
    #create db
    logger.info("create: ")

    if not is_clean(site) and not force:
        logger.info("create: forced")
        return (False, "Destination site is not clean.")

    if _create_site_database(site) or force:
         
        logger.info("create: sitedir: %s" % (site.site_dir(),))
        if _create_site_dirs(site) or force:

            # 'not installed' sites don't use the shared tables. this is necessary when installing.
            # after installed, use the shared tables so cas users may log in.
            site.set_flag('not installed')
            site.save()
            settings = _create_settings_php(site)

            if settings:
                install_status, output, err = _remote_drush(site, "site-install -y --site-name='%s' --sites-subdir='%s' --site-mail='%s' %s"
                                                        %( site.long_name,
                                                           'default' if site.short_name == 'default' else site.platform.host + '.' +  site.short_name,
                                                           site.contact_email,
                                                           site.profile) )
                if install_status == 0:
                    site.unset_flag('not installed')
                    site.set_flag('unqueried')
                    site.save()
                    # this updated settings.php uses the shared tables.
                    settings = _create_settings_php(site)
                    perm = _set_site_permissions(site)
                    return (True, output)
                site.set_flag('error')
                site.save()

                return (False, str(output) + str(err) )

            else:
                logger.error("create(): create site failed. %s" %(output,))
        else:
            logger.error("create(): create sitedirs failed")
            
            wipe_site(site)

    else:
        logger.error('create database failed %s' % (site.database,))
        return (False, "creating database failed.")

    
    #drush --uri=http://localhost/foo site-install --sites-subdir=localhost.foo  --site-name=foo psu_primary 

    logger.info("create: leave")
    return (True, "unknown")
Example #3
0
def get_cron_last(site):
    (status, out, err) = _remote_drush(site, "vget cron_last")
    cron_last = parse_vget('cron_last', out)
    if cron_last:
        t = datetime.datetime.fromtimestamp(float(cron_last))
        time_format = t.strftime(settings.TIME_FORMAT)
        x = Statistic(site=site, metric='cron_last', value=time_format)
        x.save()

        return {'cron_last': time_format}
    else:
        return {}
Example #4
0
def get_cron_last(site):
    (status, out, err) = _remote_drush(site, "vget cron_last") 
    cron_last = parse_vget('cron_last', out)
    if cron_last:
        t = datetime.datetime.fromtimestamp(float(cron_last))
        time_format = t.strftime(settings.TIME_FORMAT)
        x = Statistic(site=site, metric='cron_last', value=time_format)
        x.save()

        return {'cron_last': time_format }
    else:
        return {}
Example #5
0
def drush(site, cmd):
    (status, out, err) = _remote_drush(site, cmd)
    logger.debug("drush: %s" % (out, ))
    logger.debug("drush: %s" % (err, ))

    event = Event(
        site=site,
        event='drush',
        #user=request.user,
        task_id=drush.request.id,
        status=status == 0,
        message="%s" % (out, ),  # + "\n\n" + err,
    )
    event.save()

    return (status == 0, "%s\n%s" % (str(out), str(err)))
Example #6
0
def drush(site, cmd):
    (status, out, err) = _remote_drush(site, cmd)
    logger.debug("drush: %s" %(out,))
    logger.debug("drush: %s" %(err,))

    event = Event(  site=site, 
                    event='drush',
                    #user=request.user, 
                    task_id=drush.request.id, 
                    status= status==0,
                    message = "%s" %( out, ), # + "\n\n" + err,
                    )
    event.save()


    return (status==0, "%s\n%s" %(str(out), str(err)))
Example #7
0
def cron(site):
    (status, out, err) = _remote_drush(site, "cron")
    return (status == 0, parse_log(out))
Example #8
0
def cacheclear(site):
    #TODO: cacheclear: needs to handle default
    status, _, _ = _remote_drush(site, "vpa")
    status, out, _ = _remote_drush(site, "cc --yes all")
    return (status == 0, parse_log(out))
Example #9
0
def disable(site):
    (status, out, err) = _remote_drush(site, "vset --yes maintenance_mode 1")
    return (status == 0, parse_log(out))
Example #10
0
def verify(site):

    _out = ''

    (status, out, err) = _remote_drush(site, "vget maintenance_mode")
    _out += out

    site.unset_flag('error')
    site.unset_flag('unqueried')

    (status, out, err) = _remote_drush(site, "vget site_name")
    _out += out
    if status == 0:
        site.long_name = parse_vget('site_name', out)

        (status, extra, err) = _remote_drush(site, "vget site_name_extra")
        _out += extra
        if status == 0:
            site.long_name += ": " + parse_vget('site_name_extra', extra)

        site.set_flag('ok')
        site.unset_flag('unqueried')
        site.unset_flag('not installed')
        site.save()
    else:
        site.unset_flag('ok')

    site.save()

    if status == 0:
        x = parse_vget('maintenance_mode', out)
        if x == 1:
            site.set_flag('maintenance')
        else:
            site.unset_flag('maintenance')
        site.save()
    else:
        site.unset_flag('maintenance')
        site.save()

    (status, out, err) = _remote_drush(site, "vget site_mail")
    _out += out
    if status == 0:
        site.contact_email = parse_vget('site_mail', out)
        site.save()
    else:
        site.set_flag('error')
        site.save()

    #TODO: possibly could need to flush varnish first before checking.
    status = _check_site(site)
    if status == 500 or status > 500:
        site.set_flag('error')
    if status == 404:
        site.set_flag('not installed')
    if not status == 200:
        site.unset_flag('ok')
        site.save()
    else:
        (status, out, err) = _remote_drush(site, "status")
        if status == 0:
            db = parse_status('Database name', out)
            logger.error(
                'verify: updating database from %s to %s for site %s.' %
                (site.database, db, str(site)))
            site.database = db
            site.save()

    # if we're this far, profile the site. asynchronously.
    get_site_status.delay(site)

    #create a log entry.
    event = Event(
        site=site,
        event='verify',
        #user=request.user,
        task_id=verify.request.id,
        status='',
        message=_out,
    )
    event.save()
    return (True, "This command completed sucessfully.")
Example #11
0
def cron(site):
    (status, out, err) = _remote_drush(site, "cron")
    return (status == 0, parse_log(out))
Example #12
0
def cacheclear(site):
    #TODO: cacheclear: needs to handle default
    status, _, _ = _remote_drush(site, "vpa" )
    status, out, _ = _remote_drush(site, "cc --yes all")
    return (status == 0, parse_log(out))
Example #13
0
def disable(site):
    (status, out, err) = _remote_drush(site, "vset --yes maintenance_mode 1")
    return (status == 0, parse_log(out))
Example #14
0
def verify(site):

    _out = ''  

    (status, out, err) = _remote_drush(site, "vget maintenance_mode")
    _out += out

    site.unset_flag('error')
    site.unset_flag('unqueried')

    (status, out, err) = _remote_drush(site, "vget site_name")
    _out += out
    if status == 0:
        site.long_name = parse_vget('site_name', out)

        (status, extra, err) = _remote_drush(site, "vget site_name_extra")
        _out += extra
        if status == 0:
            site.long_name += ": " + parse_vget('site_name_extra', extra) 

        site.set_flag('ok')
        site.unset_flag('unqueried')
        site.unset_flag('not installed')
        site.save()
    else:
        site.unset_flag('ok')
        
    site.save()
    
    if status == 0:
        x = parse_vget('maintenance_mode', out)
        if x == 1:
            site.set_flag('maintenance')
        else:
            site.unset_flag('maintenance')
        site.save()
    else:
        site.unset_flag('maintenance')
        site.save()

    (status, out, err) = _remote_drush(site, "vget site_mail")
    _out += out
    if status == 0:
        site.contact_email = parse_vget('site_mail', out)
        site.save()
    else:
        site.set_flag('error')
        site.save()

    #TODO: possibly could need to flush varnish first before checking.
    status = _check_site(site)
    if status == 500 or status > 500:
        site.set_flag('error')
    if status == 404:
        site.set_flag('not installed')
    if not status == 200:
        site.unset_flag('ok')
        site.save()
    else:
        (status, out, err) = _remote_drush(site, "status")
        if status == 0:
            db = parse_status('Database name', out)
            logger.error('verify: updating database from %s to %s for site %s.' %(
                    site.database, db, str(site)))
            site.database = db
            site.save()

    # if we're this far, profile the site. asynchronously.
    get_site_status.delay(site)
    
    #create a log entry.
    event = Event(  site=site, 
                    event='verify',
                    #user=request.user, 
                    task_id=verify.request.id, 
                    status='',
                    message = _out,
                    )
    event.save()
    return (True, "This command completed sucessfully.")