Example #1
0
def run(sock):
  global APP_Pending, APP_Status
  # run application status, if it exists
  if not APP_Pending:
    cmd = lyconf.Config.script_dir + '/status'
    if os.access(cmd, os.F_OK | os.X_OK):
       LOG.debug("exec: %s" % cmd)
       APP_Pending['status'] =  subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  if APP_Pending.has_key('status'):
    p = APP_Pending['status']
    s = p.poll()
    if s == None:
      return
    del APP_Pending['status']
    LOG.debug("status output:")
    for o in p.stdout.readlines():
      LOG.debug(o)
    if s < 0:
      return
    s += lydef.LY_S_APP_RUNNING;
    if s != APP_Status:
      LOG.info("status return code: %d" % s)
      d = struct.pack('i', s)
      lyutil.socksend(sock, lydef.PKT_TYPE_OSM_REPORT, d)
      APP_Status = s 
Example #2
0
def procOSMQuery(sock, datalen, data):
  l = struct.calcsize("i")
  if datalen != l or len(data) != l:
    LOG.error("wrong OSM query packet")
    return 1
  lyutil.socksend(sock, PKT_TYPE_CLC_OSM_QUERY_REPLY,
                  "%s %d %d %s" % (data, lyconf.Config.tag, lyconf.Config.status, lyconf.Config.local_ip))
  return 0
Example #3
0
def procOSMQuery(sock, datalen, data):
    l = struct.calcsize("i")
    if datalen != l or len(data) != l:
        LOG.error("wrong OSM query packet")
        return 1
    lyutil.socksend(
        sock, lydef.PKT_TYPE_CLC_OSM_QUERY_REPLY,
        "%s %d %d %s" % (data, lyconf.Config.tag, lyconf.Config.status,
                         lyconf.Config.local_ip))
    return 0
Example #4
0
def run(sock = None, notify = 0):
  global APP_Status
  ret = 0
  s, p = runcmd('status')
  if s != None:
    ret = 1
    if s < 0:
      LOG.debug("status unknown")
      s = lydef.LY_S_APP_UNKNOWN
    elif s > 0:
      LOG.info("status output:")
      for o in p.stdout.readlines():
        LOG.info(o)
      s += lydef.LY_S_APP_RUNNING
    else:
      s = lydef.LY_S_APP_RUNNING
    if s != APP_Status or notify:
      LOG.info("status return code: %d" % s)
      if sock:
        d = struct.pack('i', s)
        if lyutil.socksend(sock, lydef.PKT_TYPE_OSM_REPORT, d) < 0:
          ret = -1
      APP_Status = s
  return ret
Example #5
0
def run(sock=None, notify=0):
    global APP_Status
    ret = 0
    s, p = runcmd('status')
    if s != None:
        ret = 1
        if s < 0:
            LOG.debug("status unknown")
            s = lydef.LY_S_APP_UNKNOWN
        elif s > 0:
            LOG.info("status output:")
            for o in p.stdout.readlines():
                LOG.info(o)
            s += lydef.LY_S_APP_RUNNING
        else:
            s = lydef.LY_S_APP_RUNNING
        if s != APP_Status or notify:
            LOG.info("status return code: %d" % s)
            if sock:
                d = struct.pack('i', s)
                if lyutil.socksend(sock, lydef.PKT_TYPE_OSM_REPORT, d) < 0:
                    ret = -1
            APP_Status = s
    return ret
Example #6
0
                        LY_OSM_KEEPALIVE_PROBES)
        sock.setblocking(0)
    except socket.error, (value, message):
        LOG.warn(message)
        if sock:
            sock.close()
        return None
    lyconf.Config.local_ip = sock.getsockname()[0]
    if not lyconf.Config.local_ip:
        lyconf.Config.local_ip = b'empty'

    try:
        LOG.info("send auth request %d" % tag)
        data = struct.pack("i%ds" % lydef.LUOYUN_AUTH_DATA_LEN, tag,
                           challengestr)
        lyutil.socksend(sock, lydef.PKT_TYPE_OSM_AUTH_REQUEST, data)

        LOG.info("recv auth reply")
        recvsize = struct.calcsize("=LLi%ds" % lydef.LUOYUN_AUTH_DATA_LEN)
        result, response = lyutil.sockrecv(sock)
        if result == -1 or len(response) != recvsize:
            LOG.error("error in sockrecv")
            return None
        if result == 0:
            LOG.error("socket closed")
            return None
        t, l, rettag, answer = struct.unpack(
            "=LLi%ds" % lydef.LUOYUN_AUTH_DATA_LEN, response)
        if t != lydef.PKT_TYPE_OSM_AUTH_REPLY:
            LOG.error("wrong auth reply %d" % t)
            return None
Example #7
0
    sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPINTVL, LY_OSM_KEEPALIVE_INTVL)
    sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPCNT, LY_OSM_KEEPALIVE_PROBES)
    sock.setblocking(0)
  except socket.error, (value,message): 
    LOG.warn(message)
    if sock: 
        sock.close()
    return None 
  lyconf.Config.local_ip = sock.getsockname()[0]
  if not lyconf.Config.local_ip:
    lyconf.Config.local_ip = b'empty'

  try:
    LOG.info("send auth request %d" % tag)
    data = struct.pack("i%ds" % lydef.LUOYUN_AUTH_DATA_LEN, tag, challengestr)
    lyutil.socksend(sock, lydef.PKT_TYPE_OSM_AUTH_REQUEST, data)

    LOG.info("recv auth reply")
    recvsize = struct.calcsize("=LLi%ds" % lydef.LUOYUN_AUTH_DATA_LEN);
    result, response = lyutil.sockrecv(sock)
    if result == -1 or len(response) != recvsize:
      LOG.error("error in sockrecv")
      return None 
    if result == 0:
      LOG.error("socket closed")
      return None
    t, l, rettag, answer = struct.unpack("=LLi%ds" % lydef.LUOYUN_AUTH_DATA_LEN, response)
    if t != lydef.PKT_TYPE_OSM_AUTH_REPLY:
      LOG.error("wrong auth reply %d" % t)
      return None
    if rettag != tag: