Fixed PHP timeout option merging bug
This commit is contained in:
parent
c3f7c6946f
commit
7d54299b28
|
@ -162,18 +162,8 @@ class PHPBackend(WebAppServiceMixin, ServiceController):
|
||||||
)
|
)
|
||||||
super(PHPBackend, self).commit()
|
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):
|
def get_fpm_config(self, webapp, context):
|
||||||
options = self.get_options(webapp)
|
options = webapp.get_options(merge=self.MERGE)
|
||||||
context.update({
|
context.update({
|
||||||
'init_vars': webapp.type_instance.get_php_init_vars(merge=self.MERGE),
|
'init_vars': webapp.type_instance.get_php_init_vars(merge=self.MERGE),
|
||||||
'max_children': options.get('processes', settings.WEBAPPS_FPM_DEFAULT_MAX_CHILDREN),
|
'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
|
exec %(php_binary_path)s%(php_init_vars)s""") % context
|
||||||
|
|
||||||
def get_fcgid_cmd_options(self, webapp, context):
|
def get_fcgid_cmd_options(self, webapp, context):
|
||||||
options = self.get_options(webapp)
|
options = webapp.get_options(merge=self.MERGE)
|
||||||
maps = OrderedDict(
|
maps = OrderedDict(
|
||||||
MaxProcesses=options.get('processes', None),
|
MaxProcesses=options.get('processes', None),
|
||||||
IOTimeout=options.get('timeout', None),
|
IOTimeout=options.get('timeout', None),
|
||||||
|
|
|
@ -56,12 +56,17 @@ class WebApp(models.Model):
|
||||||
self.data = apptype.clean_data()
|
self.data = apptype.clean_data()
|
||||||
|
|
||||||
@cached
|
@cached
|
||||||
def get_options(self, **kwargs):
|
def get_options(self, merge=settings.WEBAPPS_MERGE_PHP_WEBAPPS):
|
||||||
options = OrderedDict()
|
|
||||||
if not kwargs:
|
|
||||||
kwargs = {
|
kwargs = {
|
||||||
'webapp_id': self.pk,
|
'webapp_id': self.pk,
|
||||||
}
|
}
|
||||||
|
if merge:
|
||||||
|
kwargs = {
|
||||||
|
'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)
|
qs = WebAppOption.objects.filter(**kwargs)
|
||||||
for name, value in qs.values_list('name', 'value').order_by('name'):
|
for name, value in qs.values_list('name', 'value').order_by('name'):
|
||||||
if name in options:
|
if name in options:
|
||||||
|
|
|
@ -59,28 +59,22 @@ class PHPApp(AppType):
|
||||||
def get_detail(self):
|
def get_detail(self):
|
||||||
return self.instance.data.get('php_version', '')
|
return self.instance.data.get('php_version', '')
|
||||||
|
|
||||||
@cached
|
def get_php_init_vars(self, merge=settings.WEBAPPS_MERGE_PHP_WEBAPPS):
|
||||||
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):
|
|
||||||
"""
|
"""
|
||||||
process php options for inclusion on php.ini
|
process php options for inclusion on php.ini
|
||||||
per_account=True merges all (account, webapp.type) options
|
|
||||||
"""
|
"""
|
||||||
init_vars = OrderedDict()
|
init_vars = OrderedDict()
|
||||||
options = self.instance.options.all().order_by('name')
|
options = self.instance.get_options(merge=merge)
|
||||||
if merge:
|
php_version_number = float(self.get_php_version_number())
|
||||||
# Get options from the same account and php_version webapps
|
timeout = None
|
||||||
options = []
|
for name, value in options.items():
|
||||||
php_version = self.get_php_version()
|
if name == 'timeout':
|
||||||
webapps = self.instance.account.webapps.filter(type=self.instance.type)
|
timeout = value
|
||||||
for webapp in webapps:
|
else:
|
||||||
if webapp.type_instance.get_php_version() == php_version:
|
opt = AppOption.get(name)
|
||||||
options += list(webapp.options.all())
|
# Filter non-deprecated PHP options
|
||||||
init_vars = OrderedDict((opt.name, opt.value) for opt in options)
|
if opt.group == opt.PHP and (opt.deprecated or 999) > php_version_number:
|
||||||
|
init_vars[name] = value
|
||||||
# Enable functions
|
# Enable functions
|
||||||
if self.PHP_DISABLED_FUNCTIONS:
|
if self.PHP_DISABLED_FUNCTIONS:
|
||||||
enable_functions = init_vars.pop('enable_functions', '')
|
enable_functions = init_vars.pop('enable_functions', '')
|
||||||
|
@ -94,10 +88,9 @@ class PHPApp(AppType):
|
||||||
disable_functions.append(function)
|
disable_functions.append(function)
|
||||||
init_vars['disable_functions'] = ','.join(disable_functions)
|
init_vars['disable_functions'] = ','.join(disable_functions)
|
||||||
# process timeout
|
# process timeout
|
||||||
timeout = self.instance.options.filter(name='timeout').first()
|
|
||||||
if timeout:
|
if timeout:
|
||||||
# Give a little slack here
|
# Give a little slack here
|
||||||
timeout = str(int(timeout.value)-2)
|
timeout = str(int(timeout)-2)
|
||||||
init_vars['max_execution_time'] = timeout
|
init_vars['max_execution_time'] = timeout
|
||||||
# Custom error log
|
# Custom error log
|
||||||
if self.PHP_ERROR_LOG_PATH and 'error_log' not in init_vars:
|
if self.PHP_ERROR_LOG_PATH and 'error_log' not in init_vars:
|
||||||
|
|
Loading…
Reference in New Issue