X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lxcsu;h=dc75b71f2cc2ee4eed6852479a1a3235ab0fc5c1;hb=c3919302e3d43fee4278400414fce0f0cbd9bf66;hp=4f4a2f7ca57b63b03fbeb8e395e773e32bb85889;hpb=b6f35c7cb1502c0af36f6c3055149574a4964925;p=lxc-userspace.git diff --git a/lxcsu b/lxcsu index 4f4a2f7..dc75b71 100755 --- a/lxcsu +++ b/lxcsu @@ -84,43 +84,18 @@ def main (): debug=True try: - cmd = 'grep %s /proc/*/cgroup | grep freezer'%slice_name - output = os.popen(cmd).readlines() + cmd = '/usr/bin/virsh --connect lxc:/// domid %s'%slice_name + pidnum = int(os.popen(cmd).read().rstrip()) except: print "Error finding slice %s"%slice_name exit(1) - slice_spec = None + pid = '%s'%pidnum + if debug: print "Found pidnum",pidnum + cmdline = open('/proc/%s/cmdline'%pidnum).read().rstrip('\n\x00') + arch = getarch('/proc/%s/exe'%pid) - # provide a default as this is not always properly computed - arch = None - - for e in output: - try: - l = e.rstrip() - path = l.split(':')[0] - comp = l.rsplit(':')[-1] - slice_name_check = comp.rsplit('/')[-1] - if debug: print "dealing with >%s<"%slice_name_check - - if (slice_name_check == slice_name): - if debug: print "found %s"%slice_name - slice_path = path - pid = slice_path.split('/')[2] - cmdline = open('/proc/%s/cmdline'%pid).read().rstrip('\n\x00') - if (cmdline == '/sbin/init') or (cmdline.startswith("init [")): - slice_spec = slice_path - arch = getarch('/proc/%s/exe'%pid) - break - except Exception,e: - if debug: - import traceback - print "BEG lxcsu - ignoring exception" - traceback.print_exc() - print "END lxcsu - ignoring exception" - pass - - if (not slice_spec or not pid): + if (not pid): print "Not started: %s"%slice_name exit(1) @@ -145,13 +120,15 @@ def main (): for subsystem in ['cpuset','memory','blkio']: open('/sys/fs/cgroup/%s/libvirt/lxc/%s/tasks'%(subsystem,slice_name),'w').write(str(os.getpid())) - except: + except Exception,e: + if debug: print e print "Error assigning resources: %s"%slice_name exit(1) try: open('/sys/fs/cgroup/cpuacct/system/libvirtd.service/libvirt/lxc/%s/tasks'%slice_name,'w').write(str(os.getpid())) - except: + except Exception,e: + if debug: print e print "Error assigning cpuacct: %s" % slice_name exit(1) @@ -165,7 +142,8 @@ def main (): # note: we need to call f.close() explicitly, or we'll get an exception in # the object destructor, which will not be caught f.close() - except: + except Exception,e: + if debug: print e print "Error adding task to freezer cgroup. Slice is probably frozen: %s" % slice_name exit(1) @@ -189,7 +167,7 @@ def main (): for (sysctl_file, sysctl_name, sysctl_val) in sysctls: for fn in ["/sbin/sysctl", "/usr/sbin/sysctl", "/bin/sysctl", "/usr/bin/sysctl"]: if os.path.exists(fn): - os.system('%s -w %s=%s'%(fn, sysctl_name,sysctl_val)) + os.system('%s -w %s=%s >/dev/null 2>&1'%(fn, sysctl_name,sysctl_val)) break else: print "Error: image does not have a sysctl binary"