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, }]
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, })
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, }]
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, })
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()
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()