From e83289cf215c9a56d47d6fefeb396828953ef3aa Mon Sep 17 00:00:00 2001 From: harshadyeola Date: Tue, 28 Apr 2015 18:41:50 +0530 Subject: [PATCH] update other types of site to proxy --- ee/cli/plugins/site.py | 36 +++++++++++++++++++++++++++ ee/cli/plugins/site_functions.py | 4 +-- ee/cli/templates/virtualconf.mustache | 2 +- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/ee/cli/plugins/site.py b/ee/cli/plugins/site.py index 191e9f22..9175f9b6 100644 --- a/ee/cli/plugins/site.py +++ b/ee/cli/plugins/site.py @@ -654,6 +654,8 @@ class EESiteUpdateController(CementBaseController): dict(help='Use PageSpeed for site', action='store' or 'store_const', choices=('on', 'off'), const='on', nargs='?')), + (['--proxy'], + dict(help="update to prxy site", nargs='+')), (['--all'], dict(help="update all sites", action='store_true')), ] @@ -701,6 +703,21 @@ class EESiteUpdateController(CementBaseController): Log.error(self, "Please provide valid options combination for" " site update") + if stype is None and pargs.proxy: + stype, cache = 'proxy', '' + proxyinfo = pargs.proxy[0].strip() + if not proxyinfo: + Log.error(self, "Please provide proxy server host information") + proxyinfo = proxyinfo.split(':') + host = proxyinfo[0].strip() + port = '80' if len(proxyinfo) < 2 else proxyinfo[1].strip() + elif stype is None and not pargs.proxy: + stype, cache = 'html', 'basic' + elif stype and pargs.proxy: + Log.error(self, "--proxy can not be used with other site types") + if (pargs.proxy and (pargs.pagespeed or pargs.hhvm)): + Log.error(self, "Proxy site can not run on pagespeed or hhvm") + if not pargs.site_name: try: while not pargs.site_name: @@ -757,6 +774,18 @@ class EESiteUpdateController(CementBaseController): format(oldsitetype, oldcachetype, stype, cache)) return 1 + if stype == 'proxy': + data['site_name'] = ee_domain + data['www_domain'] = ee_www_domain + data['proxy'] = True + data['host'] = host + data['port'] = port + pagespeed = False + hhvm = False + data['webroot'] = ee_site_webroot + data['currsitetype'] = oldsitetype + data['currcachetype'] = oldcachetype + if stype == 'php': data = dict(site_name=ee_domain, www_domain=ee_www_domain, static=False, basic=True, wp=False, w3tc=False, @@ -926,6 +955,13 @@ class EESiteUpdateController(CementBaseController): "`tail /var/log/ee/ee.log` & Try Again!!!") return 1 + if 'proxy' in data.keys() and data['proxy']: + updateSiteInfo(self, ee_domain, stype=stype, cache=cache, + hhvm=hhvm, pagespeed=pagespeed) + Log.info(self, "Successfully updated site" + " http://{0}".format(ee_domain)) + return 0 + # Update pagespeed config if pargs.pagespeed: operateOnPagespeed(self, data) diff --git a/ee/cli/plugins/site_functions.py b/ee/cli/plugins/site_functions.py index f46ee70b..5ca8db80 100644 --- a/ee/cli/plugins/site_functions.py +++ b/ee/cli/plugins/site_functions.py @@ -520,7 +520,7 @@ def sitebackup(self, data): EEFileUtils.copyfile(self, '/etc/nginx/sites-available/{0}' .format(data['site_name']), backup_path) - if data['currsitetype'] in ['html', 'php', 'mysql']: + if data['currsitetype'] in ['html', 'php', 'proxy', 'mysql']: Log.info(self, "Backing up Webroot \t\t", end='') EEFileUtils.mvfile(self, ee_site_webroot + '/htdocs', backup_path) Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]") @@ -544,7 +544,7 @@ def sitebackup(self, data): raise SiteError("mysqldump failed to backup database") Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]") # move wp-config.php/ee-config.php to backup - if data['currsitetype'] in ['mysql']: + if data['currsitetype'] in ['mysql', 'proxy']: EEFileUtils.mvfile(self, configfiles[0], backup_path) else: EEFileUtils.copyfile(self, configfiles[0], backup_path) diff --git a/ee/cli/templates/virtualconf.mustache b/ee/cli/templates/virtualconf.mustache index 3bceb6e0..7553d46e 100644 --- a/ee/cli/templates/virtualconf.mustache +++ b/ee/cli/templates/virtualconf.mustache @@ -19,7 +19,7 @@ server { {{#proxy}} add_header X-Proxy-Cache $upstream_cache_status; location / { - proxy_pass {{host}}:{{port}}; + proxy_pass http://{{host}}:{{port}}; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr;