示例#1
0
def check_filesync_servers():
  if 'runserver' in sys.argv:
    # This may be run by multiple threads
    # but its ok tho tho  b/c this threads 
    # purpose is just to check 
    # whether servers are alive or not. 
    # Basically its idempotent.

    # Checking health of known servers
    # in efforts to clean up old entries
    for host in Host.objects.all():
      time.sleep(1)
      print 'checking %s' % host
      method = 'ruok'
      url = '/'.join(['http:/',host.hostname,method])
      print url
      try:
        print urllib.urlopen(url).read()
      except IOError:
        print 'Got IOError when checking %s, will delete' % host.hostname
        # so lets consider him dead
        try:
          Host.objects.filter(hostname=host.hostname).get().delete()
        except Host.DoesNotExist:
          # Hes already been removed, no biggie
          pass 

    # XXX Causes *lots* of chatter but seems to work...
    # Change of host list so lets send out an update
    #print 'timer ticked, and we removed a host, lets update group'
    fns_utils.announce_hostlist()

    # And play it again sam...
    t = threading.Timer(30, check_filesync_servers).start()
示例#2
0
def addhost(request, hn):
  str_out = 'Adding host %s ' % hn

  # We dont want duplicate entries in our db
  # so make this function idempotent for add's

  if len(Host.objects.filter(hostname=hn)) < 1:
    print 'adding new host %s ' % hn
    Host(hostname=hn).save()
  else:
    print 'Already know about host %s, wont add' % hn

  # Announce updated list
  #print 'adding host lets update group'
  fns_utils.announce_hostlist()

  return HttpResponse(str_out, mimetype="text/plain")