Exemplo n.º 1
0
def stopMN(minimal=False):
    if Const.isWindows():
        # ignore 2 error code, because in 5.4 pem cannot be stopped properly
        uUtil.readCmd(['net', 'stop', 'pem'], valid_codes=[0, 2])
        uUtil.readCmd(['net', 'stop', 'PAU'], valid_codes=[0, 1, 2])
    else:
        if not minimal:
            # pem script actually returns 1 and 123 on valid stops
            uUtil.execCommand('service pa-agent stop', [0, 1, 123])
            uUtil.execCommand('service pau stop', [0, 1, 5])

        # In some mysterious cases "service pa-agent stop" doesn't work
        uUtil.readCmdExt(['killall', '-9', 'pa-agent'])
        uUtil.readCmdExt(['killall', '-9', 'SoLoader'])
    resetPIDs()
Exemplo n.º 2
0
def listNetifaces():
    adapterLinePattern = re.compile(r".* adapter (.*):")
    ipLinePattern = re.compile(r"\s*IPv4 Address.* : (.*)")
    maskLinePattern = re.compile(r"\s*Subnet Mask.* : (.*)")
    ipAndMaskPattern = re.compile(r"([0-9]{1,3}\.){3}[0-9]{1,3}")

    ifcfg_out = uUtil.readCmd("ipconfig")

    iface_name = ip = mask = None
    rv = []
    for line in ifcfg_out.splitlines():
        line = line.strip()
        if not line:
            continue
        m = adapterLinePattern.match(line)
        if m:
            iface_name = m.group(1)
            continue
        if iface_name:
            m = ipLinePattern.match(line)
            if m:
                ip = m.group(1)
                if not ipAndMaskPattern.match(ip):
                    raise Exception("ip address %s for adapter %s does not match pattern" % (ip, iface_name))
            m = maskLinePattern.match(line)
            if m:
                mask = m.group(1)
                if not ipAndMaskPattern.match(mask):
                    raise Exception("network mask %s for adapter %s does not match pattern" % (mask, iface_name))
            if ip and mask:
                rv.append((iface_name, ip, mask))
                iface_name = ip = mask = None
    return rv
Exemplo n.º 3
0
def checkUncompatibleJDK():
    uLogging.info("Checking for incompatible JDK rpms (OpenJDK)...")
    s = uUtil.readCmd(['rpm', '-qa', '*openjdk*', 'jdk'])
    rpms = s.strip().split('\n')
    bad_rpms = filter(lambda p: 'openjdk' in p, rpms)
    if bad_rpms:
        raise uPrecheck.PrecheckFailed('incompatible java rpms found: %s' %
                                       bad_rpms, 'replace with JDK rpm shipped with PA')
Exemplo n.º 4
0
def getPOAProductId():
    # POA Product ID changes with every poa-core.msi content modification
    # return None if POA not installed
    msiProductName = "Parallels Operations Automation"
    psCmd = "Get-ChildItem HKLM:\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall " \
            "| ForEach-Object { Get-ItemProperty $_.PSPath } | Where-Object {$_.DisplayName -eq \"%s\"} " \
            "| Select -ExpandProperty PSChildName" % msiProductName
    productId = uUtil.readCmd(["powershell", "-Command", psCmd])
    productId = productId.strip()
    if not productId:
        productId = None
    return productId
Exemplo n.º 5
0
def listNetifaces():
    from netaddr import IPNetwork
    out = uUtil.readCmd(['ip', 'addr'])
    rv = []
    for line in out.splitlines():
        m = addr_pattern.match(line)
        if m:
            ip = m.group(1)
            mask = m.group(2)       # digit
            if_name = m.group(3)
            n = IPNetwork(ip + '/' + mask)
            rv.append((if_name, ip, str(n.netmask)))
    return rv
Exemplo n.º 6
0
def startMN(minimal=False):
    resetPIDs()

    platform, root = getMNInfo()
    if Const.isWindows():
        stopMN()
        # To ensure waitForJBossStarted will do correct
        from u import bootstrap
        os.remove(bootstrap.getJBossDir(root) + '\\standalone\\log\\standalone.log')
        uUtil.readCmd(['net', 'start', 'PAU'])
        # Service is stated as "started" before JBoss is actually started, need to wait
        waitForJBossStarted(root)
        uUtil.readCmd(['net', 'start', 'pem'], valid_codes=[0])
    else:
        if minimal:

            env = dict()
            env.update(os.environ)
            pleskd_env = dict(
                LD_LIBRARY_PATH=str(os.path.join(root, "lib") + ":" + "/usr/pgsql-9.5/lib/"),
                SVC_CONF=str(os.path.join(root, "etc", "svc.conf")),
                PLESKD_PROPS=str(os.path.join(root, "etc", "pleskd.props"))
            )
            env.update(pleskd_env)

            progname = os.path.join(root, "sbin", "pa-agent")

            cmd = []
            cmd.append(progname)
            cmd.append("--props-file=" + os.path.join(root, "etc", "pleskd.props"))
            # LD_LIBRARY_PATH="/usr/local/pem/lib:/usr/pgsql-9.4/lib/"
            # PATH="${PATH}:/usr/local/pem/bin" /usr/local/pem/sbin/pleskd
            # --props-file /usr/local/pem/etc/pleskd.props --send-signal
            sp.Popen(cmd, env=env)
        else:
            uUtil.execCommand('service pau start', valid_codes=[0, 1])
            uUtil.execCommand('service pa-agent start')
Exemplo n.º 7
0
def configureSystem(config, progress, PRODUCT):
    from poaupdater.uAction import retriable
    selinux_mode = uUtil.readCmd(['getenforce']).strip()
    uLogging.debug("SELinux is %s" % selinux_mode)

    progress.set_progress(1, "Adjusting kernel memory settings")
    all_mem, sh_mem = getMemTotal()
    adjustMemSettings(PRODUCT, all_mem)

    gname = config.sysgroup
    uname = config.sysuser
    progress.set_progress(2, "Creating group %s" % gname)
    try:
        grpinfo = grp.getgrnam(gname)
    except KeyError:
        retriable(uUtil.execCommand)(["groupadd", "-f", gname])
        grpinfo = grp.getgrnam(gname)
    config.sysgroupid = grpinfo.gr_gid

    progress.set_progress(5, "Creating user %s" % uname)
    try:
        pwdinfo = pwd.getpwnam(uname)
    except KeyError:
        retriable(uUtil.execCommand)(["useradd", "-M", uname, "-g", gname, "-d", "/nonexistent", "-s", "/bin/false"])
        pwdinfo = pwd.getpwnam(uname)
    config.sysuserid = pwdinfo.pw_uid
    config.sysgroupid = pwdinfo.pw_gid

    uLogging.debug("dump config after configureSystem: %s" % uUtil.stipPasswords(vars(config)))
    uLogging.debug("Setting hostname")

    hostname_line_pattern = re.compile(r"HOSTNAME=.*")

    def sysconfig_network(inf, outf):
        for ln in inf.readlines():
            if hostname_line_pattern.match(ln):
                print >> outf, 'HOSTNAME="%(hostname)s"' % vars(config)
            else:
                outf.write(ln)
    uUtil.editFileSafe('/etc/sysconfig/network', sysconfig_network, '/etc/sysconfig/network.pemsave')
    uUtil.execCommand(["hostname", config.hostname])

    #install httpd + modules
    httpd_rpms = ["httpd", "mod_ssl"]

    platform = determinePlatform()
    if platform.osver == "6":
        httpd_rpms.append("mod_proxy_wstunnel")

    # previous call resets hostname that triggers restarting Network Manager. /etc/resolv.conf content become not valid
    # for a moment. Reproduced sometimes on CentOS 7 VM in Azure IAAS
    uUtil.execCommand(["yum", "-y", "-e", "0", "install"] + httpd_rpms, retries=5)

    def tweak_httpd(inf, outf):
        conf_orig = inf.read()
        conf_1 = re.sub("ServerLimit.*10", "ServerLimit 256", conf_orig)
        conf_2 = re.sub("MaxClients.*10", "MaxClients 256", conf_1)
        outf.write(conf_2)
    prefork_conf = '/etc/httpd/conf/httpd.conf'
    if os.path.exists('/etc/httpd/conf.d/mpm_prefork.conf'):
        prefork_conf = '/etc/httpd/conf.d/mpm_prefork.conf'
    uUtil.editFileSafe(prefork_conf, tweak_httpd, prefork_conf + '.save')

    # drop the /icons/ alias; =<2.2.*: tweak httpd.conf, >=2.4.*: rename autoindex.conf
    if os.path.exists('/etc/httpd/conf.d/autoindex.conf'):
        uUtil.moveFile('/etc/httpd/conf.d/autoindex.conf', '/etc/httpd/conf.d/autoindex.conf.save')
    else:
        uUtil.replaceInFile('/etc/httpd/conf/httpd.conf', r'(?m)^\s*Alias\s+\/icons\/\s+', '#Alias /icons/ ', True)

    service_control('restart', 'httpd')
    service_autostart('httpd')

    if platform.osver == "7":
        def tweak_journald(inf, outf):
            conf_orig = inf.read()
            conf_1 = re.sub('#RateLimitInterval.*s', 'RateLimitInterval=0', conf_orig)
            conf_2 = re.sub('#Storage=auto', 'Storage=none', conf_1)
            conf_3 = re.sub('#ForwardToSyslog=no', 'ForwardToSyslog=yes', conf_2)
            outf.write(conf_3)
        journald_conf = '/etc/systemd/journald.conf'
        uUtil.editFileSafe(journald_conf, tweak_journald, journald_conf + '.save')

        def tweak_rsyslog(inf, outf):
            conf_orig = inf.read()
            conf_1 = re.sub('\$ModLoad imjournal', '#$ModLoad imjournal', conf_orig)
            conf_2 = re.sub('\$IMJournalStateFile imjournal.state', '#$IMJournalStateFile imjournal.state', conf_1)
            conf_3 = re.sub('\$OmitLocalLogging on', '$OmitLocalLogging off', conf_2)
            outf.write(conf_3)
        rsyslog_conf = '/etc/rsyslog.conf'
        uUtil.editFileSafe(rsyslog_conf, tweak_rsyslog, rsyslog_conf + '.save')

        def tweak_unix_datagram_query_len(inf, outf):
            """Tweak unix datagram query length for properly forwarding logs from journald to rsyslog"""
            conf_orig = inf.read()
            qlen_regex = re.compile('\nnet\.unix\.max_dgram_qlen.*')
            if qlen_regex.search(conf_orig):
                conf_modified = qlen_regex.sub('\nnet.unix.max_dgram_qlen=500', conf_orig)
            else:
                conf_modified = conf_orig + "\nnet.unix.max_dgram_qlen=500\n"
            outf.write(conf_modified)

        sysctl_conf = "/etc/sysctl.conf"
        uUtil.editFileSafe(sysctl_conf, tweak_unix_datagram_query_len, sysctl_conf + ".save")

        # Restart all tweaked services
        service_control('restart', 'systemd-journald')
        service_control('restart', 'rsyslog')
        uUtil.execCommand(["sysctl", "-p"], [0, 255])