def httpd_config_test(httpd_processes): """For each httpd instance, run a configtest""" for v in httpd_processes: apache_status = (shared.run_command([v, "-S"], return_retcode=True)) if apache_status[1] != 0: print_msg("Apache {0} is reporting a config error".format(v), "FAIL")
def get_sysv_enabled(): """Return list of sysv enabled services""" sysv_enabled = [] if os.path.isfile('/sbin/chkconfig'): output = shared.run_command(['chkconfig', '--list']) for line in output: if "3:on" in line: sysv_enabled.append(line.split()[0]) return sysv_enabled
def get_systemd_enabled(): """Return list of systemctl enabled service units""" systemd_enabled = [] if os.path.isfile('/bin/systemctl'): output = shared.run_command(['systemctl', 'list-unit-files']) for unit in output: if "service" in unit and "enabled" in unit: systemd_enabled.append(unit.split()[0].split('.service')[0]) return systemd_enabled
def get_fstab(): """Parse fstab for filesystems that get mounted at boot time""" fstabmounts = open("/etc/fstab").readlines() fstabentries = [(f.split()[0], f.split()[1]) for f in fstabmounts if len(f) > 2 and not f.split()[0].startswith("#")] # Convert UUIDs to block devices for i, v in enumerate(fstabentries): if v[0].startswith("UUID"): uuid = (v[0].split("=")[1]) fstabentries[i] = (shared.run_command(['blkid', '-U', uuid])[0].rstrip(), v[1]) return fstabentries
def get_listening_services(): """Return set of networking listening services""" netstat = shared.run_command(['/bin/netstat', '-tlnp']) listening_services = set() for line in netstat: if line.startswith('tcp'): process = line.split()[6] # Renamne e.g. nimbus(cdm) to nimbus if "(" in process: process = process.split('(')[0] if process != "-": listening_services.add(process.split('/')[1]) return listening_services
def is_running(): """Check if a process httpd is running, and return its path""" plist = shared.run_command(["pgrep", "-a", "httpd"]) return {v.split()[1] for v in plist}