Changeset 1741 for trunk/server/common


Ignore:
Timestamp:
Nov 22, 2010, 5:59:19 AM (13 years ago)
Author:
mitchb
Message:
Make whoisd resilient against LDAP service interruptions

Fixes Trac #146
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/server/common/oursrc/whoisd/whoisd.tac

    r772 r1741  
    6565#            return vhost + ".mit.edu"
    6666    def searchLDAP(self, vhost):
    67         results = self.ldap.search_s(self.ldap_base, ldap.SCOPE_SUBTREE,
     67        results = self.ldap.search_st(self.ldap_base, ldap.SCOPE_SUBTREE,
    6868            ldap.filter.filter_format(
    69                 '(|(apacheServername=%s)(apacheServerAlias=%s))', (vhost,)*2))
     69                '(|(apacheServername=%s)(apacheServerAlias=%s))', (vhost,)*2),
     70                timeout=5)
    7071        if len(results) >= 1:
    7172            result = results[0]
     
    8485        vhost = self.canonicalize(vhost)
    8586        info = self.vhosts.get(vhost)
    86         if not info:
    87             info = self.searchLDAP(vhost)
     87        tries = 0
     88        while (tries < 3) and not info:
     89            tries += 1
     90            try:
     91                info = self.searchLDAP(vhost)
     92            except (ldap.TIMEOUT, ldap.SERVER_DOWN):
     93                self.ldap.unbind()
     94                self.ldap = ldap.initialize(self.ldap_URL)
    8895        if info:
    8996            ret = "Hostname: %s\nAlias: %s\nLocker: %s\nDocument Root: %s" % \
    9097                (info['apacheServerName'], vhost, info['locker'], info['apacheDocumentRoot'])
     98        elif tries == 3:
     99            ret = "The whois server is experiencing problems looking up LDAP records.\nPlease contact scripts@mit.edu for help if this problem persists."
    91100        else:
    92101            ret = "No such hostname"
Note: See TracChangeset for help on using the changeset viewer.