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
|
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):
|
def _build_vhost_config_path(sitename):
|
||||||
return os.path.join(settings.GVAWEB_NGINX_SITES_AVAILABLE, 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)
|
stderr=subprocess.STDOUT)
|
||||||
subprocess.check_output([
|
subprocess.check_output([
|
||||||
SUDO_CMD, RM_CMD, filename], stderr=subprocess.STDOUT)
|
SUDO_CMD, RM_CMD, filename], stderr=subprocess.STDOUT)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError as cpe:
|
||||||
_LOGGER.exception(
|
log_and_raise(
|
||||||
'could not setup site configuration for %s', sitename)
|
cpe, 'could not setup site configuration for %s', sitename)
|
||||||
raise Exception(
|
|
||||||
'could not setup site configuration for %s' % sitename)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -114,11 +118,9 @@ def disable_web_vhost(sitename):
|
||||||
subprocess.check_output([
|
subprocess.check_output([
|
||||||
SUDO_CMD, SERVICE_CMD, 'nginx', 'reload'],
|
SUDO_CMD, SERVICE_CMD, 'nginx', 'reload'],
|
||||||
stderr=subprocess.STDOUT)
|
stderr=subprocess.STDOUT)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError as cpe:
|
||||||
_LOGGER.exception(
|
log_and_raise(
|
||||||
'could not disable site configuration for %s', sitename)
|
cpe, 'could not disable site configuration for %s', sitename)
|
||||||
raise Exception(
|
|
||||||
'could not disable site configuration for %s' % sitename)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -142,11 +144,9 @@ def enable_web_vhost(sitename):
|
||||||
subprocess.check_output([
|
subprocess.check_output([
|
||||||
SUDO_CMD, SERVICE_CMD, 'nginx', 'restart'],
|
SUDO_CMD, SERVICE_CMD, 'nginx', 'restart'],
|
||||||
stderr=subprocess.STDOUT)
|
stderr=subprocess.STDOUT)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError as cpe:
|
||||||
_LOGGER.exception(
|
log_and_raise(
|
||||||
'could not enable site configuration for %s', sitename)
|
cpe, 'could not enable site configuration for %s', sitename)
|
||||||
raise Exception(
|
|
||||||
'could not enable site configuration for %s' % sitename)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -164,11 +164,9 @@ def delete_web_vhost_config(sitename):
|
||||||
subprocess.check_output([
|
subprocess.check_output([
|
||||||
SUDO_CMD, RM_CMD, _build_vhost_config_path(sitename)],
|
SUDO_CMD, RM_CMD, _build_vhost_config_path(sitename)],
|
||||||
stderr=subprocess.STDOUT)
|
stderr=subprocess.STDOUT)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError as cpe:
|
||||||
_LOGGER.exception(
|
log_and_raise(
|
||||||
'could not delete site configuration for %s', sitename)
|
cpe, 'could not delete site configuration for %s', sitename)
|
||||||
raise Exception(
|
|
||||||
'could not delete site configuration for %s' % sitename)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -201,11 +199,8 @@ def create_web_php_fpm_pool_config(username):
|
||||||
subprocess.check_output([
|
subprocess.check_output([
|
||||||
SUDO_CMD, SERVICE_CMD, 'php5-fpm', 'reload'],
|
SUDO_CMD, SERVICE_CMD, 'php5-fpm', 'reload'],
|
||||||
stderr=subprocess.STDOUT)
|
stderr=subprocess.STDOUT)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError as cpe:
|
||||||
_LOGGER.exception(
|
log_and_raise(cpe, 'could not configure PHP FPM for %s', username)
|
||||||
'could not configure PHP FPM for %s', username)
|
|
||||||
raise Exception(
|
|
||||||
'could not configure PHP FPM for %s' % username)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -226,9 +221,7 @@ def delete_web_php_fpm_pool_config(username):
|
||||||
subprocess.check_output([
|
subprocess.check_output([
|
||||||
SUDO_CMD, SERVICE_CMD, 'php5-fpm', 'reload'],
|
SUDO_CMD, SERVICE_CMD, 'php5-fpm', 'reload'],
|
||||||
stderr=subprocess.STDOUT)
|
stderr=subprocess.STDOUT)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError as cpe:
|
||||||
_LOGGER.exception(
|
log_and_raise(
|
||||||
'could not delete PHP FPM configuration for %s', username)
|
cpe, 'could not delete PHP FPM configuration for %s', username)
|
||||||
raise Exception(
|
|
||||||
'could not delete PHP FPM configuration for %s', username)
|
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -3,11 +3,9 @@ server {
|
||||||
{%- if wildcard %}
|
{%- if wildcard %}
|
||||||
server_name *.{{ domain|parentdomain }};
|
server_name *.{{ domain|parentdomain }};
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
listen 80;
|
|
||||||
listen [::]:80;
|
|
||||||
|
|
||||||
access_log /var/log/nginx/{{ domainname }}.access.log;
|
access_log /var/log/nginx/{{ domain }}.access.log;
|
||||||
error_log /var/log/nginx/{{ domainname }}.error.log;
|
error_log /var/log/nginx/{{ domain }}.error.log;
|
||||||
|
|
||||||
client_max_body_size 20M;
|
client_max_body_size 20M;
|
||||||
gzip on;
|
gzip on;
|
||||||
|
@ -21,7 +19,7 @@ server {
|
||||||
try_files $uri =404;
|
try_files $uri =404;
|
||||||
fastcgi_pass unix:/var/run/php5-fpm-{{ user }}.sock;
|
fastcgi_pass unix:/var/run/php5-fpm-{{ user }}.sock;
|
||||||
fastcgi_index index.php;
|
fastcgi_index index.php;
|
||||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_scriptname;
|
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||||
include fastcgi_params;
|
include fastcgi_params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue