Esempio n. 1
0
def unregister(p_repo, p_isJSON):
  [repo_type, name, url, package, key, repo_filter] = get_repo(p_repo, p_isJSON)

  if util.get_os() in YUM_LIST:
    util.run_sudo("yum remove -y " + name, True, p_isJSON)
    return 0

  util.exit_message("UNREGISTER command not supported on this OS", 1, p_isJSON)
Esempio n. 2
0
def remove_linux(p_systemsvc, p_pgver):
    my_home = os.getenv("MY_HOME")
    pg_bin_dir = os.path.join(my_home, p_pgver, 'bin')
    util.remove_symlinks("/usr/bin", pg_bin_dir)

    util.run_sudo("systemctl disable " + p_systemsvc)
    util.run_sudo("rm -f " + os.path.join(util.get_systemd_dir(), p_systemsvc +
                                          ".service"))
    return (0)
Esempio n. 3
0
def config_linux(p_comp,
                 p_systemsvc,
                 p_svc_user,
                 p_start,
                 p_start_log,
                 p_stop,
                 p_reload,
                 p_status="",
                 is_pg=True,
                 p_env=None):

    my_home = os.getenv("MY_HOME")

    pg_bin_dir = os.path.join(my_home, p_comp, 'bin')
    util.create_symlinks("/usr/bin", pg_bin_dir)

    sys_svc_file = os.path.join(util.get_systemd_dir(),
                                p_systemsvc + ".service")

    print(p_comp + " config autostart " + sys_svc_file)

    ## systemD ################################
    unit_file = tempfile.mktemp(".service")
    fh = open(unit_file, "w")
    fh.write("[Unit]\n")
    fh.write("Description=PostgreSQL (" + p_comp + ")\n")
    if is_pg:
        fh.write("After=syslog.target\n")
    fh.write("After=network.target\n")
    fh.write("\n")
    fh.write("[Service]\n")
    if p_env:
        fh.write("Environment=" + p_env + "\n")
    if is_pg:
        fh.write("Type=forking\n")
    fh.write("User="******"\n")
    if is_pg:
        fh.write("\n")
        fh.write("OOMScoreAdjust=-1000\n")
    fh.write("ExecStart=" + p_start + "\n")
    if p_stop != "":
        fh.write("ExecStop=" + p_stop + "\n")
    fh.write("ExecReload=" + p_reload + "\n")
    if is_pg:
        fh.write("TimeoutSec=300\n")
    fh.write("\n")
    fh.write("[Install]\n")
    fh.write("WantedBy=multi-user.target\n")
    fh.close()

    util.run_sudo("mv " + unit_file + " " + sys_svc_file)

    return (util.run_sudo("systemctl enable " + p_systemsvc))
Esempio n. 4
0
def useradd_linux(p_user):
    print("Creating the user " + p_user)
    if not util.get_platform() == "Linux":
        print("ERROR: USERADD is a Linux only command.")
        return (1)

    if not util.is_admin():
        print("ERROR: Must be ROOT to run USERADD.")
        return (1)

    ## make sure the user exists....
    util.run_sudo("useradd -m " + p_user)

    return (0)
Esempio n. 5
0
def remove_packages(p_repo, p_pkg_list, p_isJSON):
    if not is_repo(p_repo, p_isJSON):
        util.exit_message(p_repo + " is not a valid REPO.", 1)

    os = util.get_os()
    if os == "el6":
        cmd = "yum --enablerepo=" + p_repo + " remove -y"
    elif os == "el7":
        cmd = "yum repo-pkgs " + p_repo + " remove -y"
    else:
        cmd = "apt-get remove -y"
    for pl in p_pkg_list:
        cmd = cmd + " " + str(pl)
    util.run_sudo(cmd, True, p_isJSON)
    return 0
Esempio n. 6
0
def run_salt_cmd(p_salt_cmd, p_cmd, p_isJSON):
    try:
        import salt
    except ImportError as e:
        util.exit_message("Missing SaltStack", 1, p_isJSON)

    config = os.path.join("data", "pgdevops", "etc")
    config_dir = os.path.join(os.getenv("PGC_HOME"), config)
    if not os.path.exists(config_dir):
        util.exit_message("Missing CONFIG_DIR: " + config, 1, p_isJSON)

    cmd = p_cmd + " -c " + config_dir

    if p_isJSON:
        cmd = cmd + " --out=json"

    util.run_sudo(p_salt_cmd + " " + cmd, True)
Esempio n. 7
0
def register(p_repo, p_isJSON):
  [repo_type, name, url, package, key, repo_filter] = get_repo(p_repo, p_isJSON)

  if util.get_os() in YUM_LIST:
    repo_pkg = url + "/" + package
    util.run_sudo("yum install -y " + repo_pkg, True, p_isJSON)
    return 0

  ## APT ################
  a_file = "/etc/apt/sources.list.d/pgdg.list"
  a_repo = "http://apt.postgresql.org/pub/repos/apt/"
  cmd = '"deb ' + a_repo + ' ' + p_repo + ' main" > ' + a_file
  util.run_sudo("sh -c 'echo " + cmd + "'", True, p_isJSON)

  a_key = "https://www.postgresql.org/media/keys/ACCC4CF8.asc"
  cmd = "wget --quiet -O - " + a_key + " | sudo apt-key add -"
  util.run_sudo(cmd, True, p_isJSON)
  util.run_sudo("apt-get update", True, p_isJSON)
  
  return 0
Esempio n. 8
0
def stop_linux(p_systemsvc):
    return (util.run_sudo("systemctl stop  " + p_systemsvc))
Esempio n. 9
0
def reload_linux(p_systemsvc):
    return (util.run_sudo("systemctl reload " + p_systemsvc))
Esempio n. 10
0
def config_linux(p_comp,
                 p_systemsvc,
                 p_S,
                 p_K,
                 p_svc_user,
                 p_start,
                 p_start_log,
                 p_stop,
                 p_reload,
                 p_status="",
                 is_pg=True,
                 p_env=None):

    pgc_home = os.getenv("PGC_HOME")

    if util.is_systemd():
        sys_svc_file = os.path.join(util.get_systemd_dir(),
                                    p_systemsvc + ".service")
    else:
        sys_svc_file = os.path.join("/etc/init.d", p_systemsvc)

    print(p_comp + " config autostart " + sys_svc_file)

    if not util.is_systemd():
        svcfile = os.path.join(pgc_home, p_comp, p_systemsvc)
        write_sysv_svcfile(svcfile, p_systemsvc, p_S, p_K, p_svc_user, p_start,
                           p_start_log, p_stop, p_reload, p_status)
        rc = util.run_sudo("ln -sf " + svcfile + " " + sys_svc_file)

        link_cmd = "ln -sf ../init.d/" + p_systemsvc + "  "
        util.run_sudo(link_cmd + "/etc/rc0.d/K" + p_K + p_systemsvc)
        util.run_sudo(link_cmd + "/etc/rc1.d/K" + p_K + p_systemsvc)
        util.run_sudo(link_cmd + "/etc/rc2.d/S" + p_S + p_systemsvc)
        util.run_sudo(link_cmd + "/etc/rc3.d/S" + p_S + p_systemsvc)
        util.run_sudo(link_cmd + "/etc/rc4.d/S" + p_S + p_systemsvc)
        util.run_sudo(link_cmd + "/etc/rc5.d/S" + p_S + p_systemsvc)
        rc = util.run_sudo(link_cmd + "/etc/rc6.d/K" + p_K + p_systemsvc)
        return (rc)

    ## systemD ################################
    unit_file = tempfile.mktemp(".service")
    fh = open(unit_file, "w")
    fh.write("[Unit]\n")
    fh.write("Description=PostgreSQL (" + p_comp + ")\n")
    if is_pg:
        fh.write("After=syslog.target\n")
    fh.write("After=network.target\n")
    fh.write("\n")
    fh.write("[Service]\n")
    if p_env:
        fh.write("Environment=" + p_env + "\n")
    if is_pg:
        fh.write("Type=forking\n")
    fh.write("User="******"\n")
    if is_pg:
        fh.write("\n")
        fh.write("OOMScoreAdjust=-1000\n")
    fh.write("ExecStart=" + p_start + "\n")
    if p_stop != "":
        fh.write("ExecStop=" + p_stop + "\n")
    fh.write("ExecReload=" + p_reload + "\n")
    if is_pg:
        fh.write("TimeoutSec=300\n")
    fh.write("\n")
    fh.write("[Install]\n")
    fh.write("WantedBy=multi-user.target\n")
    fh.close()

    util.run_sudo("mv " + unit_file + " " + sys_svc_file)

    return (util.run_sudo("systemctl enable " + p_systemsvc))
Esempio n. 11
0
def remove_linux(p_systemsvc, p_S, p_K):
    if util.is_systemd():
        util.run_sudo("systemctl disable " + p_systemsvc)
        util.run_sudo("rm -f " +
                      os.path.join(util.get_systemd_dir(), p_systemsvc +
                                   ".service"))
        return (0)

    ## sysV #####################################
    cmd = "rm -f "
    util.run_sudo(cmd + "/etc/rc0.d/K" + p_K + p_systemsvc)
    util.run_sudo(cmd + "/etc/rc1.d/K" + p_K + p_systemsvc)
    util.run_sudo(cmd + "/etc/rc2.d/S" + p_S + p_systemsvc)
    util.run_sudo(cmd + "/etc/rc3.d/S" + p_S + p_systemsvc)
    util.run_sudo(cmd + "/etc/rc4.d/S" + p_S + p_systemsvc)
    util.run_sudo(cmd + "/etc/rc5.d/S" + p_S + p_systemsvc)
    util.run_sudo(cmd + "/etc/rc6.d/K" + p_K + p_systemsvc)

    rc = util.run_sudo("rm -f /etc/init.d/" + p_systemsvc)
    return (rc)
Esempio n. 12
0
def reload_linux(p_systemsvc):
    if util.is_systemd():
        return (util.run_sudo("systemctl reload " + p_systemsvc))
    else:
        return (util.run_sudo("service " + p_systemsvc + " reload"))
Esempio n. 13
0
def stop_linux(p_systemsvc):
    if util.is_systemd():
        return (util.run_sudo("systemctl stop  " + p_systemsvc))
    else:
        return (util.run_sudo("service " + p_systemsvc + " stop"))