Exemple #1
0
    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,
            })
Exemple #2
0
    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()
Exemple #3
0
    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,
        })
Exemple #4
0
    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()
Exemple #5
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()
Exemple #6
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()
Exemple #7
0
 def configure(self):
     open(SystemConfig.get(self.context).data['php-fpm']['config_file'], 'w').write(
         Template.by_name(self.context, 'fpm.conf').render()
     )
     PHPFPMRestartable.get(self.context).schedule_restart()
Exemple #8
0
 def configure(self):
     open(
         SystemConfig.get(self.context).data['php-fpm']['config_file'],
         'w').write(Template.by_name(self.context, 'fpm.conf').render())
     PHPFPMRestartable.get(self.context).schedule_restart()