Exemplo n.º 1
0
    def launch_rotate(self):
        log_file = self.log_file

        # We save in a file ?
        if log_file is None:
            return

        # Find the more recent date
        dates = []
        n2 = '[0-9][0-9]'
        date_pattern = n2 + n2 + '-' + n2 + '-' + n2 + '_' + n2 + n2
        for name in glob(log_file + '.' + date_pattern + '.gz'):
            try:
                date = datetime.strptime(name[-18:-3], '%Y-%m-%d_%H%M')
            except ValueError:
                continue
            dates.append(date)
        if dates:
            dates.sort()
            last = dates[-1]
        else:
            # If here, there is no rotated files => so, we create one
            self.rotate()
            last = datetime.now()

        # Compute the next call
        next_call = last + self.rotate_interval - datetime.now()
        if next_call <= timedelta(0):
            next_call = timedelta(seconds=1)

        # Call cron
        cron(self.rotate, next_call)
Exemplo n.º 2
0
    def launch_rotate(self):
        log_file = self.log_file

        # We save in a file ?
        if log_file is None:
            return

        # Find the more recent date
        dates = []
        n2 = '[0-9][0-9]'
        date_pattern = n2 + n2 + '-' + n2 + '-' + n2 + '_' + n2 + n2
        for name in glob(log_file + '.' + date_pattern + '.gz'):
            try:
                date = datetime.strptime(name[-18:-3], '%Y-%m-%d_%H%M')
            except ValueError:
                continue
            dates.append(date)
        if dates:
            dates.sort()
            last = dates[-1]
        else:
            # If here, there is no rotated files => so, we create one
            self.rotate()
            last = datetime.now()

        # Compute the next call
        next_call = last + self.rotate_interval - datetime.now()
        if next_call <= timedelta(0):
            next_call = timedelta(seconds=1)

        # Call cron
        cron(self.rotate, next_call)
Exemplo n.º 3
0
 def launch_rotate(self):
     last = self.get_last_rotate_date()
     # If here, there is no rotated files => so, we create one
     if not last:
         last = datetime.now()
         self.rotate()
     # Compute the next call
     next_call = last + self.rotate_interval - datetime.now()
     if next_call <= timedelta(0):
         next_call = timedelta(seconds=1)
     # Call cron
     cron(self.rotate, next_call)
Exemplo n.º 4
0
    def start(self, detach=False, profile=False, loop=True):
        profile = ('%s/log/profile' % self.target) if profile else None
        self.loop = ServerLoop(
              target=self.target,
              server=self,
              profile=profile)
        # Daemon mode
        if detach:
            become_daemon()

        # Update Git tree-cache, to speed things up
        self.database.worktree.update_tree_cache()

        # Find out the IP to listen to
        address = self.config.get_value('listen-address').strip()
        if not address:
            raise ValueError, 'listen-address is missing from config.conf'
        if address == '*':
            address = None

        # Find out the port to listen
        port = self.config.get_value('listen-port')
        if port is None:
            raise ValueError, 'listen-port is missing from config.conf'

        # Listen & set context
        root = self.root
        self.listen(address, port)

        # Call method on root at start
        context = get_context()
        root.launch_at_start(context)

        # Set cron interval
        interval = self.config.get_value('cron-interval')
        if interval:
            cron(self.cron_manager, interval)

        # Init loop
        if loop:
            try:
                self.loop.run()
            except KeyboardInterrupt:
                self.close()
        # Ok
        return True
Exemplo n.º 5
0
 def flush_spool(self):
     cron(self._smtp_send, timedelta(seconds=1))
Exemplo n.º 6
0
def start(options, target):
    # Check the server is not running
    pid = get_pid('%s/pid' % target)
    if pid is not None:
        print '[%s] The Web Server is already running.' % target
        return 1
    # XXX Obsolete code, remove by 0.70
    sub_pid = get_pid('%s/pid-subprocess' % target)
    if sub_pid is not None:
        print(
            '[%s] The Web Server subprocess is running, please use '
            'icms-stop.py to stop it.') % target
        return 1

    # Check for database consistency
    if options.quick is False and check_database(target) is False:
        return 1

    # Check instance is up to date
    if not is_instance_up_to_date(target):
        print 'The instance is not up-to-date, please type:'
        print
        print '    $ icms-update.py %s' % target
        print
        return 1

    # Daemon mode
    if options.detach:
        become_daemon()

    # Set-up the server
    server = Server(target,
                    read_only=options.read_only,
                    profile_space=options.profile_space)

    # Update Git tree-cache, to speed things up
    server.database.worktree.update_tree_cache()

    # Find out the IP to listen to
    config = server.config
    address = config.get_value('listen-address').strip()
    if not address:
        raise ValueError, 'listen-address is missing from config.conf'
    if address == '*':
        address = None

    # Find out the port to listen
    port = config.get_value('listen-port')
    if port is None:
        raise ValueError, 'listen-port is missing from config.conf'

    server.listen(address, port)
    server.set_context('/', CMSContext)
    interval = config.get_value('cron-interval')
    if interval:
        cron(server.cron_manager, 1)

    # Run
    profile = options.profile_time
    profile = ('%s/log/profile' % target) if profile else None
    loop = Loop(pid_file='%s/pid' % target, profile=profile)
    loop.run()

    # Ok
    return 0
Exemplo n.º 7
0
def start(options, target):
    # Check the server is not running
    pid = get_pid('%s/pid' % target)
    if pid is not None:
        print '[%s] The Web Server is already running.' % target
        return 1
    # XXX Obsolete code, remove by 0.70
    sub_pid = get_pid('%s/pid-subprocess' % target)
    if sub_pid is not None:
        print ('[%s] The Web Server subprocess is running, please use '
               'icms-stop.py to stop it.') % target
        return 1

    # Check for database consistency
    if options.quick is False and check_database(target) is False:
        return 1

    # Check instance is up to date
    if not is_instance_up_to_date(target):
        print 'The instance is not up-to-date, please type:'
        print
        print '    $ icms-update.py %s' % target
        print
        return 1

    # Daemon mode
    if options.detach:
        become_daemon()

    # Set-up the server
    server = Server(target, read_only=options.read_only,
                    profile_space=options.profile_space)

    # Update Git tree-cache, to speed things up
    server.database.worktree.update_tree_cache()

    # Find out the IP to listen to
    config = server.config
    address = config.get_value('listen-address').strip()
    if not address:
        raise ValueError, 'listen-address is missing from config.conf'
    if address == '*':
        address = None

    # Find out the port to listen
    port = config.get_value('listen-port')
    if port is None:
        raise ValueError, 'listen-port is missing from config.conf'

    server.listen(address, port)
    server.set_context('/', CMSContext)
    interval = config.get_value('cron-interval')
    if interval:
        cron(server.cron_manager, 1)

    # Run
    profile = options.profile_time
    profile = ('%s/log/profile' % target) if profile else None
    loop = Loop(pid_file='%s/pid' % target, profile=profile)
    loop.run()

    # Ok
    return 0
Exemplo n.º 8
0
 def launch_cron(self):
     # Set cron interval
     interval = self.config.get_value('cron-interval')
     if interval:
         cron(self.cron_manager, interval)