PYTHON   100
set node services py
Guest on 10th February 2023 01:47:48 AM


  1. #! /usr/bin/python2
  2.  
  3. import os
  4.  
  5. # the list of required services
  6. req_services = ["autofs",
  7.                 "crond",
  8.                 "irqbalance",
  9.                 "keytable",
  10.                 "microcode_ctl",
  11.                 "netfs",      
  12.                 "network",    
  13.                 "nfslock",
  14.                 "ntpd",      
  15.                 "random",    
  16.                 "rawdevices",
  17.                 "sshd",    
  18.                 "syslog",    
  19.                 "xfs"]
  20.  
  21. if __name__=="__main__":
  22.     # get all services currently running on the system
  23.     services_running = os.popen('/sbin/chkconfig --list')
  24.     service_list = []
  25.     for line in services_running.readlines():
  26.         line = line.strip()
  27.         if len(line) > 50:
  28.             print line
  29.             cols = line.split()
  30.             service_list.append(cols[0])
  31.     # close the input file
  32.     services_running.close()
  33.  
  34.     # turn off all services
  35.     command_service_off = "chkconfig %s off"
  36.     for service in service_list:
  37.         cmd = command_service_off % (service)
  38.         # commands.getstatusoutput(cmd)
  39.         print cmd
  40.  
  41.     # turn on the required services
  42.     command_service_on = "chckconfig --levels 35 %s on"
  43.     for service in req_services:
  44.         cmd = command_service_on % (service)
  45.         # commands.getstatusoutput(cmd)
  46.         print cmd

Raw Paste

Login or Register to edit or fork this paste. It's free.