- #! /usr/bin/python2
- import os
- # the list of required services
- req_services = ["autofs",
- "crond",
- "irqbalance",
- "keytable",
- "microcode_ctl",
- "netfs",
- "network",
- "nfslock",
- "ntpd",
- "random",
- "rawdevices",
- "sshd",
- "syslog",
- "xfs"]
- if __name__=="__main__":
- # get all services currently running on the system
- services_running = os.popen('/sbin/chkconfig --list')
- service_list = []
- for line in services_running.readlines():
- line = line.strip()
- if len(line) > 50:
- print line
- cols = line.split()
- service_list.append(cols[0])
- # close the input file
- services_running.close()
- # turn off all services
- command_service_off = "chkconfig %s off"
- for service in service_list:
- cmd = command_service_off % (service)
- # commands.getstatusoutput(cmd)
- print cmd
- # turn on the required services
- command_service_on = "chckconfig --levels 35 %s on"
- for service in req_services:
- cmd = command_service_on % (service)
- # commands.getstatusoutput(cmd)
- print cmd
Raw Paste