示例#1
0
文件: server.py 项目: 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()
示例#2
0
文件: server.py 项目: ajenti/veb
    def __generate_website_config(self, website):
        location_info = []
        for location in website['locations']:
            if location['type'] in ['static', 'proxy', 'fcgi']:
                new_location = location.copy()
                new_location['path'] = absolute_path(location['path'],
                                                     website['root'])
                location_info.append(new_location)
            elif location['type'] == 'app':
                for app in website['apps']:
                    if app['name'] == location['params']['app']:
                        break
                else:
                    logging.warn('Skipping unknown app "%s"',
                                 location['params']['app'])
                    continue

                app_type = AppType.by_name(self.context, app['type'])
                if not app_type:
                    logging.warn('Skipping unknown app type "%s"', app['type'])
                    continue
                new_location = location.copy()
                new_location['type'] = app_type.get_access_type(website, app)
                new_location['params'].update(
                    app_type.get_access_params(website, app))
                new_location['path'] = absolute_path(app['path'],
                                                     website['root'])
                location_info.append(new_location)
            else:
                logging.warn('Skipped unknown location type "%s"',
                             location['type'])

        log_dir = os.path.join(
            SystemConfig.get(self.context).data['log_dir'], website['name'])
        ensure_directory(log_dir,
                         uid=SystemConfig.get(
                             self.context).data['nginx']['user'],
                         mode=0755)

        return Template.by_name(
            self.context,
            'nginx.website.conf').render(data={
                'website': website,
                'location_info': location_info,
            })
示例#3
0
文件: server.py 项目: ajenti/veb
    def __generate_website_config(self, website):
        location_info = []
        for location in website['locations']:
            if location['type'] in ['static', 'proxy', 'fcgi']:
                new_location = location.copy()
                new_location['path'] = absolute_path(location['path'], website['root'])
                location_info.append(new_location)
            elif location['type'] == 'app':
                for app in website['apps']:
                    if app['name'] == location['params']['app']:
                        break
                else:
                    logging.warn('Skipping unknown app "%s"', location['params']['app'])
                    continue

                app_type = AppType.by_name(self.context, app['type'])
                if not app_type:
                    logging.warn('Skipping unknown app type "%s"', app['type'])
                    continue
                new_location = location.copy()
                new_location['type'] = app_type.get_access_type(website, app)
                new_location['params'].update(app_type.get_access_params(website, app))
                new_location['path'] = absolute_path(app['path'], website['root'])
                location_info.append(new_location)
            else:
                logging.warn('Skipped unknown location type "%s"', location['type'])

        log_dir = os.path.join(SystemConfig.get(self.context).data['log_dir'], website['name'])
        ensure_directory(
            log_dir,
            uid=SystemConfig.get(self.context).data['nginx']['user'],
            mode=0755
        )

        return Template.by_name(self.context, 'nginx.website.conf').render(data={
            'website': website,
            'location_info': location_info,
        })
示例#4
0
文件: server.py 项目: 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()
示例#5
0
def _get_config_path(website, app):
    config_dir = os.path.join(vvv.config_dir, 'gunicorn')
    ensure_directory(config_dir)
    return os.path.join(config_dir, _get_module_name(website, app) + '.py')
示例#6
0
文件: python.py 项目: carriercomm/veb
def _get_config_path(website, app):
    config_dir = os.path.join(vvv.config_dir, 'gunicorn')
    ensure_directory(config_dir)
    return os.path.join(config_dir, _get_module_name(website, app) + '.py')