Пример #1
0
 def __init__ (self, script, id):
   self.id = id
   self.script = script
   host = getHostNameShort()
   port = int(script.cfg["STREAM_RECV_PORT"]) + int(id)
   self.script.log (0, "ConfiguringThread listening on " + host + ":" + str(port))
   ReportingThread.__init__(self, script, host, port)
Пример #2
0
  def main (self):

    # open a listening socket to receive the data files to read
    hostname = getHostNameShort()

    # get the site configurationa
    config = Config()

    # prepare header using configuration file parameters
    fixed_config = config.getStreamConfigFixed(self.id)

    db_prefix = self.cfg["DATA_BLOCK_PREFIX"]
    db_id = self.cfg["RECEIVING_DATA_BLOCK"]
    num_stream = self.cfg["NUM_STREAM"]
    db_key = SMRBDaemon.getDBKey (db_prefix, stream_id, num_stream, db_id)

    cmd = "dada_diskdb -k " + db_key + " -z -s " + \
          "-f /data/spip/first_light/single_dish/2016-04-28-13:27:30_0000000000000000.000000.dada" + \
          "-f /data/spip/first_light/single_dish/2016-04-28-13:27:30_0000000000000000.000000.dada" + \
          "-f /data/spip/first_light/single_dish/2016-04-28-13:27:30_0000034359738368.000000.dada" + \
          "-f /data/spip/first_light/single_dish/2016-04-28-13:27:30_0000068719476736.000000.dada" + \
          "-f /data/spip/first_light/single_dish/2016-04-28-13:27:30_0000103079215104.000000.dada" + \
          "-f /data/spip/first_light/single_dish/2016-04-28-13:27:30_0000137438953472.000000.dada" + \
          "-f /data/spip/first_light/single_dish/2016-04-28-13:27:30_0000171798691840.000000.dada" + \
          "-f /data/spip/first_light/single_dish/2016-04-28-13:27:30_0000206158430208.000000.dada" + \
          "-f /data/spip/first_light/single_dish/2016-04-28-13:27:30_0000240518168576.000000.dada"

    self.log (0, "cmd=" + cmd)
    (rval, lines) = self.system (cmd)
    self.log (0, "rval=" + str(rval))
    for line in lines:
      self.log (0, line)
Пример #3
0
 def __init__ (self, script, id):
   self.id = id
   self.script = script
   host = getHostNameShort()
   port = int(script.cfg["STREAM_RECV_PORT"]) + int(id)
   self.script.log (2, "ConfiguringThread listening on " + host + ":" + str(port))
   ReportingThread.__init__(self, script, host, port)
Пример #4
0
  def __init__ (self, script, id):
    host = sockets.getHostNameShort()
    port = int(script.cfg["STREAM_RESULTS_PORT"])
    if id >= 0:
      port += int(id)
    ReportingThread.__init__(self, script, host, port)

    with open (script.cfg["WEB_DIR"] + "/spip/images/blankimage.gif", mode='rb') as file:
      self.no_data = file.read()
Пример #5
0
  def __init__ (self, script, id):
    host = sockets.getHostNameShort()
    port = int(script.cfg["STREAM_REPACK_PORT"])
    if id >= 0:
      port += int(id)
    ReportingThread.__init__(self, script, host, port)

    with open (script.cfg["WEB_DIR"] + "/spip/images/blankimage.gif", mode='rb') as file:
      self.no_data = file.read()
Пример #6
0
    def __init__(self, name):
        TCSInterfaceDaemon.__init__(self, name, "-1")
        ServerBased.__init__(self, self.cfg)

        self.host = sockets.getHostNameShort()
        self.interface_port = int(self.cfg["TCS_INTERFACE_PORT"]) - 1
        self.spip_tcs_port = int(self.cfg["TCS_INTERFACE_PORT"])

        # beam_states maintains info about last observation for beam
        self.beam_cfg = {}
Пример #7
0
  def __init__ (self, script, id):
    host = sockets.getHostNameShort()
    port = int(script.cfg["BEAM_REPACK_FOLD_PORT"])
    if int(id) >= 0:
      port += int(id)
    ReportingThread.__init__(self, script, host, port)

    with open (script.cfg["WEB_DIR"] + "/spip/images/blankimage.gif", mode='rb') as file:
      self.no_data = file.read()

    self.script.log (2, "RepackReportingThread::ReportingThread listening on " + host + ":" + str(port))
Пример #8
0
    def __init__(self, script, id):
        host = sockets.getHostNameShort()
        port = int(script.cfg["BEAM_REPACK_FOLD_PORT"])
        if int(id) >= 0:
            port += int(id)
        ReportingThread.__init__(self, script, host, port)

        with open(script.cfg["WEB_DIR"] + "/spip/images/blankimage.gif",
                  mode='rb') as file:
            self.no_data = file.read()

        self.script.log(
            2, "RepackReportingThread::ReportingThread listening on " + host +
            ":" + str(port))
Пример #9
0
  def main (self):

    # open a listening socket to receive the header to use in configuring the
    # the data generator
    hostname = getHostNameShort()

    config = Config()

    # prepare header using configuration file parameters
    fixed_config = config.getStreamConfigFixed(self.id)

    if DL > 1:
      self.log(1, "NBIT\t"  + fixed_config["NBIT"])
      self.log(1, "NDIM\t"  + fixed_config["NDIM"])
      self.log(1, "NCHAN\t" + fixed_config["NCHAN"])
      self.log(1, "TSAMP\t" + fixed_config["TSAMP"])
      self.log(1, "BW\t"    + fixed_config["BW"])
      self.log(1, "FREQ\t"  + fixed_config["FREQ"])
      self.log(1, "START_CHANNEL\t"  + fixed_config["START_CHANNEL"])
      self.log(1, "END_CHANNEL\t"  + fixed_config["END_CHANNEL"])

    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    sock.bind((hostname, int(self.cfg["STREAM_GEN_PORT"]) + int(self.id)))
    sock.listen(1)

    can_read = [sock]
    can_write = []
    can_error = []

    while not self.quit_event.isSet():

      timeout = 1

      did_read = []
      did_write = []
      did_error = []

      try:
        # wait for some activity on the control socket
        self.log(3, "main: select")
        did_read, did_write, did_error = select.select(can_read, can_write, can_error, timeout)
        self.log(3, "main: read="+str(len(did_read))+" write="+
                    str(len(did_write))+" error="+str(len(did_error)))
      except select.error as e:
        if e[0] == errno.EINTR:
          self.log(0, "SIGINT received during select, exiting")
          self.quit_event.set()
        else:
          raise

      if (len(did_read) > 0):
        for handle in did_read:
          if (handle == sock):
            (new_conn, addr) = sock.accept()
            self.log(1, "main: accept connection from "+repr(addr))

            # add the accepted connection to can_read
            can_read.append(new_conn)

          # an accepted connection must have generated some data
          else:

            try:
              message = handle.recv(4096).strip()
              self.log(3, "commandThread: message='" + str(message) +"'")
            
              # and empty messages means a remote close (normally)
              if (len(message) == 0):
                self.log(1, "commandThread: closing connection")
                handle.close()
                for i, x in enumerate(can_read):
                  if (x == handle):
                    del can_read[i]

              # handle the command (non-blocking)
              else:
                self.log (3, "<- " + message)
                self.log (2, "genDaemon::handle_command()")
                (result, response) = self.handle_command (fixed_config, message)
                self.log (2, "genDaemon::handle_command() =" + result)

                self.log (3, "-> " + result + " " + response)
                xml_response = "<gen_response>" + response + "</gen_response>"
                handle.send (xml_response)

            except socket.error as e:
              if e.errno == errno.ECONNRESET:
                self.log(1, "commandThread: closing connection")
                handle.close()
                for i, x in enumerate(can_read):
                  if (x == handle):
                    del can_read[i]

      if self.gen_thread:
        if not self.gen_thread.is_alive():
          # join a previously launched and no longer running gen thread
          rval = self.gen_thread.join()
          if rval:
            self.log (-2, "gen thread failed")
          self.gen_thread = []
Пример #10
0
 def __init__ (self, name, id):
   Daemon.__init__(self, name, str(id))
   self.beam_states = {}
   self.host = sockets.getHostNameShort()
   self.start_offset_seconds = 5
Пример #11
0
 def __init__(self, script, id):
     host = getHostNameShort()
     port = int(script.cfg["STREAM_PROC_PORT"]) + int(id)
     script.log(
         0, "ProcReportingThread: listening on " + host + ":" + str(port))
     ReportingThread.__init__(self, script, host, port)
Пример #12
0
    def main(self):

        log_host = sockets.getHostNameShort()
        log_port = self.cfg["SERVER_LOG_PORT"]

        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.log(2, "main: binding to " + log_host + ":" + log_port)
        sock.bind((log_host, int(log_port)))

        # allow up to 10 queued connections
        sock.listen(10)

        can_read = [sock]
        can_write = []
        can_error = []
        headers = {}
        line_buffers = {}
        timeout = 1

        while (not self.quit_event.isSet()):

            self.log(
                3, "main: calling select len(can_read)=" + str(len(can_read)))
            timeout = 1
            did_read, did_write, did_error = select(can_read, can_write,
                                                    can_error, timeout)
            self.log(3, "main: read="+str(len(did_read))+" write="+ \
                          str(len(did_write))+" error="+str(len(did_error)))

            if (len(did_read) > 0):
                for handle in did_read:
                    if (handle == sock):
                        (new_conn, addr) = sock.accept()
                        self.log(1,
                                 "main: accept connection from " + repr(addr))

                        # read header information about this logging stream
                        header = new_conn.recv(4096)

                        try:
                            xml = parse(header)
                        except ExpatError as e:
                            self.log(
                                0, "main: accept: xml error [" + header + "]")
                            new_conn.send(
                                "<xml>Malformed XML message</xml>\r\n")
                            new_conn.close()
                        else:
                            # add to list of open file handles
                            can_read.append(new_conn)
                            # return a single character to confirm header has been receive
                            new_conn.send('\n')
                            headers[new_conn] = xml
                            line_buffers[new_conn] = ""

                    else:
                        message = handle.recv(4096)

                        # if the socket has been closed
                        if len(message) == 0:
                            self.log(1, "commandThread: closing connection")
                            if len(line_buffers[handle]) > 0:
                                line = line_buffers[handle]
                                self.processLine(line, headers[handle])
                            handle.close()
                            for i, x in enumerate(can_read):
                                if (x == handle):
                                    del can_read[i]
                            del headers[handle]
                            del line_buffers[handle]

                        else:
                            well_terminated = message.endswith('\n')
                            line_buffers[handle] += message.rstrip('\n')
                            lines = line_buffers[handle].split("\n")
                            to_use = len(lines)

                            if well_terminated:
                                line_buffers[handle] = ""
                            else:
                                to_use -= 1

                            for i in range(to_use):
                                line = lines[i]
                                self.log(3,
                                         "commandThread: line='" + line + "'")
                                self.processLine(line, headers[handle])
Пример #13
0
###############################################################################
#
if __name__ == "__main__":

    if len(sys.argv) != 2:
        print "ERROR: 1 command line argument expected"
        sys.exit(1)

    cfg = sys.argv[1]

    cfg_dir = os.environ.get('SPIP_ROOT') + "/share"
    cmd = "cp " + cfg_dir + "/" + cfg + "/*.cfg " + cfg_dir + "/"
    system(cmd, False)

    hostname = getHostNameShort()

    script = LMCDaemon("spip_lmc", hostname)
    state = script.configure(DAEMONIZE, DL, "lmc", "lmc")
    if state != 0:
        sys.exit(state)

    script.log(1, "STARTING SCRIPT")

    try:

        script.main()

    except:
        script.quit_event.set()
Пример #14
0
  # for all beams, otherwise, 1 per beam

  if int(beam_id) == -1:
    print "ERROR: script not configured for server mode"
    sys.exit(1)

  script = KATCPBeamDaemon ("meerkat_katcp", int(beam_id))

  state = script.configure (DAEMONIZE, DL, "katcp", "katcp")
  if state != 0:
    sys.exit(state)

  server = []

  try:
    server_host = sockets.getHostNameShort()
    server_port = 5000 + int(beam_id)

    script.log(2, "__main__: KATCPServer(" +server_host+"," + str(server_port) + ")")
    server = KATCPServer (server_host, server_port, script)

    script.log(2, "__main__: script.set_katcp()")
    script.set_katcp(server)

    script.log(1, "STARTING SCRIPT")
   
    script.log(1, "quit_file="+str(script.quit_file))
    script.log(2, "__main__: server.start()")
    server.start()

    pubsub = PubSubThread (script, beam_id)
Пример #15
0
  def main (self):

    log_host = sockets.getHostNameShort()
    log_port = self.cfg["SERVER_LOG_PORT"]

    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    self.log(2, "main: binding to " + log_host + ":" + log_port)
    sock.bind((log_host, int(log_port)))

    # allow up to 128 queued connections
    sock.listen (128)

    can_read = [sock]
    can_write = []
    can_error = []
    headers = {}
    line_buffers = {}
    timeout = 1

    # TODO change this over to nslookups based on configured servers in
    # configuration files
    allowed_hosts = ["127.0.0.1", "130.155.182.74", "130.155.182.28", "130.155.182.31", "130.155.182.32", "130.155.182.33", "130.155.182.34", "130.155.182.35", "130.155.182.36", "130.155.182.37", "130.155.182.38", "10.98.72.1", "10.98.72.2" ]

    keep_logging = True
    to_wait = 10

    while keep_logging:

      # if the script has been asked to quit
      if self.quit_event.isSet():

        # if only the listening socket and LMC socket remain
        if len(can_read) == 2:
          keep_logging = False

        # some logging clients are still attached, wait 10 seconds before quitting
        else:
          to_wait -= 1

        if to_wait <= 0: 
          keep_logging = False

      self.log(3, "main: calling select len(can_read)="+str(len(can_read)))
      timeout = 1
      did_read, did_write, did_error = select(can_read, can_write, can_error, timeout)
      self.log(3, "main: read="+str(len(did_read))+" write="+ \
                    str(len(did_write))+" error="+str(len(did_error)))

      if (len(did_read) > 0):
        for handle in did_read:
          if (handle == sock):
            (new_conn, addr) = sock.accept()
            ip, port = addr
            self.log(2, "main: accept connection from " + ip + ":" + str(port))

            if len(allowed_hosts) > 0 and not (ip in allowed_hosts):
              self.log(1, "main: rejecting connection from " + ip + " not in " + str(allowed_hosts))
              new_conn.close()

            else:

              # read header information about this logging stream
              header = new_conn.recv (4096)

              try: 
                xml = parse(header)
              except ExpatError as e:
                self.log(0, "main: accept: xml error [" + header + "]")
                new_conn.send ("<xml>Malformed XML message</xml>\r\n")
                new_conn.close()
              else:
                # add to list of open file handles
                can_read.append(new_conn)
                # return a single character to confirm header has been receive
                new_conn.send('\n')
                headers[new_conn] = xml
                line_buffers[new_conn] = ""

          else:
            message = handle.recv(4096)

            # if the socket has been closed
            if len(message) == 0:
              self.log(2, "commandThread: closing connection")
              if len(line_buffers[handle]) > 0:
                line = line_buffers[handle]
                self.processLine(line, headers[handle])
              handle.close()
              for i, x in enumerate(can_read):
                if (x == handle):
                  del can_read[i]
              del headers[handle]
              del line_buffers[handle]

            else:
              well_terminated = message.endswith('\n')
              line_buffers[handle] += message.rstrip('\n')
              lines = line_buffers[handle].split("\n")
              to_use = len(lines)

              if well_terminated:
                line_buffers[handle] = ""
              else:
                to_use -= 1

              for i in range(to_use):
                line = lines[i]
                self.log(3, "commandThread: line='" + line + "'")
                self.processLine (line, headers[handle])
Пример #16
0
 def __init__(self, name, id):
     Daemon.__init__(self, name, str(id))
     self.beam_states = {}
     self.host = sockets.getHostNameShort()
     self.start_offset_seconds = 20
Пример #17
0
    # for all beams, otherwise, 1 per beam

    if int(beam_id) == -1:
        print "ERROR: script not configured for server mode"
        sys.exit(1)

    script = KATCPBeamDaemon("meerkat_katcp", int(beam_id))

    state = script.configure(DAEMONIZE, DL, "katcp", "katcp")
    if state != 0:
        sys.exit(state)

    server = []

    try:
        server_host = sockets.getHostNameShort()
        server_port = 5000 + int(beam_id)

        script.log(
            2, "__main__: KATCPServer(" + server_host + "," +
            str(server_port) + ")")
        server = KATCPServer(server_host, server_port, script)

        script.log(2, "__main__: script.set_katcp()")
        script.set_katcp(server)

        script.log(1, "STARTING SCRIPT")

        script.log(2, "__main__: server.start()")
        server.start()
Пример #18
0
 def __init__(self, name, id):
     Daemon.__init__(self, name, str(id))
     self.beam_cfg = {}
     self.host = sockets.getHostNameShort()
Пример #19
0
    def main(self):

        # open a listening socket to receive the data files to read
        hostname = getHostNameShort()

        # get the site configurationa
        config = Config()

        # prepare header using configuration file parameters
        fixed_config = config.getStreamConfigFixed(self.id)

        if DL > 1:
            self.log(1, "NBIT\t" + fixed_config["NBIT"])
            self.log(1, "NDIM\t" + fixed_config["NDIM"])
            self.log(1, "NCHAN\t" + fixed_config["NCHAN"])
            self.log(1, "TSAMP\t" + fixed_config["TSAMP"])
            self.log(1, "BW\t" + fixed_config["BW"])
            self.log(1, "FREQ\t" + fixed_config["FREQ"])
            self.log(1, "START_CHANNEL\t" + fixed_config["START_CHANNEL"])
            self.log(1, "END_CHANNEL\t" + fixed_config["END_CHANNEL"])

        self.log(1, "ReadDaemon::main self.list_obs()")
        list_xml_str = self.list_obs()
        list_xml = xmltodict.parse(list_xml_str)
        first_obs = list_xml['observation_list']['observation'][0]
        print str(first_obs)
        self.read_obs(first_obs)
        #self.log(1, "ReadDaemon::main " + str(xml))

        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.bind((hostname, int(self.cfg["STREAM_READ_PORT"]) + int(self.id)))
        sock.listen(1)

        can_read = [sock]
        can_write = []
        can_error = []

        while not self.quit_event.isSet():

            timeout = 1

            did_read = []
            did_write = []
            did_error = []

            try:
                # wait for some activity on the control socket
                self.log(3, "main: select")
                did_read, did_write, did_error = select.select(
                    can_read, can_write, can_error, timeout)
                self.log(
                    3, "main: read=" + str(len(did_read)) + " write=" +
                    str(len(did_write)) + " error=" + str(len(did_error)))
            except select.error as e:
                if e[0] == errno.EINTR:
                    self.log(0, "SIGINT received during select, exiting")
                    self.quit_event.set()
                else:
                    raise

            if (len(did_read) > 0):
                for handle in did_read:
                    if (handle == sock):
                        (new_conn, addr) = sock.accept()
                        self.log(1,
                                 "main: accept connection from " + repr(addr))

                        # add the accepted connection to can_read
                        can_read.append(new_conn)

                    # an accepted connection must have generated some data
                    else:

                        message = handle.recv(4096).strip()
                        self.log(
                            3, "commandThread: message='" + str(message) + "'")

                        xml = xmltodict.parse(message)
                        self.log(3, DL,
                                 "commandThread: xml='" + str(xml) + "'")

                        if (len(message) == 0):
                            self.log(1, "commandThread: closing connection")
                            handle.close()
                            for i, x in enumerate(can_read):
                                if (x == handle):
                                    del can_read[i]
                        else:

                            if xml['command'] == "list_obs":
                                self.log(1, "command [" + xml['command'] + "]")
                                self.list_obs()
                                response = "OK"

                            elif xml['command'] == "read_obs":
                                self.log(1, "command [" + xml['command'] + "]")
                                self.read_obs()
                                response = "OK"

                            else:
                                self.log(
                                    -1, "unrecognized command [" +
                                    xml['command'] + "]")
                                response = "FAIL"

                            self.log(3, "-> " + response)
                            xml_response = "<read_response>" + response + "</read_response>"
                            handle.send(xml_response)
Пример #20
0
    def main(self):

        log_host = sockets.getHostNameShort()
        log_port = self.cfg["SERVER_LOG_PORT"]

        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.log(2, "main: binding to " + log_host + ":" + log_port)
        sock.bind((log_host, int(log_port)))

        # allow up to 128 queued connections
        sock.listen(128)

        can_read = [sock]
        can_write = []
        can_error = []
        headers = {}
        line_buffers = {}
        timeout = 1

        # TODO change this over to nslookups based on configured servers in
        # configuration files
        allowed_hosts = [
            "127.0.0.1", "130.155.182.74", "130.155.182.28", "130.155.182.31",
            "130.155.182.32", "130.155.182.33", "130.155.182.34",
            "130.155.182.35", "130.155.182.36", "130.155.182.37",
            "130.155.182.38", "10.98.72.1", "10.98.72.2"
        ]

        keep_logging = True
        to_wait = 10

        while keep_logging:

            # if the script has been asked to quit
            if self.quit_event.isSet():

                # if only the listening socket and LMC socket remain
                if len(can_read) == 2:
                    keep_logging = False

                # some logging clients are still attached, wait 10 seconds before quitting
                else:
                    to_wait -= 1

                if to_wait <= 0:
                    keep_logging = False

            self.log(
                3, "main: calling select len(can_read)=" + str(len(can_read)))
            timeout = 1
            did_read, did_write, did_error = select(can_read, can_write,
                                                    can_error, timeout)
            self.log(3, "main: read="+str(len(did_read))+" write="+ \
                          str(len(did_write))+" error="+str(len(did_error)))

            if (len(did_read) > 0):
                for handle in did_read:
                    if (handle == sock):
                        (new_conn, addr) = sock.accept()
                        ip, port = addr
                        self.log(
                            2, "main: accept connection from " + ip + ":" +
                            str(port))

                        if len(allowed_hosts) > 0 and not (ip
                                                           in allowed_hosts):
                            self.log(
                                1, "main: rejecting connection from " + ip +
                                " not in " + str(allowed_hosts))
                            new_conn.close()

                        else:

                            # read header information about this logging stream
                            header = new_conn.recv(4096)

                            try:
                                xml = parse(header)
                            except ExpatError as e:
                                self.log(
                                    0,
                                    "main: accept: xml error [" + header + "]")
                                new_conn.send(
                                    "<xml>Malformed XML message</xml>\r\n")
                                new_conn.close()
                            else:
                                # add to list of open file handles
                                can_read.append(new_conn)
                                # return a single character to confirm header has been receive
                                new_conn.send('\n')
                                headers[new_conn] = xml
                                line_buffers[new_conn] = ""

                    else:
                        message = handle.recv(4096)

                        # if the socket has been closed
                        if len(message) == 0:
                            self.log(2, "commandThread: closing connection")
                            if len(line_buffers[handle]) > 0:
                                line = line_buffers[handle]
                                self.processLine(line, headers[handle])
                            handle.close()
                            for i, x in enumerate(can_read):
                                if (x == handle):
                                    del can_read[i]
                            del headers[handle]
                            del line_buffers[handle]

                        else:
                            well_terminated = message.endswith('\n')
                            line_buffers[handle] += message.rstrip('\n')
                            lines = line_buffers[handle].split("\n")
                            to_use = len(lines)

                            if well_terminated:
                                line_buffers[handle] = ""
                            else:
                                to_use -= 1

                            for i in range(to_use):
                                line = lines[i]
                                self.log(3,
                                         "commandThread: line='" + line + "'")
                                self.processLine(line, headers[handle])
Пример #21
0
      self.server_thread.join()

###############################################################################
#
if __name__ == "__main__":

  if len(sys.argv) != 1:
    print "ERROR: 0 command line argument expected"
    sys.exit(1)

  # cfg = sys.argv[1]
  # cfg_dir = os.environ.get('SPIP_ROOT') + "/share"
  # cmd = "cp " + cfg_dir + "/" + cfg + "/*.cfg " + cfg_dir + "/"
  # system (cmd, False)  

  hostname = getHostNameShort()

  script = LMCDaemon ("spip_lmc", hostname)
  state = script.configure (DAEMONIZE, DL, "lmc", "lmc")
  if state != 0:
    sys.exit(state)

  script.log(1, "STARTING SCRIPT")

  try:

    reporting_thread = LMCReportingThread(script)
    reporting_thread.start()

    script.main()
Пример #22
0
  def main (self):

    # open a listening socket to receive the data files to read
    hostname = getHostNameShort()

    # get the site configurationa
    config = Config()

    # prepare header using configuration file parameters
    fixed_config = config.getStreamConfigFixed(self.id)

    if DL > 1:
      self.log(1, "NBIT\t"  + fixed_config["NBIT"])
      self.log(1, "NDIM\t"  + fixed_config["NDIM"])
      self.log(1, "NCHAN\t" + fixed_config["NCHAN"])
      self.log(1, "TSAMP\t" + fixed_config["TSAMP"])
      self.log(1, "BW\t"    + fixed_config["BW"])
      self.log(1, "FREQ\t"  + fixed_config["FREQ"])
      self.log(1, "START_CHANNEL\t"  + fixed_config["START_CHANNEL"])
      self.log(1, "END_CHANNEL\t"  + fixed_config["END_CHANNEL"])

    self.log(1, "ReadDaemon::main self.list_obs()")
    list_xml_str = self.list_obs()
    list_xml = xmltodict.parse (list_xml_str)
    first_obs = list_xml['observation_list']['observation'][0]
    print str(first_obs)
    self.read_obs (first_obs)
    #self.log(1, "ReadDaemon::main " + str(xml))

    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    sock.bind((hostname, int(self.cfg["STREAM_READ_PORT"]) + int(self.id)))
    sock.listen(1)

    can_read = [sock]
    can_write = []
    can_error = []

    while not self.quit_event.isSet():

      timeout = 1

      did_read = []
      did_write = []
      did_error = []

      try:
        # wait for some activity on the control socket
        self.log(3, "main: select")
        did_read, did_write, did_error = select.select(can_read, can_write, can_error, timeout)
        self.log(3, "main: read="+str(len(did_read))+" write="+
                    str(len(did_write))+" error="+str(len(did_error)))
      except select.error as e:
        if e[0] == errno.EINTR:
          self.log(0, "SIGINT received during select, exiting")
          self.quit_event.set()
        else:
          raise

      if (len(did_read) > 0):
        for handle in did_read:
          if (handle == sock):
            (new_conn, addr) = sock.accept()
            self.log(1, "main: accept connection from "+repr(addr))

            # add the accepted connection to can_read
            can_read.append(new_conn)

          # an accepted connection must have generated some data
          else:

            message = handle.recv(4096).strip()
            self.log(3, "commandThread: message='" + str(message) +"'")
            
            xml = xmltodict.parse (message)
            self.log(3, DL, "commandThread: xml='" + str(xml) +"'")

            if (len(message) == 0):
              self.log(1, "commandThread: closing connection")
              handle.close()
              for i, x in enumerate(can_read):
                if (x == handle):
                  del can_read[i]
            else:

              if xml['command'] == "list_obs":
                self.log (1, "command ["+xml['command'] + "]")
                self.list_obs ()
                response = "OK"

              elif xml['command'] == "read_obs":
                self.log (1, "command ["+xml['command'] + "]")
                self.read_obs ()
                response = "OK"

              else:
                self.log (-1, "unrecognized command ["+xml['command'] + "]")
                response = "FAIL"
  
              self.log(3, "-> " + response)
              xml_response = "<read_response>" + response + "</read_response>"
              handle.send (xml_response)
Пример #23
0
 def __init__ (self, script, id):
   host = getHostNameShort()
   port = int(script.cfg["STREAM_PROC_PORT"]) + int(id)
   script.log (0, "ProcReportingThread: listening on " + host + ":" + str(port))
   ReportingThread.__init__(self, script, host, port)