Exemplo n.º 1
0
def copy_or_cache(sources, filename, cache_dir=None):
    """
    Try a list of sources, first cache the file before copying locally for install
    """
    if type(sources) is str:
        sources = [sources]
    if cache_dir is not None and os.path.isfile(cache_dir + os.sep + filename):
        shutil.copyfile(cache_dir + os.sep + filename, filename)
    else:
        source = failover_source(sources)
        res.Execute(copymethods(source, filename))
        if cache_dir is not None:
            if not os.path.exists(cache_dir):
                res.Execute("mkdir -p " + cache_dir)
            shutil.copyfile(filename, cache_dir + os.sep + filename)
    return
Exemplo n.º 2
0
    def start(self, env):
        print "start apache"
        self.configure(env)

        import time
        if detect_linux_version() in ["Centos7"]:
            # wait 3 seconds before calling start
            time.sleep(3)
            try:
                res.Execute("systemctl start httpd")
            except:
                res.Execute("apachectl graceful")

        time.sleep(3)
        res.Execute("apachectl graceful")
        time.sleep(3)
Exemplo n.º 3
0
    def install(self, env):
        print "installing apache..."
        self.install_packages(env)
        import params

        env.set_params(params)
        res.Execute("mkdir -p " + params.www_folder)
        chown_r(params.www_folder, "apache")
Exemplo n.º 4
0
def install_epel(clean=True):
    """
    install epel independent of redhat or centos version
    """
    if detect_linux_version() in ["Centos6"]:
        res.Execute(
            'yum -y install --setopt=retries=20 --setopt=timeout=60 epel-release'
        )
    else:
        status, stdout, _stderr = shell_call_wrapper('yum info epel-release')
        if status or 'installed' not in stdout:
            res.Execute(
                'yum -y install --setopt=retries=20 --setopt=timeout=60 wget')
            res.Execute(
                'wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm'
            )
            res.Execute('yum -y install epel-release-latest-7.noarch.rpm')
    if clean:
        res.Execute('yum clean all')
Exemplo n.º 5
0
    def configure(self, env):
        import params

        env.set_params(params)
        res.Execute('chkconfig httpd on')
        res.File('/etc/httpd/conf.d/000_default.conf',
                 content=res.InlineTemplate(params.template_000_default),
                 mode=0644)
        chown_r('/etc/httpd/conf.d/', "apache")
        chown_r(params.www_folder, "apache")
        if not os.path.isfile('/etc/httpd/conf/httpd.conf'):
            raise RuntimeError("Service not installed correctly")
        os.system("grep -v '^Listen' /etc/httpd/conf/httpd.conf > tmp.cnf")
        f = open("tmp.cnf")
        r = f.read()
        f.close()
        if len(r) < 13 or "ServerRoot" not in r:
            raise IOError("Temporary httpd.conf file corrupted!")
        res.Execute("cp tmp.cnf /etc/httpd/conf/httpd.conf")
        chown_r('/etc/httpd/conf/', "apache")
def make_ambari_service_effective(service_name, data_service):
    """Name: make_ambari_service_effective
    Performs all operations necessary (ie. restart) to register new service with Ambari
    """
    log.info('Proceeding with registration & installation of %s service + components on head node', service_name)
    time.sleep(data_service.get_delay_base_unit() * 2)
    log.info('Restarting Ambari on head node to register %s service', service_name)
    with rm.Environment():
        rm.Execute(('ambari-server', 'refresh-stack-hash'))
        rm.Service('ambari-server', action='restart')
    # We have to wait for it to come back up properly 
    time.sleep(data_service.get_delay_base_unit() * 3)
def restart_ams_if_necessary(ambari_cluster, data_service):
    """Name: restart_ams_if_necessary
    Restarts the Ambari Metrics Service collector service if the service is running on this host. This is required to make any new metrics registered in the whitelist file effective.
    """
    #Ambari holds the fqdn of each host
    ams_collector_host = ambari_cluster.services('AMBARI_METRICS').components('METRICS_COLLECTOR').host_components.next().host_name
    this_host = socket.getaddrinfo(socket.gethostname(), 0, 0, 0, 0, socket.AI_CANONNAME)[0][3]
    if data_service.is_ams_collector_host(ams_collector_host, this_host):
        try:
            log.info("Restarting AMS to make new whitelist metrics effective")
            with rm.Environment():
                rm.Execute([data_service.get_ams_collector_exe(), '--config', data_service.get_ams_collector_config(), 'restart'], user='******', logoutput=True)
        except rm.Fail as ex:
            log.warning('Failed to successfully restart AMS metrics collector. Details: %s', ex.message)
Exemplo n.º 8
0
def extra_redhat_repos():
    """
    Enable additional redhat repositories needed by some
    select components
    """
    rh = is_true_redhat()
    if rh:
        for repo in [
                'rhui-REGION-rhel-server-optional',
                'rhui-REGION-rhel-server-extras',
                'rhui-REGION-rhel-server-source-optional',
                'rhui-REGION-rhel-server-releases-source'
        ]:
            res.Execute('yum-config-manager --enable ' + repo)
    return rh
Exemplo n.º 9
0
def chmod_up(lowest, mode, seen=[]):
    """
    chmod wrapper, add certain modes to all directories walking up towards root
    """
    lowest = os.path.realpath(lowest)
    if lowest in seen:
        return
    # prevent infinite recursion!
    seen.append(lowest)
    if lowest == '/':
        return
    elif not os.path.exists(lowest):
        return
    elif not len(lowest):
        return
    res.Execute('chmod ' + mode + ' ' + lowest)
    if lowest.count("/") < 2:
        # prevent infinite recursion!
        return
    if lowest == os.path.realpath(os.sep.join(lowest.split(os.sep)[:-1])):
        # prevent infinite recursion!
        return
    return chmod_up(os.sep.join(lowest.split(os.sep)[:-1]), mode, seen=seen)
Exemplo n.º 10
0
 def restart(self, env):
     print "restart apache..."
     res.Execute('service httpd restart')
Exemplo n.º 11
0
 def stop(self, env):
     print "stop apache.."
     res.Execute('systemctl stop httpd')