示例#1
0
    def cleanup(self):
        self.logger.info('Starting to clean up old Nuclide processes/files.')
        # TODO: Remove it after migration is complete.
        # For migration, stop the forever monitor processes of Nuclide server.
        # This does not stop existing Nuclide server processes themselves.
        # It just removes the monitor so that we can kill them on upgrade.
        for proc in ProcessInfo.get_processes(
                getpass.getuser(), '%s.*%s' %
                (re.escape('forever/bin/monitor'), re.escape('nuclide-main.js'))):
            self.logger.info('Stopping forever monitor process: %s' % proc)
            proc.stop()

        # Clean up multiple Nuclide processes on same port.
        # There should be no more than one on a given port.
        # TODO: log the error to analytics db.
        # { port1 => [proc1, proc2, ...], ...}
        server_proc_map = defaultdict(list)
        # Group the processes by port.
        for proc in NuclideServer.get_processes():
            port = int(proc.get_command_param('port'))
            server_proc_map[port].append(proc)
        for port in server_proc_map:
            if len(server_proc_map[port]) > 1:
                self.logger.warning(
                    'Multiple Nuclide processes on port %d. Something wrong. Clean them up...' %
                    port)
                for proc in server_proc_map[port]:
                    proc.stop()

        self.cleanup_certificates(CERTS_EXPIRATION_DAYS)
        self.logger.info('Finished cleaning up old Nuclide processes/files.')
示例#2
0
    def cleanup(self):
        self.logger.info('Starting to clean up old Nuclide processes/files.')
        # TODO: Remove it after migration is complete.
        # For migration, stop the forever monitor processes of Nuclide server.
        # This does not stop existing Nuclide server processes themselves.
        # It just removes the monitor so that we can kill them on upgrade.
        for proc in ProcessInfo.get_processes(
                getpass.getuser(), '%s.*%s' %
            (re.escape('forever/bin/monitor'), re.escape('nuclide-main.js'))):
            self.logger.info('Stopping forever monitor process: %s' % proc)
            proc.stop()

        # Clean up multiple Nuclide processes on same port.
        # There should be no more than one on a given port.
        # TODO: log the error to analytics db.
        # { port1 => [proc1, proc2, ...], ...}
        server_proc_map = defaultdict(list)
        # Group the processes by port.
        for proc in NuclideServer.get_processes():
            port = int(proc.get_command_param('port'))
            server_proc_map[port].append(proc)
        for port in server_proc_map:
            if len(server_proc_map[port]) > 1:
                self.logger.warning(
                    'Multiple Nuclide processes on port %d. Something wrong. Clean them up...'
                    % port)
                for proc in server_proc_map[port]:
                    proc.stop()

        self.cleanup_certificates(CERTS_EXPIRATION_DAYS)
        self.logger.info('Finished cleaning up old Nuclide processes/files.')
示例#3
0
    def cleanup(self):

        # TODO: Remove it after migration is complete.
        # For migration, stop the forever monitor processes of Nuclide server.
        # This does not stop existing Nuclide server processes themselves.
        # It just removes the monitor so that we can kill them on upgrade.
        for proc in ProcessInfo.get_processes(
            getpass.getuser(), "%s.*%s" % (re.escape("forever/bin/monitor"), re.escape("nuclide-main.js"))
        ):
            print("Stopping %s" % proc, file=sys.stderr)
            proc.stop()

        # Clean up multiple Nuclide processes on same port.
        # There should be no more than one on a given port.
        # TODO: log the error to analytics db.
        # { port1 => [proc1, proc2, ...], ...}
        server_proc_map = defaultdict(list)
        # Group the processes by port.
        for proc in NuclideServer.get_processes():
            port = int(proc.get_command_param("port"))
            server_proc_map[port].append(proc)
        for port in server_proc_map:
            if len(server_proc_map[port]) > 1:
                print(
                    "Multiple Nuclide processes on port %d. Something wrong. Clean them up..." % port, file=sys.stderr
                )
                for proc in server_proc_map[port]:
                    proc.stop()

        self.cleanup_certificates(CERTS_EXPIRATION_DAYS)
示例#4
0
    def get_processes(user=getpass.getuser(), port=None):
        matches = []
        procs = ProcessInfo.get_processes(user, re.escape(NuclideServer.script_name + " --port"))
        for proc in procs:
            port_from_proc = int(proc.get_command_param('port'))
            # If port not specified, skip port check and add to result list.
            if port is None:
                matches.append(proc)
            else:
                # If port is given, match it.
                if port_from_proc == port:
                    matches.append(proc)

        return matches
示例#5
0
 def test_get_processes(self):
     # Verify against the test process itself.
     testname = 'nuclide_server_py_tests'
     procs = ProcessInfo.get_processes(getpass.getuser(), re.escape(testname))
     found_it = False
     for proc in procs:
         # The base command is python.
         # There may be other processes with this particular pattern in it.
         if 'python' in proc.get_column('comm'):
             found_it = True
             self.assertTrue(proc.get_column('pid') is not None)
             self.assertTrue(int(proc.get_column('pid')) > 0)
             self.assertTrue(testname in proc.get_column('command'))
     self.assertTrue(found_it)
示例#6
0
 def test_get_processes(self):
     # Verify against the test process itself.
     testname = 'nuclide_server_py_tests'
     procs = ProcessInfo.get_processes(getpass.getuser(), re.escape(testname))
     found_it = False
     for proc in procs:
         # The base command is python.
         # There may be other processes with this particular pattern in it.
         if 'python' in proc.get_column('comm'):
             found_it = True
             self.assertTrue(proc.get_column('pid') is not None)
             self.assertTrue(int(proc.get_column('pid')) > 0)
             self.assertTrue(testname in proc.get_column('command'))
     self.assertTrue(found_it)