Add nginx hashbucket fix and config rollback
This commit is contained in:
@@ -8,6 +8,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|||||||
|
|
||||||
### v3.9.x - [Unreleased]
|
### 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
|
### v3.9.9.1 - 2019-09-26
|
||||||
|
|
||||||
#### Added
|
#### Added
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ from wo.core.shellexec import CommandExecutionError, WOShellExec
|
|||||||
from wo.core.sslutils import SSL
|
from wo.core.sslutils import SSL
|
||||||
from wo.core.template import WOTemplate
|
from wo.core.template import WOTemplate
|
||||||
from wo.core.variables import WOVariables
|
from wo.core.variables import WOVariables
|
||||||
|
from wo.core.nginxhashbucket import hashbucket
|
||||||
|
|
||||||
|
|
||||||
def pre_pref(self, apt_packages):
|
def pre_pref(self, apt_packages):
|
||||||
@@ -470,20 +471,27 @@ def post_pref(self, apt_packages, packages, upgrade=False):
|
|||||||
'> /dev/null 2>&1',
|
'> /dev/null 2>&1',
|
||||||
comment='Cloudflare IP refresh cronjob '
|
comment='Cloudflare IP refresh cronjob '
|
||||||
'added by WordOps')
|
'added by WordOps')
|
||||||
|
WOGit.add(self,
|
||||||
if upgrade:
|
["/etc/nginx"], msg="Adding Nginx into Git")
|
||||||
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"])
|
|
||||||
|
|
||||||
# Nginx Configation into GIT
|
# Nginx Configation into GIT
|
||||||
WOGit.add(self,
|
WOGit.add(self,
|
||||||
["/etc/nginx"], msg="Adding Nginx into Git")
|
["/etc/nginx"], msg="Adding Nginx into Git")
|
||||||
|
if not WOService.restart_service(self, 'nginx'):
|
||||||
|
try:
|
||||||
|
hashbucket(self)
|
||||||
WOService.restart_service(self, 'nginx')
|
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)):
|
if set(WOVariables.wo_php).issubset(set(apt_packages)):
|
||||||
WOGit.add(self, ["/etc/php"], msg="Adding PHP into Git")
|
WOGit.add(self, ["/etc/php"], msg="Adding PHP into Git")
|
||||||
|
|||||||
@@ -28,7 +28,13 @@ def hashbucket(self):
|
|||||||
ngx_hash = math.trunc(math.pow(2, ngx_calc))
|
ngx_hash = math.trunc(math.pow(2, ngx_calc))
|
||||||
|
|
||||||
# Replace hashbucket in Nginx.conf file
|
# Replace hashbucket in Nginx.conf file
|
||||||
if WOFileUtils.grep(self, "/etc/nginx/nginx.conf",
|
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"):
|
"server_names_hash_bucket_size"):
|
||||||
for line in fileinput.FileInput("/etc/nginx/nginx.conf", inplace=1):
|
for line in fileinput.FileInput("/etc/nginx/nginx.conf", inplace=1):
|
||||||
if "server_names_hash_bucket_size" in line:
|
if "server_names_hash_bucket_size" in line:
|
||||||
@@ -37,8 +43,7 @@ def hashbucket(self):
|
|||||||
print(line, end='')
|
print(line, end='')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
WOFileUtils.searchreplace(self, '/etc/nginx/nginx.conf',
|
ngxconf = open("/etc/nginx/conf.d/hashbucket.conf",
|
||||||
"gzip_disable \"msie6\";",
|
encoding='utf-8', mode='w')
|
||||||
"gzip_disable \"msie6\";\n"
|
ngxconf.write("\tserver_names_hash_bucket_size {0};".format(ngx_hash))
|
||||||
"\tserver_names_hash_bucket_size {0};\n"
|
ngxconf.close()
|
||||||
.format(ngx_hash))
|
|
||||||
|
|||||||
Reference in New Issue
Block a user