Exemplo n.º 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
Exemplo n.º 2
0
def _rename_file(src, dst):
    """Rename the specified file"""

    fs.replace(src, dst)
    mode = os.stat(dst).st_mode
    mode |= (stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
    if _is_executable(dst):
        mode |= (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
    os.chmod(dst, mode)
Exemplo n.º 3
0
 def add(self, _princ, keytabs):
     """Add keytab to locker.
     if client has permission to access a keytab,
     we added it to spool dir after validating the keytabs
     """
     # Use kt-split to validate keytab
     # if validated, return keytab files else return None
     for kt in kt_split.validate_as_file(keytabs, self._kt_spool_tmp_dir):
         dest_kt = os.path.join(self._kt_spool_dir, os.path.basename(kt))
         fs.replace(kt, dest_kt)
Exemplo n.º 4
0
    def _terminate(self, instance_name):
        """Removes application from the supervised running list.

        Move the link from running directory to the cleanup directory.

        :param instance_name:
            Name of the instance to configure
        :type instance_name:
            ``str``
        """
        # In case the node is deleted from zookeeper (app is terminated),
        # the "services" directory still exists, and it is the job of
        # svscan to terminate the process.
        #
        # If services directory does not exist, app finished on it's own, and
        # the zk node was deleted by the cleanup script.
        #
        instance_run_link = os.path.join(
            self.tm_env.running_dir,
            instance_name
        )

        container_dir = self._resolve_running_link(instance_run_link)

        _LOGGER.info('terminating %sfinished %r (%r)',
                     ('not ' if os.path.exists(container_dir) else ''),
                     instance_name, container_dir)

        container_name = os.path.basename(container_dir)
        container_cleanup_link = os.path.join(
            self.tm_env.cleanup_dir,
            container_name
        )

        try:
            fs.replace(instance_run_link, container_cleanup_link)
            utils.touch(os.path.join(container_dir, 'data', 'terminated'))
        except OSError as err:
            # It is OK if the symlink is already removed (race with app own
            # cleanup).  Everything else is an error.
            if err.errno == errno.ENOENT:
                pass
            else:
                raise