Beispiel #1
0
    def run(self):
        results  = []
        failures = []
        
        self.logger.info("Issuing shutdown commands to local segments...")
        for db in self.dblist:
            datadir, port = db.split(':')[0:2]

            cmd = gp.SegmentStop('segment shutdown', datadir, mode=self.mode, timeout=self.timeout)
            cmd.run()
            res = cmd.get_results()
            if res.rc == 0:

                # MPP-15208
                #
                cmd2 = gp.SegmentIsShutDown('check if shutdown', datadir)
                cmd2.run()
                if cmd2.is_shutdown():
                    status = SegStopStatus(datadir, True, "Shutdown Succeeded")
                    results.append(status)                
                    continue

                # MPP-16171
                # 
                if self.mode == 'immediate':
                    status = SegStopStatus(datadir, True, "Shutdown Immediate")
                    results.append(status)
                    continue

            # read pid and datadir from /tmp/.s.PGSQL.<port>.lock file
            name = "failed segment '%s'" % db
            (succeeded, mypid, file_datadir) = pg.ReadPostmasterTempFile.local(name,port).getResults()
            if succeeded and file_datadir == datadir:

                # now try to terminate the process, first trying with
                # SIGTERM and working our way up to SIGABRT sleeping
                # in between to give the process a moment to exit
                #
                unix.kill_sequence(mypid)

                if not unix.check_pid(mypid):
                    lockfile = "/tmp/.s.PGSQL.%s" % port    
                    if os.path.exists(lockfile):
                        self.logger.info("Clearing segment instance lock files")        
                        os.remove(lockfile)
            
            status = SegStopStatus(datadir,False,"Shutdown failed: rc: %d stdout: %s stderr: %s" % (res.rc,res.stdout,res.stderr))
            failures.append(status)
            results.append(status)
        
        #Log the results!
        status = '\nCOMMAND RESULTS\n'
        for result in results:
            status += str(result) + "\n"
        
        self.logger.info(status)
        return 1 if failures else 0
Beispiel #2
0
    def terminate_process(self, pid):

        self.validate_attempt(pid)

        logger.warning('Confirm [N/y]:')

        confirmation = raw_input().strip().lower()
        if confirmation not in ['y', 'ye', 'yes']:
            raise KillError('operation aborted')

        kill_sequence(pid)

        if check_pid(pid):
            raise KillError('Failed to kill process %s' % pid)
Beispiel #3
0
    def terminate_process(self, pid):
       
        self.validate_attempt(pid)
      
        logger.warning('Confirm [N/y]:')  

        confirmation = raw_input().strip().lower()
        if confirmation not in ['y', 'ye', 'yes']:
            raise KillError('operation aborted')

        kill_sequence(pid)

        if check_pid(pid):
            raise KillError('Failed to kill process %s' % pid)
Beispiel #4
0
    def run(self):
        try:
            self.datadir, self.port = self.get_datadir_and_port()

            cmd = gp.SegmentStop('segment shutdown',
                                 self.datadir,
                                 mode=self.mode,
                                 timeout=self.timeout)
            cmd.run()

            results = cmd.get_results()
            is_shutdown = False

            if results.rc == 0:
                cmd = gp.SegmentIsShutDown('check if shutdown', self.datadir)
                cmd.run()

                if cmd.is_shutdown():
                    status = SegStopStatus(self.datadir, True,
                                           "Shutdown Succeeded")
                    self.result = status
                    is_shutdown = True
                # MPP-16171
                #
                elif self.mode == 'immediate':
                    status = SegStopStatus(self.datadir, True,
                                           "Shutdown Immediate")
                    self.result = status
                    is_shutdown = True

            # read pid and datadir from /tmp/.s.PGSQL.<port>.lock file
            name = "failed segment '%s'" % self.db
            (succeeded, mypid, file_datadir) = pg.ReadPostmasterTempFile.local(
                name, self.port).getResults()

            if not is_shutdown:
                if succeeded and file_datadir == self.datadir:

                    # now try to terminate the process, first trying with
                    # SIGTERM and working our way up to SIGABRT sleeping
                    # in between to give the process a moment to exit
                    #
                    unix.kill_sequence(mypid)

                    if not unix.check_pid(mypid):
                        lockfile = "/tmp/.s.PGSQL.%s" % self.port
                        if os.path.exists(lockfile):
                            self.logger.info(
                                "Clearing segment instance lock files")
                            os.remove(lockfile)

                status = SegStopStatus(
                    self.datadir, True,
                    "Forceful termination success: rc: %d stdout: %s stderr: %s."
                    % (results.rc, results.stdout, results.stderr))

            try:
                unix.kill_9_segment_processes(self.datadir, self.port, mypid)

                if unix.check_pid(mypid) and mypid != -1:
                    status = SegStopStatus(
                        self.datadir, False,
                        "Failed forceful termnation: rc: %d stdout: %s stderr: %s."
                        % (results.rc, results.stdout, results.stderr))

                self.result = status
            except Exception as e:
                logger.error(
                    'Failed forceful termination of segment %s: (%s)' %
                    (self.datadir, str(e)))
                self.result = SegStopStatus(
                    self.datadir, False,
                    'Failed forceful termination of segment! (%s)' % str(e))

            return self.result
        except Exception as e:
            logger.exception(e)
            self.result = SegStopStatus(self.datadir, False,
                                        'Shutdown failed! %s' % str(e))
            return self.result
Beispiel #5
0
    def run(self):
        try:
            self.datadir, self.port = self.get_datadir_and_port()

            cmd = gp.SegmentStop('segment shutdown', self.datadir, mode=self.mode, timeout=self.timeout)
            cmd.run()

            results = cmd.get_results()
            is_shutdown = False

            if results.rc == 0:
                cmd = gp.SegmentIsShutDown('check if shutdown', self.datadir)
                cmd.run()

                if cmd.is_shutdown():
                    status = SegStopStatus(self.datadir, True, "Shutdown Succeeded")
                    self.result = status
                    is_shutdown = True
                # MPP-16171
                # 
                elif self.mode == 'immediate':
                    status = SegStopStatus(self.datadir, True, "Shutdown Immediate")
                    self.result = status
                    is_shutdown = True

            # read pid and datadir from /tmp/.s.PGSQL.<port>.lock file
            name = "failed segment '%s'" % self.db
            (succeeded, mypid, file_datadir) = pg.ReadPostmasterTempFile.local(name,self.port).getResults()

            if not is_shutdown:
                if succeeded and file_datadir == self.datadir:

                    # now try to terminate the process, first trying with
                    # SIGTERM and working our way up to SIGABRT sleeping
                    # in between to give the process a moment to exit
                    #
                    unix.kill_sequence(mypid)

                    if not unix.check_pid(mypid):
                        lockfile = "/tmp/.s.PGSQL.%s" % self.port
                        if os.path.exists(lockfile):
                            self.logger.info("Clearing segment instance lock files")
                            os.remove(lockfile)

                status = SegStopStatus(self.datadir, True, "Forceful termination success: rc: %d stdout: %s stderr: %s." % (results.rc,results.stdout,results.stderr))

            try:
                unix.kill_9_segment_processes(self.datadir, self.port, mypid)

                if unix.check_pid(mypid) and mypid != -1:
                    status = SegStopStatus(self.datadir, False, "Failed forceful termnation: rc: %d stdout: %s stderr: %s." % (results.rc,results.stdout,results.stderr))

                self.result = status
            except Exception as e:
                logger.error('Failed forceful termination of segment %s: (%s)' % (self.datadir, str(e)))
                self.result = SegStopStatus(self.datadir,False,'Failed forceful termination of segment! (%s)' % str(e))

            return self.result
        except Exception as e:
            logger.exception(e)
            self.result = SegStopStatus(self.datadir,False,'Shutdown failed! %s' % str(e))
            return self.result