Пример #1
0
 def get_process(self, website, app):
     p = {
         'command':
         'gunicorn -c %s %s' % (
             _get_config_path(website, app),
             app['params']['module'],
         ),
         'user':
         app['params']['user'],
         'environment':
         app['params']['environment'],
         'autorestart':
         app['params']['autorestart'],
         'startretries':
         app['params']['startretries'],
         'startsecs':
         app['params']['startsecs'],
         'directory':
         absolute_path(app['path'], website['root']),
     }
     virtualenv = app['params']['virtualenv']
     if virtualenv:
         virtualenv = absolute_path(
             virtualenv, absolute_path(app['path'], website['root']))
         p['environment'] = 'PATH="%s:%s"' % (
             os.path.join(virtualenv, 'bin'),
             os.environ['PATH'],
         )
         p['command'] = os.path.join(virtualenv, 'bin') + '/' + p['command']
     return p
Пример #2
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,
            })
Пример #3
0
 def get_process(self, website, app):
     p = {
         'command': 'gunicorn -c %s %s' % (
             _get_config_path(website, app),
             app['params']['module'],
         ),
         'user': app['params']['user'],
         'environment': app['params']['environment'],
         'directory': absolute_path(app['path'], website['root']),
     }
     virtualenv = app['params']['virtualenv']
     if virtualenv:
         virtualenv = absolute_path(virtualenv, absolute_path(app['path'], website['root']))
         p['environment'] = 'PATH="%s:%s"' % (
             os.path.join(virtualenv, 'bin'),
             os.environ['PATH'],
         )
         p['command'] = os.path.join(virtualenv, 'bin') + '/' + p['command']
     return p
Пример #4
0
 def get_process(self, website, app):
     p = {
         'command': '%s %s' % (
             app['params']['node_binary'],
             app['params']['script'] or '.',
         ),
         'user': app['params']['user'],
         'environment': app['params']['environment'],
         'directory': absolute_path(app['path'], website['root']),
     }
     return p
Пример #5
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']),
                         })
                     )
Пример #6
0
 def get_process(self, website, app):
     cmd = app['params']['command']
     if cmd.startswith('./'):
         if app['path']:
             cmd = os.path.join(absolute_path(app['path'], website['root']), cmd[2:])
         else:
             cmd = os.path.join(website['root'], cmd[2:])
     return {
         'command': cmd,
         'directory': app['path'] or website['root'],
         'environment': app['params']['environment'],
         'user': app['params']['user'],
     }
Пример #7
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,
        })
Пример #8
0
 def get_process(self, website, app):
     cmd = app['params']['command']
     if cmd.startswith('./'):
         if app['path']:
             cmd = os.path.join(absolute_path(app['path'], website['root']),
                                cmd[2:])
         else:
             cmd = os.path.join(website['root'], cmd[2:])
     return {
         'command': cmd,
         'directory': app['path'] or website['root'],
         'environment': app['params']['environment'],
         'user': app['params']['user'],
     }
Пример #9
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']),
                             }))
Пример #10
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()
Пример #11
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()