Ejemplo n.º 1
0
    def run(self):
        cfg = MainConfig.get(self.context)
        for website in cfg.data['websites']:
            if website['name'] == self.website_name:
                website['maintenance_mode'] = self.on
        cfg.save()

        logging.info('Website %s maintenance mode set to: %s', self.website_name, self.on)
Ejemplo n.º 2
0
    def run(self):
        cfg = MainConfig.get(self.context)
        for website in cfg.data['websites']:
            if website['name'] == self.website_name:
                website['maintenance_mode'] = self.on
        cfg.save()

        logging.info('Website %s maintenance mode set to: %s',
                     self.website_name, self.on)
Ejemplo n.º 3
0
    def run(self):
        ws = {
            'name': self.website_name,
        }

        cfg = MainConfig.get(self.context)
        cfg.data['websites'].append(ws)
        cfg.save()

        logging.info('Website %s added', self.website_name)
Ejemplo n.º 4
0
 def configure(self):
     for website in MainConfig.get(self.context).data['websites']:
         if website['enabled']:
             for app in website['apps']:
                 if app['type'] == 'python-wsgi':
                     open(_get_config_path(website, app), 'w').write(
                         Template.by_name(self.context, 'gunicorn').render(data={
                             'website': website,
                             'app': app,
                             'path': absolute_path(app['path'], website['root']),
                         })
                     )
Ejemplo n.º 5
0
 def run(self):
     cfg = MainConfig.get(self.context)
     for ws in cfg.data['websites']:
         if ws['name'] == self.website_name:
             return yaml.safe_dump(
                 ws,
                 default_flow_style=False,
                 encoding='utf-8',
                 allow_unicode=True,
             )
     else:
         raise Exception('Website "%s" not found', self.website_name)
Ejemplo n.º 6
0
Archivo: server.py Proyecto: ajenti/veb
    def configure(self):
        cfg = MainConfig.get(self.context)
        system = SystemConfig.get(self.context)
        shutil.rmtree(system.data['nginx']['config_root'])

        ensure_directory(
            system.data['nginx']['config_root'],
            uid=system.data['nginx']['user'],
            mode=0755
        )
        ensure_directory(
            system.data['nginx']['config_vhost_root'],
            uid=system.data['nginx']['user'],
            mode=0755
        )
        ensure_directory(
            system.data['nginx']['config_custom_root'],
            uid=system.data['nginx']['user'],
            mode=0755
        )
        ensure_directory(
            system.data['log_dir'] + '/nginx',
            uid=system.data['nginx']['user'],
            mode=0755
        )
        ensure_directory(
            system.data['nginx']['lib_path'],
            uid=system.data['nginx']['user'],
            mode=0755
        )

        open(system.data['nginx']['config_file'], 'w').write(
            Template.by_name(self.context, 'nginx.conf').render()
        )
        open(system.data['nginx']['config_file_mime'], 'w').write(
            Template.by_name(self.context, 'nginx.mime.conf').render()
        )
        open(system.data['nginx']['config_file_fastcgi'], 'w').write(
            Template.by_name(self.context, 'nginx.fcgi.conf').render()
        )
        open(system.data['nginx']['config_file_proxy'], 'w').write(
            Template.by_name(self.context, 'nginx.proxy.conf').render()
        )

        for website in cfg.data['websites']:
            if website['enabled']:
                path = os.path.join(system.data['nginx']['config_vhost_root'], website['name'] + '.conf')
                with open(path, 'w') as f:
                    f.write(self.__generate_website_config(website))

        NginxRestartable.get(self.context).schedule_restart()
Ejemplo n.º 7
0
 def configure(self):
     for website in MainConfig.get(self.context).data['websites']:
         if website['enabled']:
             for app in website['apps']:
                 if app['type'] == 'python-wsgi':
                     open(_get_config_path(website, app), 'w').write(
                         Template.by_name(self.context, 'gunicorn').render(
                             data={
                                 'website':
                                 website,
                                 'app':
                                 app,
                                 'path':
                                 absolute_path(app['path'],
                                               website['root']),
                             }))
Ejemplo n.º 8
0
 def get_instances(self):
     for website in MainConfig.get(self.context).data['websites']:
         if website['enabled']:
             prefix = 'veb-app-%s-' % website['name']
             for app in website['apps']:
                 app_type = AppType.by_name(self.context, app['type'])
                 if not app_type:
                     logging.warn('Skipping unknown app type "%s"', app['type'])
                     continue
                 process_info = app_type.get_process(website, app)
                 if process_info:
                     full_name = prefix + app['name'] + process_info.get('suffix', '')
                     yield [{
                         'full_name': full_name,
                         'website': website,
                         'app': app,
                     }]
Ejemplo n.º 9
0
    def run(self):
        cfg = MainConfig.get(self.context)
        for ws in cfg.data['websites']:
            if ws['name'] == self.website_name:
                self.website = ws
                break
        else:
            logging.critical('Website "%s" not found', self.website_name)
            return

        tmp = tempfile.NamedTemporaryFile(delete=False)
        tmp.write(yaml.safe_dump(
            ws,
            default_flow_style=False,
            encoding='utf-8',
            allow_unicode=True,
        ))
        tmp.close()

        editor = os.environ.get('EDITOR', 'nano' if os.path.exists('/usr/bin/nano') else 'vi')

        while True:
            if subprocess.call([editor, tmp.name]) == 0:
                try:
                    new_config = yaml.load(open(tmp.name))
                except Exception as e:
                    logging.critical('Config content is invalid: %s', str(e))
                    logging.info('File is retained in %s', tmp.name)
                    logging.info('Press Enter to continue editing, Ctrl-C to abort')
                    try:
                        raw_input()
                    except KeyboardInterrupt:
                        logging.critical('Aborted')
                        return
                    continue

                ws.update(new_config)
                os.unlink(tmp.name)
                cfg.save()
                logging.info('Updated configuration for %s', self.website_name)
                break
            else:
                logging.critical('Editor exited with an erroneous exitcode')
                logging.info('File is retained in %s', tmp.name)
Ejemplo n.º 10
0
 def get_instances(self):
     for website in MainConfig.get(self.context).data['websites']:
         if website['enabled']:
             prefix = 'veb-app-%s-' % website['name']
             for app in website['apps']:
                 app_type = AppType.by_name(self.context, app['type'])
                 if not app_type:
                     logging.warn('Skipping unknown app type "%s"',
                                  app['type'])
                     continue
                 process_info = app_type.get_process(website, app)
                 if process_info:
                     full_name = prefix + app['name'] + process_info.get(
                         'suffix', '')
                     yield [{
                         'full_name': full_name,
                         'website': website,
                         'app': app,
                     }]
Ejemplo n.º 11
0
Archivo: server.py Proyecto: ajenti/veb
    def configure(self):
        cfg = MainConfig.get(self.context)
        system = SystemConfig.get(self.context)
        shutil.rmtree(system.data['nginx']['config_root'])

        ensure_directory(system.data['nginx']['config_root'],
                         uid=system.data['nginx']['user'],
                         mode=0755)
        ensure_directory(system.data['nginx']['config_vhost_root'],
                         uid=system.data['nginx']['user'],
                         mode=0755)
        ensure_directory(system.data['nginx']['config_custom_root'],
                         uid=system.data['nginx']['user'],
                         mode=0755)
        ensure_directory(system.data['log_dir'] + '/nginx',
                         uid=system.data['nginx']['user'],
                         mode=0755)
        ensure_directory(system.data['nginx']['lib_path'],
                         uid=system.data['nginx']['user'],
                         mode=0755)

        open(system.data['nginx']['config_file'],
             'w').write(Template.by_name(self.context, 'nginx.conf').render())
        open(system.data['nginx']['config_file_mime'], 'w').write(
            Template.by_name(self.context, 'nginx.mime.conf').render())
        open(system.data['nginx']['config_file_fastcgi'], 'w').write(
            Template.by_name(self.context, 'nginx.fcgi.conf').render())
        open(system.data['nginx']['config_file_proxy'], 'w').write(
            Template.by_name(self.context, 'nginx.proxy.conf').render())

        for website in cfg.data['websites']:
            if website['enabled']:
                path = os.path.join(system.data['nginx']['config_vhost_root'],
                                    website['name'] + '.conf')
                with open(path, 'w') as f:
                    f.write(self.__generate_website_config(website))

        NginxRestartable.get(self.context).schedule_restart()
Ejemplo n.º 12
0
    def run(self):
        cfg = MainConfig.get(self.context)

        try:
            website = yaml.load(sys.stdin)
        except Exception as e:
            raise Exception('Config content is invalid: %s', str(e))

        if not isinstance(website, dict):
            raise Exception('Config content is not a dictionary')

        if 'name' not in website:
            raise Exception('Config contains no website name')

        for ws in cfg.data['websites']:
            if ws['name'] == website['name']:
                ws.update(website)
                break
        else:
            cfg.data['websites'].append(website)

        cfg.save()
        logging.info('Updated configuration for %s', website['name'])
Ejemplo n.º 13
0
    def configure(self):
        aug = Augeas(
            modules=[{
                'name': 'Supervisor',
                'lens': 'Supervisor.lns',
                'incl': [
                    SystemConfig.get(self.context).data['supervisor']['config_file'],
                ]
            }],
            loadpath=os.path.dirname(__file__),
        )
        aug_path = '/files' + SystemConfig.get(self.context).data['supervisor']['config_file']
        aug.load()

        for website in MainConfig.get(self.context).data['websites']:
            if website['enabled'] and not website['maintenance_mode']:
                prefix = 'veb-app-%s-' % website['name']

                for path in aug.match(aug_path + '/*'):
                    if aug.get(path + '/#titlecomment') == 'Autogenerated Ajenti V process':
                        aug.remove(path)
                    if aug.get(path + '/#titlecomment') == 'Generated by Ajenti-V':
                        aug.remove(path)
                    if prefix in path:
                        aug.remove(path)

                for app in website['apps']:
                    app_type = AppType.by_name(self.context, app['type'])
                    if not app_type:
                        logging.warn('Skipping unknown app type "%s"', app['type'])
                        continue

                    process_info = app_type.get_process(website, app)
                    if process_info:
                        full_name = prefix + app['name'] + process_info.get('suffix', '')
                        path = aug_path + '/program:%s' % full_name
                        aug.set(path + '/command', process_info['command'])
                        aug.set(
                            path + '/directory',
                            absolute_path(process_info['directory'], website['root']) or website['root']
                        )
                        if process_info['environment']:
                            aug.set(path + '/environment', process_info['environment'])
                        aug.set(path + '/user', process_info['user'])
                        aug.set(path + '/killasgroup', 'true')
                        aug.set(path + '/stopasgroup', 'true')
                        aug.set(path + '/startsecs', str(process_info.get('startsecs', 1)))
                        aug.set(path + '/startretries', str(process_info.get('startretries', 5)))
                        aug.set(path + '/autorestart', str(process_info.get('autorestart', 'unexpected')).lower())
                        aug.set(path + '/stdout_logfile', '%s/%s/%s.stdout.log' % (
                            SystemConfig.get(self.context).data['log_dir'],
                            website['name'],
                            app['name'],
                        ))
                        aug.set(path + '/stderr_logfile', '%s/%s/%s.stderr.log' % (
                            SystemConfig.get(self.context).data['log_dir'],
                            website['name'],
                            app['name'],
                        ))

        aug.save()
        SupervisorRestartable.get(self.context).schedule_restart()
Ejemplo n.º 14
0
    def configure(self):
        aug = Augeas(
            modules=[{
                'name':
                'Supervisor',
                'lens':
                'Supervisor.lns',
                'incl': [
                    SystemConfig.get(
                        self.context).data['supervisor']['config_file'],
                ]
            }],
            loadpath=os.path.dirname(__file__),
        )
        aug_path = '/files' + SystemConfig.get(
            self.context).data['supervisor']['config_file']
        aug.load()

        for website in MainConfig.get(self.context).data['websites']:
            if website['enabled'] and not website['maintenance_mode']:
                prefix = 'veb-app-%s-' % website['name']

                for path in aug.match(aug_path + '/*'):
                    if aug.get(path + '/#titlecomment'
                               ) == 'Autogenerated Ajenti V process':
                        aug.remove(path)
                    if aug.get(path +
                               '/#titlecomment') == 'Generated by Ajenti-V':
                        aug.remove(path)
                    if prefix in path:
                        aug.remove(path)

                for app in website['apps']:
                    app_type = AppType.by_name(self.context, app['type'])
                    if not app_type:
                        logging.warn('Skipping unknown app type "%s"',
                                     app['type'])
                        continue

                    process_info = app_type.get_process(website, app)
                    if process_info:
                        full_name = prefix + app['name'] + process_info.get(
                            'suffix', '')
                        path = aug_path + '/program:%s' % full_name
                        aug.set(path + '/command', process_info['command'])
                        aug.set(
                            path + '/directory',
                            absolute_path(process_info['directory'],
                                          website['root']) or website['root'])
                        if process_info['environment']:
                            aug.set(path + '/environment',
                                    process_info['environment'])
                        aug.set(path + '/user', process_info['user'])
                        aug.set(path + '/killasgroup', 'true')
                        aug.set(path + '/stopasgroup', 'true')
                        aug.set(path + '/startsecs',
                                str(process_info.get('startsecs', 1)))
                        aug.set(path + '/startretries',
                                str(process_info.get('startretries', 5)))
                        aug.set(
                            path + '/autorestart',
                            str(process_info.get('autorestart',
                                                 'unexpected')).lower())
                        aug.set(
                            path + '/stdout_logfile', '%s/%s/%s.stdout.log' % (
                                SystemConfig.get(self.context).data['log_dir'],
                                website['name'],
                                app['name'],
                            ))
                        aug.set(
                            path + '/stderr_logfile', '%s/%s/%s.stderr.log' % (
                                SystemConfig.get(self.context).data['log_dir'],
                                website['name'],
                                app['name'],
                            ))

        aug.save()
        SupervisorRestartable.get(self.context).schedule_restart()
Ejemplo n.º 15
0
 def run(self):
     cfg = MainConfig.get(self.context)
     for ws in cfg.data['websites']:
         print '- %s' % ws['name']