Browse Source

Merge branch 'master' of github.com:rtCamp/easyengine

bugfixes
gau1991 10 years ago
parent
commit
018821d901
  1. 36
      config/bash_completion.d/ee_auto.rc
  2. 116
      ee/cli/plugins/site.py
  3. 23
      ee/cli/plugins/site_functions.py
  4. 2
      ee/cli/templates/siteinfo.mustache
  5. 18
      ee/cli/templates/virtualconf.mustache

36
config/bash_completion.d/ee_auto.rc

@ -165,7 +165,7 @@ _ee_complete()
"create")
COMPREPLY=( $(compgen \
-W "--html --php --mysql --wp --wpsubdir --wpsubdomain --w3tc --wpfc --wpsc --hhvm --pagespeed" \
-W "--user --pass --email --html --php --mysql --wp --wpsubdir --wpsubdomain --w3tc --wpfc --wpsc --hhvm --proxy= --pagespeed" \
-- $cur) )
;;
@ -216,7 +216,13 @@ _ee_complete()
case "$prev" in
"--wp" | "--wpsubdir" | "--wpsubdomain")
if [ ${COMP_WORDS[1]} != "debug" ]; then
retlist="--w3tc --wpfc --wpsc"
if [ ${COMP_WORDS[2]} == "create" ]; then
retlist="--w3tc --wpfc --wpsc --pagespeed --hhvm --user --email --pass"
elif [ ${COMP_WORDS[2]} == "update" ]; then
retlist="--w3tc --wpfc --wpsc --pagespeed --hhvm --pagespeed=off --hhvm=off"
else
retlist=""
fi
else
retlist="--wp=off --rewrite --rewrite=off -i --interactive"
fi
@ -227,6 +233,21 @@ _ee_complete()
-- $cur) )
;;
"--pagespeed" | "--hhvm")
if [ ${COMP_WORDS[2]} == "create" ]; then
retlist="--user --pass --email --html --php --mysql --wp --wpsubdir --wpsubdomain --w3tc --wpfc --wpsc --hhvm --pagespeed"
elif [ ${COMP_WORDS[2]} == "update" ]; then
retlist="--password --php --mysql --wp --wpsubdir --wpsubdomain --w3tc --wpfc --wpsc --hhvm --hhvm=off --pagespeed --pagespeed=off"
else
retlist=""
fi
ret="${retlist[@]/$prev}"
COMPREPLY=( $(compgen \
-W "$(echo $ret)" \
-- $cur) )
;;
"--web" | "--admin" | "--mail" | "--nginx" | "--php" | "--mysql" | "--postfix" | "--wpcli" | "--phpmyadmin" | "--adminer" | "--utils" | "--memcache" | "--dovecot")
if [[ ${COMP_WORDS[2]} == "install" || ${COMP_WORDS[2]} == "purge" || ${COMP_WORDS[2]} == "remove" ]]; then
retlist="--web --admin --mail --nginx --php --mysql --postfix --wpcli --phpmyadmin --adminer --utils --memcache --dovecot"
@ -315,6 +336,17 @@ _ee_complete()
*)
;;
esac
case "$mprev" in
"--user" | "--email" | "--pass")
if [ ${COMP_WORDS[2]} == "create" ]; then
retlist="--user --pass --email --html --php --mysql --wp --wpsubdir --wpsubdomain --w3tc --wpfc --wpsc --hhvm --pagespeed"
fi
ret="${retlist[@]/$prev}"
COMPREPLY=( $(compgen \
-W "$(echo $ret)" \
-- $cur) )
;;
esac
return 0

116
ee/cli/plugins/site.py

@ -144,6 +144,10 @@ class EESiteController(CementBaseController):
ee_db_host = siteinfo.db_host
if sitetype != "html":
hhvm = ("enabled" if siteinfo.is_hhvm else "disabled")
if sitetype == "proxy":
access_log = "/var/log/nginx/{0}.access.log".format(ee_domain)
error_log = "/var/log/nginx/{0}.error.log".format(ee_domain)
ee_site_webroot = ''
pagespeed = ("enabled" if siteinfo.is_pagespeed else "disabled")
@ -338,6 +342,15 @@ class EESiteCreateController(CementBaseController):
dict(help="create HHVM site", action='store_true')),
(['--pagespeed'],
dict(help="create pagespeed site", action='store_true')),
(['--user'],
dict(help="provide user for wordpress site")),
(['--email'],
dict(help="provide email address for wordpress site")),
(['--pass'],
dict(help="provide password for wordpress user",
dest='wppass')),
(['--proxy'],
dict(help="create proxy for site", nargs='+'))
]
@expose(hide=True)
@ -345,12 +358,29 @@ class EESiteCreateController(CementBaseController):
# self.app.render((data), 'default.mustache')
# Check domain name validation
data = dict()
host, port = None, None
try:
stype, cache = detSitePar(vars(self.app.pargs))
except RuntimeError as e:
Log.debug(self, str(e))
Log.error(self, "Please provide valid options to creating site")
if stype is None and self.app.pargs.proxy:
stype, cache = 'proxy', ''
proxyinfo = self.app.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 self.app.pargs.proxy:
stype, cache = 'html', 'basic'
elif stype and self.app.pargs.proxy:
Log.error(self, "proxy should not be used with other site types")
if (self.app.pargs.proxy and (self.app.pargs.pagespeed
or self.app.pargs.hhvm)):
Log.error(self, "Proxy site can not run on pagespeed or hhvm")
if not self.app.pargs.site_name:
try:
while not self.app.pargs.site_name:
@ -377,6 +407,14 @@ class EESiteCreateController(CementBaseController):
Log.error(self, "Nginx configuration /etc/nginx/sites-available/"
"{0} already exists".format(ee_domain))
if stype == 'proxy':
data['site_name'] = ee_domain
data['www_domain'] = ee_www_domain
data['proxy'] = True
data['host'] = host
data['port'] = port
ee_site_webroot = ""
if stype in ['html', 'php']:
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
static=True, basic=False, wp=False, w3tc=False,
@ -386,6 +424,7 @@ class EESiteCreateController(CementBaseController):
if stype == 'php':
data['static'] = False
data['basic'] = True
elif stype in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
@ -399,10 +438,15 @@ class EESiteCreateController(CementBaseController):
data['wp'] = True
data['basic'] = False
data[cache] = True
data['wp-user'] = self.app.pargs.user
data['wp-email'] = self.app.pargs.email
data['wp-pass'] = self.app.pargs.wppass
if stype in ['wpsubdir', 'wpsubdomain']:
data['multisite'] = True
if stype == 'wpsubdir':
data['wpsubdir'] = True
else:
pass
if stype == "html" and self.app.pargs.hhvm:
Log.error(self, "Can not create HTML site with HHVM")
@ -421,13 +465,12 @@ class EESiteCreateController(CementBaseController):
data['pagespeed'] = False
pagespeed = 0
if not data:
self.app.args.print_help()
self.app.close(1)
# if not data:
# self.app.args.print_help()
# self.app.close(1)
# Check rerequired packages are installed or not
ee_auth = site_package_check(self, stype)
try:
try:
# setup NGINX configuration, and webroot
@ -442,12 +485,23 @@ class EESiteCreateController(CementBaseController):
Log.error(self, "Check logs for reason "
"`tail /var/log/ee/ee.log` & Try Again!!!")
if 'proxy' in data.keys() and data['proxy']:
addNewSite(self, ee_domain, stype, cache, ee_site_webroot)
# Service Nginx Reload
EEService.reload_service(self, 'nginx')
if ee_auth and len(ee_auth):
for msg in ee_auth:
Log.info(self, Log.ENDC + msg, log=False)
Log.info(self, "Successfully created site"
" http://{0}".format(ee_domain))
return
# Update pagespeed config
if self.app.pargs.pagespeed:
operateOnPagespeed(self, data)
addNewSite(self, ee_domain, stype, cache, ee_site_webroot,
hhvm=hhvm, pagespeed=pagespeed)
# Setup database for MySQL site
if 'ee_db_name' in data.keys() and not data['wp']:
try:
@ -605,6 +659,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')),
]
@ -652,6 +708,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:
@ -685,14 +756,21 @@ class EESiteUpdateController(CementBaseController):
Log.info(self, "Password Unchanged.")
return 0
if ((stype == "proxy" and stype == oldsitetype and self.app.pargs.hhvm)
or (stype == "proxy" and
stype == oldsitetype and self.app.pargs.pagespeed)):
Log.info(self, Log.FAIL +
"Can not update proxy site to HHVM or Pagespeed")
return 1
if stype == "html" and stype == oldsitetype and self.app.pargs.hhvm:
Log.info(self, Log.FAIL + "Can not update HTML site to HHVM")
return 1
if ((stype == 'php' and oldsitetype != 'html') or
(stype == 'mysql' and oldsitetype not in ['html', 'php']) or
if ((stype == 'php' and oldsitetype not in ['html', 'proxy']) or
(stype == 'mysql' and oldsitetype not in ['html', 'php',
'proxy']) or
(stype == 'wp' and oldsitetype not in ['html', 'php', 'mysql',
'wp']) or
'proxy', 'wp']) or
(stype == 'wpsubdir' and oldsitetype in ['wpsubdomain']) or
(stype == 'wpsubdomain' and oldsitetype in ['wpsubdir']) or
(stype == oldsitetype and cache == oldcachetype) and
@ -701,6 +779,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,
@ -736,8 +826,7 @@ class EESiteUpdateController(CementBaseController):
stype = oldsitetype
cache = oldcachetype
if oldsitetype == 'html':
if oldsitetype == 'html' or oldsitetype == 'proxy':
data['static'] = True
data['wp'] = False
data['multisite'] = False
@ -871,6 +960,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)
@ -917,7 +1013,7 @@ class EESiteUpdateController(CementBaseController):
return 1
# Setup WordPress if old sites are html/php/mysql sites
if data['wp'] and oldsitetype in ['html', 'php', 'mysql']:
if data['wp'] and oldsitetype in ['html', 'proxy', 'php', 'mysql']:
try:
ee_wp_creds = setupwordpress(self, data)
except SiteError as e:

23
ee/cli/plugins/site_functions.py

@ -52,7 +52,7 @@ def check_domain_exists(self, domain):
def setupdomain(self, data):
ee_domain_name = data['site_name']
ee_site_webroot = data['webroot']
ee_site_webroot = data['webroot'] if 'webroot' in data.keys() else ''
# Check if nginx configuration already exists
# if os.path.isfile('/etc/nginx/sites-available/{0}'
@ -90,6 +90,9 @@ def setupdomain(self, data):
raise SiteError("created nginx configuration failed for site."
" check with `nginx -t`")
if 'proxy' in data.keys() and data['proxy']:
return
# create symbolic link for
EEFileUtils.create_symlink(self, ['/etc/nginx/sites-available/{0}'
.format(ee_domain_name),
@ -235,6 +238,13 @@ def setupwordpress(self, data):
# ee_wp_user = ''
# ee_wp_pass = ''
if 'wp-user' in data.keys() and data['wp-user']:
ee_wp_user = data['wp-user']
if 'wp-email' in data.keys() and data['wp-email']:
ee_wp_email = data['wp-email']
if 'wp-pass' in data.keys() and data['wp-pass']:
ee_wp_pass = data['wp-pass']
Log.info(self, "Downloading Wordpress \t\t", end='')
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
try:
@ -510,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 + "]")
@ -534,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)
@ -545,7 +555,8 @@ def site_package_check(self, stype):
packages = []
stack = EEStackController()
stack.app = self.app
if stype in ['html', 'php', 'mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
if stype in ['html', 'proxy', 'php', 'mysql', 'wp', 'wpsubdir',
'wpsubdomain']:
Log.debug(self, "Setting apt_packages variable for Nginx")
if EEVariables.ee_platform_distro == 'debian':
@ -790,8 +801,8 @@ def detSitePar(opts):
raise RuntimeError("could not determine site and cache type")
else:
if not typelist and not cachelist:
sitetype = 'html'
cachetype = 'basic'
sitetype = None
cachetype = None
elif (not typelist) and cachelist:
sitetype = 'wp'
cachetype = cachelist[0]

2
ee/cli/templates/siteinfo.mustache

@ -5,7 +5,7 @@ Nginx configuration {{type}} {{enable}}
{{#hhvm}}HHVM {{hhvm}}{{/hhvm}}
access_log {{accesslog}}
error_log {{errorlog}}
Webroot {{webroot}}
{{#webroot}}Webroot {{webroot}}{{/webroot}}
{{#dbname}}DB_NAME {{dbname}}{{/dbname}}
{{#dbname}}DB_USER {{dbuser}}{{/dbname}}
{{#dbname}}DB_PASS {{dbpass}}{{/dbname}}

18
ee/cli/templates/virtualconf.mustache

@ -15,11 +15,24 @@ server {
access_log /var/log/nginx/{{site_name}}.access.log {{^static}}rt_cache{{/static}};
error_log /var/log/nginx/{{site_name}}.error.log;
{{#proxy}}
add_header X-Proxy-Cache $upstream_cache_status;
location / {
proxy_pass http://{{host}}:{{port}};
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
{{/proxy}}
{{^proxy}}
{{^vma}}{{^rc}}root {{webroot}}/htdocs;{{/rc}}{{/vma}}
{{#vma}}root /var/www/22222/htdocs/vimbadmin/public;{{/vma}}
{{#rc}}root /var/www/roundcubemail/htdocs/;{{/rc}}
index {{^static}}index.php{{/static}} index.html index.htm;
{{^proxy}}index {{^static}}index.php{{/static}} index.html index.htm;{{/proxy}}
{{#static}}
location / {
@ -30,6 +43,7 @@ server {
{{^static}}include {{^hhvm}}{{#basic}}common/php.conf;{{/basic}}{{#w3tc}}common/w3tc.conf;{{/w3tc}}{{#wpfc}}common/wpfc.conf;{{/wpfc}} {{#wpsc}}common/wpsc.conf;{{/wpsc}} {{/hhvm}}{{#hhvm}}{{#basic}}common/php-hhvm.conf;{{/basic}}{{#w3tc}}common/w3tc-hhvm.conf;{{/w3tc}}{{#wpfc}}common/wpfc-hhvm.conf;{{/wpfc}} {{#wpsc}}common/wpsc-hhvm.conf;{{/wpsc}} {{/hhvm}}
{{#wpsubdir}}include common/wpsubdir.conf;{{/wpsubdir}}{{/static}}
{{#wp}}include common/wpcommon.conf;{{/wp}}
include common/locations.conf;
{{^proxy}}include common/locations.conf;{{/proxy}}
{{^vma}}{{^rc}}include {{webroot}}/conf/nginx/*.conf;{{/rc}}{{/vma}}
{{/proxy}}
}

Loading…
Cancel
Save