Exemplo n.º 1
0
 def execute(self, *args, **options):
     '''
     Just wrapping a timer around regular execution.
     '''
     logger.debug('Command line arguments: %s' % options)
     start_time = time.time()
     output = BaseCommand.execute(self, *args, **options)
     logger.debug('Command execution is done in %s seconds.' %
                  (time.time() - start_time))
     return output
Exemplo n.º 2
0
    def execute(self, *args, **options):
        """
        Takes the options and starts a daemon context from them.

        Example::

            python manage.py linkconsumer --pidfile=/var/run/cb_link.pid
                --stdout=/var/log/cb/links.out --stderr=/var/log/cb/links.err

        """
        # print 20130610, 'execute', __file__

        #~ print options

        if daemon is not None:

            context = daemon.DaemonContext()

            context.chroot_directory = self.get_option_value(
                options, 'chroot_directory')
            context.working_directory = self.get_option_value(
                options, 'working_directory', '/')
            context.umask = self.get_option_value(options, 'umask', 0)
            context.detach_process = self.get_option_value(
                options, 'detach_process')
            context.prevent_core = self.get_option_value(
                options, 'prevent_core', True)
            if self.preserve_loggers:
                context.files_preserve = get_logger_files(
                    self.preserve_loggers)

            # Get file objects
            # stdin =  self.get_option_value(options, 'stdin')
            stdin = options.pop('stdin', None)
            if stdin is not None:
                options['stdin'] = context.stdin = open(stdin, "r")

            # stdout = self.get_option_value(options, 'stdout')
            stdout = options.pop('stdout', None)
            if stdout is not None:
                options['stdout'] = context.stdout = open(stdout, "a+")

            # stderr = self.get_option_value(options, 'stderr')
            stderr = options.pop('stderr', None)
            if stderr is not None:
                self.stderr = options[
                    'stderr'] = context.stderr = open(stderr, "a+")
            # self.stderr is needed in case there is an exception during execute.
            # Django then would try to write to sys.stderr which is None because
            # we are a daemon

            # Make pid lock file
            pidfile = self.get_option_value(options, 'pidfile')
            if pidfile is not None:
                #~ context.pidfile=pidlockfile.PIDLockFile(pidfile)
                context.pidfile = pidlockfile.TimeoutPIDLockFile(pidfile, 0)

            uid = self.get_option_value(options, 'uid')
            if uid is not None:
                context.uid = uid

            gid = self.get_option_value(options, 'gid')
            if gid is not None:
                context.gid = uid

            context.open()

        # Django 1.5.1 needs them:
        # for k in ('stdout','stderr'):
        #     options[k] = getattr(context,k,None)

        # self.handle_daemon(*args, **options)
        BaseCommand.execute(self, *args, **options)
Exemplo n.º 3
0
    def execute(self, *args, **options):
        """
        Takes the options and starts a daemon context from them.

        Example::

            python manage.py linkconsumer --pidfile=/var/run/cb_link.pid
                --stdout=/var/log/cb/links.out --stderr=/var/log/cb/links.err

        """
        # print 20130610, 'execute', __file__

        #~ print options

        if daemon is not None:

            context = daemon.DaemonContext()

            context.chroot_directory = self.get_option_value(
                options, 'chroot_directory')
            context.working_directory = self.get_option_value(
                options, 'working_directory', '/')
            context.umask = self.get_option_value(options, 'umask', 0)
            context.detach_process = self.get_option_value(
                options, 'detach_process')
            context.prevent_core = self.get_option_value(
                options, 'prevent_core', True)
            if self.preserve_loggers:
                context.files_preserve = get_logger_files(
                    self.preserve_loggers)

            # Get file objects
            # stdin =  self.get_option_value(options, 'stdin')
            stdin = options.pop('stdin', None)
            if stdin is not None:
                options['stdin'] = context.stdin = open(stdin, "r")

            # stdout = self.get_option_value(options, 'stdout')
            stdout = options.pop('stdout', None)
            if stdout is not None:
                options['stdout'] = context.stdout = open(stdout, "a+")

            # stderr = self.get_option_value(options, 'stderr')
            stderr = options.pop('stderr', None)
            if stderr is not None:
                self.stderr = options['stderr'] = context.stderr = open(
                    stderr, "a+")
            # self.stderr is needed in case there is an exception during execute.
            # Django then would try to write to sys.stderr which is None because
            # we are a daemon

            # Make pid lock file
            pidfile = self.get_option_value(options, 'pidfile')
            if pidfile is not None:
                #~ context.pidfile=pidlockfile.PIDLockFile(pidfile)
                context.pidfile = pidlockfile.TimeoutPIDLockFile(pidfile, 0)

            uid = self.get_option_value(options, 'uid')
            if uid is not None:
                context.uid = int(uid)

            gid = self.get_option_value(options, 'gid')
            if gid is not None:
                context.gid = int(gid)

            context.open()

        # Django 1.5.1 needs them:
        # for k in ('stdout','stderr'):
        #     options[k] = getattr(context,k,None)

        # self.handle_daemon(*args, **options)
        BaseCommand.execute(self, *args, **options)