diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 8991ec5e..3839fd15 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,7 @@ +v 3.1.3 - May 6, 2015 +- EasyEngine now fixes missing GPG keys automatically, fixes #470 +- Fixed Nginx hash bucket issue, fixes #449 + v 3.1.2 - April 29, 2015 - Updated PHP version from PHP 5.5 to PHP 5.6 #425 - Added ee stack upgrade command for stack upgrade #458 diff --git a/ee/cli/plugins/site.py b/ee/cli/plugins/site.py index d90cefdb..54a130e0 100644 --- a/ee/cli/plugins/site.py +++ b/ee/cli/plugins/site.py @@ -9,6 +9,7 @@ from ee.core.services import EEService from ee.cli.plugins.sitedb import * from ee.core.git import EEGit from subprocess import Popen +from ee.core.nginxhashbucket import hashbucket import sys import os import glob @@ -471,10 +472,20 @@ class EESiteCreateController(CementBaseController): # Check rerequired packages are installed or not ee_auth = site_package_check(self, stype) + + try: + pre_run_checks(self) + except SiteError as e: + Log.debug(self, str(e)) + Log.error(self, "NGINX configuration check failed.") + try: try: # setup NGINX configuration, and webroot setupdomain(self, data) + + # Fix Nginx Hashbucket size error + hashbucket(self) except SiteError as e: # call cleanup actions on failure Log.info(self, Log.FAIL + "Oops Something went wrong !!") diff --git a/ee/cli/templates/22222.mustache b/ee/cli/templates/22222.mustache index c0897d54..3893b90e 100644 --- a/ee/cli/templates/22222.mustache +++ b/ee/cli/templates/22222.mustache @@ -19,21 +19,24 @@ server { # Turn on directory listing autoindex on; + # HTTP Authentication on port 22222 + include common/acl.conf; + location / { - include common/acl.conf; try_files $uri $uri/ /index.php?$args; } + # Display menu at location /fpm/status/ location = /fpm/status/ {} location ~ /fpm/status/(.*) { + try_files $uri =404; include fastcgi_params; fastcgi_param SCRIPT_NAME /status; fastcgi_pass $1; } location ~ \.php$ { - include common/acl.conf; try_files $uri =404; include fastcgi_params; fastcgi_pass php; diff --git a/ee/cli/templates/locations.mustache b/ee/cli/templates/locations.mustache index c8414fb2..9fd1ef25 100644 --- a/ee/cli/templates/locations.mustache +++ b/ee/cli/templates/locations.mustache @@ -1,5 +1,5 @@ # NGINX CONFIGURATION FOR COMMON LOCATION -# DO NOT MODIFY, ALL CHNAGES LOST AFTER UPDATE EasyEngine (ee) +# DO NOT MODIFY, ALL CHANGES LOST AFTER UPDATE EasyEngine (ee) # Basic locations files location = /favicon.ico { access_log off; diff --git a/ee/cli/templates/php-hhvm.mustache b/ee/cli/templates/php-hhvm.mustache index 54f4d2aa..198d81de 100644 --- a/ee/cli/templates/php-hhvm.mustache +++ b/ee/cli/templates/php-hhvm.mustache @@ -1,5 +1,5 @@ # PHP NGINX CONFIGURATION -# DO NOT MODIFY, ALL CHNAGES LOST AFTER UPDATE EasyEngine (ee) +# DO NOT MODIFY, ALL CHANGES LOST AFTER UPDATE EasyEngine (ee) location / { try_files $uri $uri/ /index.php?$args; } diff --git a/ee/cli/templates/php.mustache b/ee/cli/templates/php.mustache index 3546f571..b12b250a 100644 --- a/ee/cli/templates/php.mustache +++ b/ee/cli/templates/php.mustache @@ -1,5 +1,5 @@ # PHP NGINX CONFIGURATION -# DO NOT MODIFY, ALL CHNAGES LOST AFTER UPDATE EasyEngine (ee) +# DO NOT MODIFY, ALL CHANGES LOST AFTER UPDATE EasyEngine (ee) location / { try_files $uri $uri/ /index.php?$args; } diff --git a/ee/cli/templates/w3tc-hhvm.mustache b/ee/cli/templates/w3tc-hhvm.mustache index dbaca7c0..b5c70ed1 100644 --- a/ee/cli/templates/w3tc-hhvm.mustache +++ b/ee/cli/templates/w3tc-hhvm.mustache @@ -1,6 +1,6 @@ # W3TC NGINX CONFIGURATION -# DO NOT MODIFY, ALL CHNAGES LOST AFTER UPDATE EasyEngine (ee) +# DO NOT MODIFY, ALL CHANGES LOST AFTER UPDATE EasyEngine (ee) set $cache_uri $request_uri; # POST requests and URL with a query string should always go to php if ($request_method = POST) { diff --git a/ee/cli/templates/w3tc.mustache b/ee/cli/templates/w3tc.mustache index 5b162822..ea13c255 100644 --- a/ee/cli/templates/w3tc.mustache +++ b/ee/cli/templates/w3tc.mustache @@ -1,6 +1,6 @@ # W3TC NGINX CONFIGURATION -# DO NOT MODIFY, ALL CHNAGES LOST AFTER UPDATE EasyEngine (ee) +# DO NOT MODIFY, ALL CHANGES LOST AFTER UPDATE EasyEngine (ee) set $cache_uri $request_uri; # POST requests and URL with a query string should always go to php if ($request_method = POST) { diff --git a/ee/cli/templates/wpcommon.mustache b/ee/cli/templates/wpcommon.mustache index e6b34782..cbafa601 100644 --- a/ee/cli/templates/wpcommon.mustache +++ b/ee/cli/templates/wpcommon.mustache @@ -1,5 +1,5 @@ # WordPress COMMON SETTINGS -# DO NOT MODIFY, ALL CHNAGES LOST AFTER UPDATE EasyEngine (ee) +# DO NOT MODIFY, ALL CHANGES LOST AFTER UPDATE EasyEngine (ee) # Limit access to avoid brute force attack location = /wp-login.php { limit_req zone=one burst=1 nodelay; diff --git a/ee/cli/templates/wpfc-hhvm.mustache b/ee/cli/templates/wpfc-hhvm.mustache index 54255c4f..9de76275 100644 --- a/ee/cli/templates/wpfc-hhvm.mustache +++ b/ee/cli/templates/wpfc-hhvm.mustache @@ -1,5 +1,5 @@ # WPFC NGINX CONFIGURATION -# DO NOT MODIFY, ALL CHNAGES LOST AFTER UPDATE EasyEngine (ee) +# DO NOT MODIFY, ALL CHANGES LOST AFTER UPDATE EasyEngine (ee) set $skip_cache 0; # POST requests and URL with a query string should always go to php if ($request_method = POST) { diff --git a/ee/cli/templates/wpfc.mustache b/ee/cli/templates/wpfc.mustache index ff5240c7..72b88b8b 100644 --- a/ee/cli/templates/wpfc.mustache +++ b/ee/cli/templates/wpfc.mustache @@ -1,5 +1,5 @@ # WPFC NGINX CONFIGURATION -# DO NOT MODIFY, ALL CHNAGES LOST AFTER UPDATE EasyEngine (ee) +# DO NOT MODIFY, ALL CHANGES LOST AFTER UPDATE EasyEngine (ee) set $skip_cache 0; # POST requests and URL with a query string should always go to php if ($request_method = POST) { diff --git a/ee/cli/templates/wpsc-hhvm.mustache b/ee/cli/templates/wpsc-hhvm.mustache index 29e9ebd9..834b87fc 100644 --- a/ee/cli/templates/wpsc-hhvm.mustache +++ b/ee/cli/templates/wpsc-hhvm.mustache @@ -1,5 +1,5 @@ # WPSC NGINX CONFIGURATION -# DO NOT MODIFY, ALL CHNAGES LOST AFTER UPDATE EasyEngine (ee) +# DO NOT MODIFY, ALL CHANGES LOST AFTER UPDATE EasyEngine (ee) set $cache_uri $request_uri; # POST requests and URL with a query string should always go to php if ($request_method = POST) { diff --git a/ee/cli/templates/wpsc.mustache b/ee/cli/templates/wpsc.mustache index 2600a795..48f8736d 100644 --- a/ee/cli/templates/wpsc.mustache +++ b/ee/cli/templates/wpsc.mustache @@ -1,5 +1,5 @@ # WPSC NGINX CONFIGURATION -# DO NOT MODIFY, ALL CHNAGES LOST AFTER UPDATE EasyEngine (ee) +# DO NOT MODIFY, ALL CHANGES LOST AFTER UPDATE EasyEngine (ee) set $cache_uri $request_uri; # POST requests and URL with a query string should always go to php if ($request_method = POST) { diff --git a/ee/cli/templates/wpsubdir.mustache b/ee/cli/templates/wpsubdir.mustache index 7b65841f..2ef06489 100644 --- a/ee/cli/templates/wpsubdir.mustache +++ b/ee/cli/templates/wpsubdir.mustache @@ -1,5 +1,5 @@ # WPSUBDIRECTORY NGINX CONFIGURATION -# DO NOT MODIFY, ALL CHNAGES LOST AFTER UPDATE EasyEngine (ee) +# DO NOT MODIFY, ALL CHANGES LOST AFTER UPDATE EasyEngine (ee) if (!-e $request_filename) { # Redirect wp-admin to wp-admin/ rewrite /wp-admin$ $scheme://$host$uri/ permanent; diff --git a/ee/core/aptget.py b/ee/core/aptget.py index a4071a4a..33f5aa11 100644 --- a/ee/core/aptget.py +++ b/ee/core/aptget.py @@ -4,6 +4,7 @@ import apt_pkg import sys import subprocess from ee.core.logging import Log +from ee.core.apt_repo import EERepo from sh import apt_get from sh import ErrorReturnCode @@ -13,24 +14,45 @@ class EEAptGet(): def update(self): """ - Similar to `apt-get upgrade` + Similar to `apt-get update` """ try: with open('/var/log/ee/ee.log', 'a') as f: proc = subprocess.Popen('apt-get update', shell=True, - stdin=None, stdout=f, stderr=f, + stdin=None, stdout=f, + stderr=subprocess.PIPE, executable="/bin/bash") proc.wait() + output, error_output = proc.communicate() + + # Check what is error in error_output + if "NO_PUBKEY" in str(error_output): + # Split the output + Log.info(self, "Fixing missing GPG keys, please wait...") + error_list = str(error_output).split("\\n") + + # Use a loop to add misising keys + for single_error in error_list: + if "NO_PUBKEY" in single_error: + key = single_error.rsplit(None, 1)[-1] + EERepo.add_key(self, key) + + proc = subprocess.Popen('apt-get update', + shell=True, + stdin=None, stdout=f, stderr=f, + executable="/bin/bash") + proc.wait() - if proc.returncode == 0: - return True - else: - Log.error(self, "Unable to run apt-get update") + if proc.returncode == 0: + return True + else: + Log.info(self, Log.FAIL + "Oops Something went wrong!!") + Log.error(self, "Check logs for reason " + "`tail /var/log/ee/ee.log` & Try Again!!!") except Exception as e: - Log.error(self, "Error while installing packages, " - "apt-get exited with error") + Log.error(self, "apt-get update exited with error") def check_upgrade(self): """ @@ -71,7 +93,10 @@ class EEAptGet(): if proc.returncode == 0: return True else: - Log.error(self, "Unable to run apt-get dist_upgrade") + Log.info(self, Log.FAIL + "Oops Something went " + "wrong!!") + Log.error(self, "Check logs for reason " + "`tail /var/log/ee/ee.log` & Try Again!!!") except Exception as e: Log.error(self, "Error while installing packages, " "apt-get exited with error") @@ -94,11 +119,16 @@ class EEAptGet(): if proc.returncode == 0: return True else: - Log.error(self, "Unable to run apt-get install") + Log.info(self, Log.FAIL + "Oops Something went " + "wrong!!") + Log.error(self, "Check logs for reason " + "`tail /var/log/ee/ee.log` & Try Again!!!") except Exception as e: - Log.error(self, "Error while installing packages, " - "apt-get exited with error") + Log.info(self, Log.FAIL + "Oops Something went " + "wrong!!") + Log.error(self, "Check logs for reason " + "`tail /var/log/ee/ee.log` & Try Again!!!") def remove(self, packages, auto=False, purge=False): all_packages = ' '.join(packages) @@ -118,7 +148,10 @@ class EEAptGet(): if proc.returncode == 0: return True else: - Log.error(self, "Unable to run apt-get remove/purge") + Log.info(self, Log.FAIL + "Oops Something went " + "wrong!!") + Log.error(self, "Check logs for reason " + "`tail /var/log/ee/ee.log` & Try Again!!!") except Exception as e: Log.error(self, "Error while installing packages, " diff --git a/ee/core/nginxhashbucket.py b/ee/core/nginxhashbucket.py new file mode 100644 index 00000000..f282c326 --- /dev/null +++ b/ee/core/nginxhashbucket.py @@ -0,0 +1,59 @@ +"""EasyEngine Hash bucket calculate function for Nginx""" +from ee.core.fileutils import EEFileUtils +import math +import os +import fileinput +import re +import subprocess + + +def hashbucket(self): + # Check Nginx Hashbucket error + sub = subprocess.Popen('nginx -t', stdout=subprocess.PIPE, + stderr=subprocess.PIPE, shell=True) + output, error_output = sub.communicate() + if 'server_names_hash_bucket_size' not in str(error_output): + return True + + count = 0 + # Get the list of sites-availble + sites_list = os.listdir("/etc/nginx/sites-enabled/") + + # Count the number of characters in site names + for site in sites_list: + count = sum([count, len(site)]) + + # Calculate Nginx hash bucket size + ngx_calc = math.trunc(sum([math.log(count, 2), 2])) + ngx_hash = math.trunc(math.pow(2, ngx_calc)) + + # Replace hashbucket in Nginx.conf file + if EEFileUtils.grep(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)) + else: + print(line, end='') + + elif os.path.isfile('/etc/nginx/conf.d/ee-nginx.conf'): + if EEFileUtils.grep(self, "/etc/nginx/conf.d/ee-nginx.conf", + "server_names_hash_bucket_size"): + for line in fileinput.FileInput("/etc/nginx/conf.d/ee-nginx.conf", + inplace=1): + if "server_names_hash_bucket_size" in line: + print("server_names_hash_bucket_size {0};" + .format(ngx_hash)) + else: + print(line, end='') + + else: + with open('/etc/nginx/conf.d/ee-nginx.conf', 'a') as conf: + conf.write("server_names_hash_bucket_size {0};\n" + .format(ngx_hash)) + else: + EEFileUtils.searchreplace(self, '/etc/nginx/nginx.conf', + "gzip_disable \"msie6\";", + "gzip_disable \"msie6\";\n" + "\tserver_names_hash_bucket_size {0};\n" + .format(ngx_hash)) diff --git a/ee/core/variables.py b/ee/core/variables.py index 8cbea03d..62f78327 100644 --- a/ee/core/variables.py +++ b/ee/core/variables.py @@ -12,7 +12,7 @@ class EEVariables(): """Intialization of core variables""" # EasyEngine version - ee_version = "3.1.2" + ee_version = "3.1.3" # EasyEngine packages versions ee_wp_cli = "0.19.0" diff --git a/install b/install index 5041992f..788dcacb 100644 --- a/install +++ b/install @@ -48,7 +48,7 @@ fi # Define variables for later use ee_branch=$1 readonly ee_version_old="2.2.3" -readonly ee_version_new="3.1.2" +readonly ee_version_new="3.1.3" readonly ee_log_dir=/var/log/ee/ readonly ee_install_log=/var/log/ee/install.log readonly ee_linux_distro=$(lsb_release -i | awk '{print $3}') diff --git a/setup.py b/setup.py index 082ffa24..43660d82 100644 --- a/setup.py +++ b/setup.py @@ -54,7 +54,7 @@ except Exception as e: os.system("git config --global user.email {0}".format(ee_email)) setup(name='ee', - version='3.1.2', + version='3.1.3', description=long_description, long_description=long_description, classifiers=[],