Add nginx hashbucket fix and config rollback

This commit is contained in:
VirtuBox
2019-09-27 11:58:02 +02:00
parent 6258f8f093
commit f10acccec3
3 changed files with 36 additions and 17 deletions

View File

@@ -8,6 +8,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### v3.9.x - [Unreleased]
#### Added
- [STACK] Nginx server_names_hash_bucket_size automated fix
- [STACK] Nginx configuration rollback in case of failure after `wo stack upgrade --nginx
- [STACK] Nginx ultimate bad bots blocker with `wo stack install --ngxblocker`
### v3.9.9.1 - 2019-09-26
#### Added

View File

@@ -24,6 +24,7 @@ from wo.core.shellexec import CommandExecutionError, WOShellExec
from wo.core.sslutils import SSL
from wo.core.template import WOTemplate
from wo.core.variables import WOVariables
from wo.core.nginxhashbucket import hashbucket
def pre_pref(self, apt_packages):
@@ -470,20 +471,27 @@ def post_pref(self, apt_packages, packages, upgrade=False):
'> /dev/null 2>&1',
comment='Cloudflare IP refresh cronjob '
'added by WordOps')
if upgrade:
try:
WOShellExec.cmd_exec(self, 'nginx -t')
except CommandExecutionError as e:
Log.debug(self, "{0}".format(e))
Log.info(self, "Rolling-Back Nginx"
"configuration")
WOGit.rollback(self, ["/etc/nginx"])
WOGit.add(self,
["/etc/nginx"], msg="Adding Nginx into Git")
# Nginx Configation into GIT
WOGit.add(self,
["/etc/nginx"], msg="Adding Nginx into Git")
WOService.restart_service(self, 'nginx')
if not WOService.restart_service(self, 'nginx'):
try:
hashbucket(self)
WOService.restart_service(self, 'nginx')
except Exception:
Log.warn(
self, "increasing nginx server_names_hash_bucket_size "
"do not fix the issue")
Log.info(self, "Rolling back to previous configuration")
WOGit.rollback(self, ["/etc/nginx"])
if not WOService.restart_service(self, 'nginx'):
Log.error(
self, "There is an error in Nginx configuration.\n"
"Use the command nginx -t to identify "
"the cause of this issue", False)
if set(WOVariables.wo_php).issubset(set(apt_packages)):
WOGit.add(self, ["/etc/php"], msg="Adding PHP into Git")

View File

@@ -28,8 +28,14 @@ def hashbucket(self):
ngx_hash = math.trunc(math.pow(2, ngx_calc))
# Replace hashbucket in Nginx.conf file
if WOFileUtils.grep(self, "/etc/nginx/nginx.conf",
"server_names_hash_bucket_size"):
if WOFileUtils.grepcheck(self, "/etc/nginx/nginx.conf",
"# server_names_hash_bucket_size 64;"):
ngxconf = open("/etc/nginx/conf.d/hashbucket.conf",
encoding='utf-8', mode='w')
ngxconf.write("\tserver_names_hash_bucket_size {0};".format(ngx_hash))
ngxconf.close()
elif WOFileUtils.grepcheck(self, "/etc/nginx/nginx/conf",
"server_names_hash_bucket_size"):
for line in fileinput.FileInput("/etc/nginx/nginx.conf", inplace=1):
if "server_names_hash_bucket_size" in line:
print("\tserver_names_hash_bucket_size {0};".format(ngx_hash))
@@ -37,8 +43,7 @@ def hashbucket(self):
print(line, end='')
else:
WOFileUtils.searchreplace(self, '/etc/nginx/nginx.conf',
"gzip_disable \"msie6\";",
"gzip_disable \"msie6\";\n"
"\tserver_names_hash_bucket_size {0};\n"
.format(ngx_hash))
ngxconf = open("/etc/nginx/conf.d/hashbucket.conf",
encoding='utf-8', mode='w')
ngxconf.write("\tserver_names_hash_bucket_size {0};".format(ngx_hash))
ngxconf.close()