#!/usr/bin/env python import ldap import os import sys import subprocess import time log_file = '/run/ldapcheck.log' class LDAPCHECK: def __init__(self): print "[LDAPCHECK] Init" self.ready=False self.count=0 #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('dc=ma5,dc=lliurex,dc=net',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