#!/usr/bin/env python import ldap import os import sys import subprocess import time log_file = '/tmp/ldapcheck.log' class LDAPCHECK: def __init__(self): print "[LDAPCHECK] Init" self.ready=False self.count=0 ''' p1=subprocess.Popen(["llxcfg-listvars","--values"],stdout=subprocess.PIPE) p2=subprocess.Popen(["grep","LDAP"],stdin=p1.stdout,stdout=subprocess.PIPE) output=p2.communicate()[0] output=output.replace("'","") tmp1=output.split(';\n') self.ldap_vars={} for item in tmp1: tmp2=item.split('=',1) if len(tmp2)>1: self.ldap_vars[tmp2[0]]=tmp2[1] ''' #def __init__ def connect(self): f = open(log_file,'a') f.write("[LDAPCHECK] [Try %d] Connecting to ldap...\n"%(self.count+1)) try: self.l=ldap.open('localhost',port=389) test=self.l.search_s('',ldap.SCOPE_SUBTREE,'(cn=admin)') f.write("[LDAPCHECK] LDAP Ready\n") self.ready=True except: f.write("[LDAPCHECK] LDAP not ready\n") f.close() #def connect #class LDAPCHECK if __name__=="__main__": if not os.path.exists(log_file): ldapcheck = LDAPCHECK() while(not ldapcheck.ready): if ldapcheck.count < 5: ldapcheck.connect() ldapcheck.count+=1 if not ldapcheck.ready: time.sleep(2) else: ldapcheck.ready=True