Package actions :: Module rhnsd
[hide private]
[frames] | no frames]

Source Code for Module actions.rhnsd

 1  #!/usr/bin/python2 
 2   
 3  # Copyright (c) 1999--2018 Red Hat, Inc.  Distributed under GPLv2. 
 4  # 
 5  # Author: Adrian Likins <alikins@redhat.com> 
 6  # 
 7   
 8  import os 
 9   
10  # mark this module as acceptable 
11  __rhnexport__ = [ 
12      'configure', 
13  ] 
14   
15 -def __configRhnsd(interval, cache_only=None):
16 rhnsdconfig = "/etc/sysconfig/rhn/rhnsd" 17 fd = open(rhnsdconfig, "r") 18 lines = fd.readlines() 19 count = 0 20 index = None 21 tmplines = [] 22 for line in lines: 23 tmp = line.strip() 24 tmplines.append(tmp) 25 comps = tmp.split("=", 1) 26 if comps[0] == "INTERVAL": 27 index = count 28 count = count + 1 29 30 if index != None: 31 tmplines[index] = "INTERVAL=%s" % interval 32 33 fd.close() 34 fd = open(rhnsdconfig, "w") 35 contents = "\n".join(tmplines) 36 fd.write(contents) 37 fd.close()
38 39
40 -def configure(interval=None, restart=None, cache_only=None):
41 if cache_only: 42 return (0, "no-ops for caching", {}) 43 msg = "" 44 if interval: 45 try: 46 __configRhnsd(interval) 47 msg = "rhnsd interval config updated. " 48 except IOError: 49 # i'm runing as root, must of been chattr'ed. 50 # i'll resist the erge to unchattr this file 51 return (37,"Could not modify /etc/sysconfig/rhn/rhnsd", {}) 52 53 if restart: 54 rc = os.system("/sbin/service rhnsd restart > /dev/null") 55 msg = msg + "rhnsd restarted" 56 57 return(0, msg, {})
58 59 60 if __name__ == "__main__": 61 print(configure("240")) 62 63 print(configure("361", 1)) 64 65 print(configure("127", restart=1)) 66 67 print(configure(restart=1)) 68 69 print(configure("192")) 70