import subprocess from tempfile import mkstemp #Define vars capbasedir = "/var/lib/lliurex-cap" lockdir = os.path.join(capbasedir,capname,"locks") # Get servers without user lock self.sysloger.debug("[lliurex-listener-logoutscripts] : Launch lliurex-cap list-servers " + capname) pexecute = subprocess.Popen(["lliurex-cap","list-servers",capname],stdout=subprocess.PIPE) auxservers = pexecute.stdout.readline().split(' ') while '' in auxservers: auxservers.remove('') servers = [] for n in auxservers: try : servers.append(n.split("@")[1]) except: self.sysloger.error("[lliurex-listener-logoutscripts] : lliurex-cap list-servers return " + n + " and this haven't correct format") while '' in servers: servers.remove('') auxs = " ".join(servers) self.sysloger.debug("[lliurex-listener-logoutscripts] : servers of CAP "+ auxs) serverswithlock = os.listdir(lockdir) for servername in serverswithlock: if os.path.isdir(os.path.join(lockdir,servername)): if os.path.exists(os.path.join(lockdir,servername,username)) : self.sysloger.warning("[lliurex-listener-logoutscripts] : user " + username + " is locked on " + servername + " this client isn't sync") if servername in servers : servers.remove(servername) continue # Get user group pexecute = subprocess.Popen(["groups",username],stdout=subprocess.PIPE) group = pexecute.stdout.readline().split(' ')[2] if not hasattr(self,'hostname'): paux = subprocess.Popen(["llxcfg-showvars","SRV_HOST_ID"],stdout = subprocess.PIPE,stderr = subprocess.PIPE) cnaux = paux.stdout.readline() if len(cnaux) == 0: self.sysloger.error("[lliurex-listener] : CAP_ZERO_CAPNAME is not defined ") sys.exit(1) else: srvhostid = cnaux.split('=')[1] srvhostid = str(srvhostid[1:-3]) self.hostname = "node-"+srvhostid+"."+capname+".cap" os.remove(os.path.join(lockdir ,self.hostname ,username)) if group != "": self.sysloger.debug("[lliurex-listener-logoutscripts] : User " + username + "has group " + group) # Launch command that resolve conflicts auxfilepath = mkstemp()[1] auxfile = open(auxfilepath,'w') auxfile.write(",".join(servers)) auxfile.close() self.sysloger.info("[lliurex-listener-logoutscripts] : Launch lliurex-cap sync-with-rconflict " + capname + " data /net/home/" + group + "/" + username + " " + auxfilepath) pexecute = subprocess.Popen(["lliurex-cap","sync-with-rconflict",capname,"data","/net/home/"+group+"/"+username,auxfilepath],stdout=subprocess.PIPE) # Remove lock in this server and propagate self.sysloger.info("[lliurex-listener-logoutscripts] : Launch lliurex-cap sync-with-rconflict "+capname+" lock") pexecute = subprocess.Popen(["lliurex-cap","sync-with-rconflict",capname,"lock"],stdout=subprocess.PIPE) else : self.sysloger.warning("[lliurex-listener-logoutscripts] : user " + username + " haven't group")