unify exception handling, fix nginx template
This commit is contained in:
parent
35b102a7b7
commit
7dc3a634f7
2 changed files with 26 additions and 35 deletions
|
@ -34,6 +34,12 @@ def _jinja_parentdomain(domain):
|
|||
JINJAENV.filters['parentdomain'] = _jinja_parentdomain
|
||||
|
||||
|
||||
def log_and_raise(exception, message, *args):
|
||||
logargs = list(args) + [exception.returncode, exception.output]
|
||||
_LOGGER.error(message + "\nreturncode: %d\noutput:\n%s", *logargs)
|
||||
raise Exception(message % args)
|
||||
|
||||
|
||||
def _build_vhost_config_path(sitename):
|
||||
return os.path.join(settings.GVAWEB_NGINX_SITES_AVAILABLE, sitename)
|
||||
|
||||
|
@ -89,11 +95,9 @@ def create_web_vhost_config(username, sitename, wildcard):
|
|||
stderr=subprocess.STDOUT)
|
||||
subprocess.check_output([
|
||||
SUDO_CMD, RM_CMD, filename], stderr=subprocess.STDOUT)
|
||||
except subprocess.CalledProcessError:
|
||||
_LOGGER.exception(
|
||||
'could not setup site configuration for %s', sitename)
|
||||
raise Exception(
|
||||
'could not setup site configuration for %s' % sitename)
|
||||
except subprocess.CalledProcessError as cpe:
|
||||
log_and_raise(
|
||||
cpe, 'could not setup site configuration for %s', sitename)
|
||||
return True
|
||||
|
||||
|
||||
|
@ -114,11 +118,9 @@ def disable_web_vhost(sitename):
|
|||
subprocess.check_output([
|
||||
SUDO_CMD, SERVICE_CMD, 'nginx', 'reload'],
|
||||
stderr=subprocess.STDOUT)
|
||||
except subprocess.CalledProcessError:
|
||||
_LOGGER.exception(
|
||||
'could not disable site configuration for %s', sitename)
|
||||
raise Exception(
|
||||
'could not disable site configuration for %s' % sitename)
|
||||
except subprocess.CalledProcessError as cpe:
|
||||
log_and_raise(
|
||||
cpe, 'could not disable site configuration for %s', sitename)
|
||||
return True
|
||||
|
||||
|
||||
|
@ -142,11 +144,9 @@ def enable_web_vhost(sitename):
|
|||
subprocess.check_output([
|
||||
SUDO_CMD, SERVICE_CMD, 'nginx', 'restart'],
|
||||
stderr=subprocess.STDOUT)
|
||||
except subprocess.CalledProcessError:
|
||||
_LOGGER.exception(
|
||||
'could not enable site configuration for %s', sitename)
|
||||
raise Exception(
|
||||
'could not enable site configuration for %s' % sitename)
|
||||
except subprocess.CalledProcessError as cpe:
|
||||
log_and_raise(
|
||||
cpe, 'could not enable site configuration for %s', sitename)
|
||||
return True
|
||||
|
||||
|
||||
|
@ -164,11 +164,9 @@ def delete_web_vhost_config(sitename):
|
|||
subprocess.check_output([
|
||||
SUDO_CMD, RM_CMD, _build_vhost_config_path(sitename)],
|
||||
stderr=subprocess.STDOUT)
|
||||
except subprocess.CalledProcessError:
|
||||
_LOGGER.exception(
|
||||
'could not delete site configuration for %s', sitename)
|
||||
raise Exception(
|
||||
'could not delete site configuration for %s' % sitename)
|
||||
except subprocess.CalledProcessError as cpe:
|
||||
log_and_raise(
|
||||
cpe, 'could not delete site configuration for %s', sitename)
|
||||
return True
|
||||
|
||||
|
||||
|
@ -201,11 +199,8 @@ def create_web_php_fpm_pool_config(username):
|
|||
subprocess.check_output([
|
||||
SUDO_CMD, SERVICE_CMD, 'php5-fpm', 'reload'],
|
||||
stderr=subprocess.STDOUT)
|
||||
except subprocess.CalledProcessError:
|
||||
_LOGGER.exception(
|
||||
'could not configure PHP FPM for %s', username)
|
||||
raise Exception(
|
||||
'could not configure PHP FPM for %s' % username)
|
||||
except subprocess.CalledProcessError as cpe:
|
||||
log_and_raise(cpe, 'could not configure PHP FPM for %s', username)
|
||||
return True
|
||||
|
||||
|
||||
|
@ -226,9 +221,7 @@ def delete_web_php_fpm_pool_config(username):
|
|||
subprocess.check_output([
|
||||
SUDO_CMD, SERVICE_CMD, 'php5-fpm', 'reload'],
|
||||
stderr=subprocess.STDOUT)
|
||||
except subprocess.CalledProcessError:
|
||||
_LOGGER.exception(
|
||||
'could not delete PHP FPM configuration for %s', username)
|
||||
raise Exception(
|
||||
'could not delete PHP FPM configuration for %s', username)
|
||||
except subprocess.CalledProcessError as cpe:
|
||||
log_and_raise(
|
||||
cpe, 'could not delete PHP FPM configuration for %s', username)
|
||||
return True
|
||||
|
|
|
@ -3,11 +3,9 @@ server {
|
|||
{%- if wildcard %}
|
||||
server_name *.{{ domain|parentdomain }};
|
||||
{%- endif %}
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
|
||||
access_log /var/log/nginx/{{ domainname }}.access.log;
|
||||
error_log /var/log/nginx/{{ domainname }}.error.log;
|
||||
access_log /var/log/nginx/{{ domain }}.access.log;
|
||||
error_log /var/log/nginx/{{ domain }}.error.log;
|
||||
|
||||
client_max_body_size 20M;
|
||||
gzip on;
|
||||
|
@ -21,7 +19,7 @@ server {
|
|||
try_files $uri =404;
|
||||
fastcgi_pass unix:/var/run/php5-fpm-{{ user }}.sock;
|
||||
fastcgi_index index.php;
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_scriptname;
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
include fastcgi_params;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue