Fixed PHP timeout option merging bug

This commit is contained in:
Marc Aymerich 2015-06-04 10:23:51 +00:00
parent c3f7c6946f
commit 7d54299b28
3 changed files with 24 additions and 36 deletions

View File

@ -162,18 +162,8 @@ class PHPBackend(WebAppServiceMixin, ServiceController):
)
super(PHPBackend, self).commit()
def get_options(self, webapp):
kwargs = {}
if self.MERGE:
kwargs = {
'webapp__account': webapp.account,
'webapp__type': webapp.type,
'webapp__data__contains': '"php_version":"%s"' % webapp.data['php_version'],
}
return webapp.get_options(**kwargs)
def get_fpm_config(self, webapp, context):
options = self.get_options(webapp)
options = webapp.get_options(merge=self.MERGE)
context.update({
'init_vars': webapp.type_instance.get_php_init_vars(merge=self.MERGE),
'max_children': options.get('processes', settings.WEBAPPS_FPM_DEFAULT_MAX_CHILDREN),
@ -227,7 +217,7 @@ class PHPBackend(WebAppServiceMixin, ServiceController):
exec %(php_binary_path)s%(php_init_vars)s""") % context
def get_fcgid_cmd_options(self, webapp, context):
options = self.get_options(webapp)
options = webapp.get_options(merge=self.MERGE)
maps = OrderedDict(
MaxProcesses=options.get('processes', None),
IOTimeout=options.get('timeout', None),

View File

@ -56,12 +56,17 @@ class WebApp(models.Model):
self.data = apptype.clean_data()
@cached
def get_options(self, **kwargs):
options = OrderedDict()
if not kwargs:
def get_options(self, merge=settings.WEBAPPS_MERGE_PHP_WEBAPPS):
kwargs = {
'webapp_id': self.pk,
}
if merge:
kwargs = {
'webapp_id': self.pk,
'webapp__account': self.account_id,
'webapp__type': self.type,
'webapp__data__contains': '"php_version":"%s"' % self.data['php_version'],
}
options = OrderedDict()
qs = WebAppOption.objects.filter(**kwargs)
for name, value in qs.values_list('name', 'value').order_by('name'):
if name in options:

View File

@ -59,28 +59,22 @@ class PHPApp(AppType):
def get_detail(self):
return self.instance.data.get('php_version', '')
@cached
def get_php_options(self):
php_version = float(self.get_php_version_number())
php_options = AppOption.get_option_groups()[AppOption.PHP]
return [op for op in php_options if (op.deprecated or 999) > php_version]
def get_php_init_vars(self, merge=False):
def get_php_init_vars(self, merge=settings.WEBAPPS_MERGE_PHP_WEBAPPS):
"""
process php options for inclusion on php.ini
per_account=True merges all (account, webapp.type) options
"""
init_vars = OrderedDict()
options = self.instance.options.all().order_by('name')
if merge:
# Get options from the same account and php_version webapps
options = []
php_version = self.get_php_version()
webapps = self.instance.account.webapps.filter(type=self.instance.type)
for webapp in webapps:
if webapp.type_instance.get_php_version() == php_version:
options += list(webapp.options.all())
init_vars = OrderedDict((opt.name, opt.value) for opt in options)
options = self.instance.get_options(merge=merge)
php_version_number = float(self.get_php_version_number())
timeout = None
for name, value in options.items():
if name == 'timeout':
timeout = value
else:
opt = AppOption.get(name)
# Filter non-deprecated PHP options
if opt.group == opt.PHP and (opt.deprecated or 999) > php_version_number:
init_vars[name] = value
# Enable functions
if self.PHP_DISABLED_FUNCTIONS:
enable_functions = init_vars.pop('enable_functions', '')
@ -94,10 +88,9 @@ class PHPApp(AppType):
disable_functions.append(function)
init_vars['disable_functions'] = ','.join(disable_functions)
# process timeout
timeout = self.instance.options.filter(name='timeout').first()
if timeout:
# Give a little slack here
timeout = str(int(timeout.value)-2)
timeout = str(int(timeout)-2)
init_vars['max_execution_time'] = timeout
# Custom error log
if self.PHP_ERROR_LOG_PATH and 'error_log' not in init_vars: