コード例 #1
0
    def execute(self, data):
        """Pass a container to the cleanup service.
        """
        _LOGGER.critical('Monitor container cleanup: %r', data)
        running = os.path.join(self._tm_env.running_dir, data['id'])
        data_dir = supervisor.open_service(running, existing=False).data_dir
        cleanup = os.path.join(self._tm_env.cleanup_dir, data['id'])

        # pid1 will SIGABRT(6) when there is an issue
        if int(data['signal']) == 6:
            app_abort.flag_aborted(data_dir, why=app_abort.AbortedReason.PID1)

        try:
            _LOGGER.info('Moving %r -> %r', running, cleanup)
            fs.replace(running, cleanup)
        except OSError as err:
            if err.errno == errno.ENOENT:
                pass
            else:
                raise

        try:
            supervisor.control_svscan(self._tm_env.running_dir, [
                supervisor.SvscanControlAction.alarm,
                supervisor.SvscanControlAction.nuke
            ])
        except subproc.CalledProcessError as err:
            _LOGGER.warning('Failed to nuke svscan: %r',
                            self._tm_env.running_dir)

        return True
コード例 #2
0
    def run(approot, runtime, container_dir):
        """Runs container given a container dir."""
        # Intercept SIGTERM from s6 supervisor, so that initialization is not
        # left in broken state.
        with lc.LogContext(_LOGGER, os.path.basename(container_dir),
                           lc.ContainerAdapter) as log:
            terminated = utils.make_signal_flag(utils.term_signal())
            tm_env = None
            try:
                log.info('run %r %r', approot, container_dir)
                tm_env = appenv.AppEnvironment(approot)

                app_runtime.get_runtime(runtime, tm_env,
                                        container_dir).run(terminated)

                # If we reach here, the application was terminated.

            except Exception as exc:  # pylint: disable=W0703
                if not terminated:
                    log.critical('Failed to start, app will be aborted.',
                                 exc_info=True)
                    app_abort.flag_aborted(tm_env, container_dir, exc)
                else:
                    log.logger.info('Exception while handling term, ignore.',
                                    exc_info=True)
コード例 #3
0
    def run(approot, runtime, container_dir):
        """Runs container given a container dir."""
        # Make sure container_dir is a fully resolved path.
        container_dir = os.path.realpath(container_dir)

        _LOGGER.info('run %r %r', approot, container_dir)

        tm_env = appenv.AppEnvironment(approot)
        try:
            app_runtime.get_runtime(runtime, tm_env, container_dir).run()

        except Exception as exc:  # pylint: disable=W0703
            _LOGGER.exception('Failed to start, app will be aborted.')
            app_abort.flag_aborted(tm_env, container_dir, exc)
コード例 #4
0
    def test_flag_aborted(self):
        """Tests flag abort sequence."""
        container_dir = os.path.join(self.root, 'apps', 'proid.myapp#001',
                                     'data')
        fs.mkdir_safe(container_dir)

        app_abort.flag_aborted(container_dir,
                               why=app_abort.AbortedReason.INVALID_TYPE,
                               payload='test')

        aborted_file = os.path.join(container_dir, 'aborted')
        with io.open(aborted_file) as f:
            aborted = json.load(f)

        self.assertEqual('invalid_type', aborted.get('why'))
        self.assertEqual('test', aborted.get('payload'))
コード例 #5
0
ファイル: run.py プロジェクト: vrautela/treadmill-workdir
    def run(approot, runtime, container_dir, runtime_param=None):
        """Runs container given a container dir."""
        # Make sure container_dir is a fully resolved path.
        container_dir = os.path.realpath(container_dir)
        service = supervisor.open_service(container_dir)

        _LOGGER.info('run %r %r', approot, container_dir)

        tm_env = appenv.AppEnvironment(approot)
        param = utils.equals_list2dict(runtime_param or [])
        try:
            app_runtime.get_runtime(
                runtime, tm_env, service, param
            ).run()
        except exc.ContainerSetupError as err:
            _LOGGER.exception('Failed to start, app will be aborted.')
            app_abort.flag_aborted(service.data_dir,
                                   why=err.reason,
                                   payload=traceback.format_exc())
        except Exception as err:  # pylint: disable=W0703
            _LOGGER.exception('Failed to start, app will be aborted.')
            app_abort.flag_aborted(service.data_dir,
                                   why=app_abort.AbortedReason.UNKNOWN,
                                   payload=traceback.format_exc())