Skip to content

Commit 018821d

Browse files
author
gau1991
committed
Merge branch 'master' of github.com:rtCamp/easyengine
2 parents acfbebd + 12decc9 commit 018821d

File tree

5 files changed

+174
-21
lines changed

5 files changed

+174
-21
lines changed

config/bash_completion.d/ee_auto.rc

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ _ee_complete()
165165

166166
"create")
167167
COMPREPLY=( $(compgen \
168-
-W "--html --php --mysql --wp --wpsubdir --wpsubdomain --w3tc --wpfc --wpsc --hhvm --pagespeed" \
168+
-W "--user --pass --email --html --php --mysql --wp --wpsubdir --wpsubdomain --w3tc --wpfc --wpsc --hhvm --proxy= --pagespeed" \
169169
-- $cur) )
170170
;;
171171

@@ -216,7 +216,13 @@ _ee_complete()
216216
case "$prev" in
217217
"--wp" | "--wpsubdir" | "--wpsubdomain")
218218
if [ ${COMP_WORDS[1]} != "debug" ]; then
219-
retlist="--w3tc --wpfc --wpsc"
219+
if [ ${COMP_WORDS[2]} == "create" ]; then
220+
retlist="--w3tc --wpfc --wpsc --pagespeed --hhvm --user --email --pass"
221+
elif [ ${COMP_WORDS[2]} == "update" ]; then
222+
retlist="--w3tc --wpfc --wpsc --pagespeed --hhvm --pagespeed=off --hhvm=off"
223+
else
224+
retlist=""
225+
fi
220226
else
221227
retlist="--wp=off --rewrite --rewrite=off -i --interactive"
222228
fi
@@ -227,6 +233,21 @@ _ee_complete()
227233
-- $cur) )
228234
;;
229235

236+
"--pagespeed" | "--hhvm")
237+
if [ ${COMP_WORDS[2]} == "create" ]; then
238+
retlist="--user --pass --email --html --php --mysql --wp --wpsubdir --wpsubdomain --w3tc --wpfc --wpsc --hhvm --pagespeed"
239+
elif [ ${COMP_WORDS[2]} == "update" ]; then
240+
retlist="--password --php --mysql --wp --wpsubdir --wpsubdomain --w3tc --wpfc --wpsc --hhvm --hhvm=off --pagespeed --pagespeed=off"
241+
else
242+
retlist=""
243+
fi
244+
245+
ret="${retlist[@]/$prev}"
246+
COMPREPLY=( $(compgen \
247+
-W "$(echo $ret)" \
248+
-- $cur) )
249+
;;
250+
230251
"--web" | "--admin" | "--mail" | "--nginx" | "--php" | "--mysql" | "--postfix" | "--wpcli" | "--phpmyadmin" | "--adminer" | "--utils" | "--memcache" | "--dovecot")
231252
if [[ ${COMP_WORDS[2]} == "install" || ${COMP_WORDS[2]} == "purge" || ${COMP_WORDS[2]} == "remove" ]]; then
232253
retlist="--web --admin --mail --nginx --php --mysql --postfix --wpcli --phpmyadmin --adminer --utils --memcache --dovecot"
@@ -315,6 +336,17 @@ _ee_complete()
315336
*)
316337
;;
317338
esac
339+
case "$mprev" in
340+
"--user" | "--email" | "--pass")
341+
if [ ${COMP_WORDS[2]} == "create" ]; then
342+
retlist="--user --pass --email --html --php --mysql --wp --wpsubdir --wpsubdomain --w3tc --wpfc --wpsc --hhvm --pagespeed"
343+
fi
344+
ret="${retlist[@]/$prev}"
345+
COMPREPLY=( $(compgen \
346+
-W "$(echo $ret)" \
347+
-- $cur) )
348+
;;
349+
esac
318350

319351
return 0
320352

ee/cli/plugins/site.py

Lines changed: 106 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ def info(self):
144144
ee_db_host = siteinfo.db_host
145145
if sitetype != "html":
146146
hhvm = ("enabled" if siteinfo.is_hhvm else "disabled")
147+
if sitetype == "proxy":
148+
access_log = "/var/log/nginx/{0}.access.log".format(ee_domain)
149+
error_log = "/var/log/nginx/{0}.error.log".format(ee_domain)
150+
ee_site_webroot = ''
147151

148152
pagespeed = ("enabled" if siteinfo.is_pagespeed else "disabled")
149153

@@ -338,19 +342,45 @@ class Meta:
338342
dict(help="create HHVM site", action='store_true')),
339343
(['--pagespeed'],
340344
dict(help="create pagespeed site", action='store_true')),
345+
(['--user'],
346+
dict(help="provide user for wordpress site")),
347+
(['--email'],
348+
dict(help="provide email address for wordpress site")),
349+
(['--pass'],
350+
dict(help="provide password for wordpress user",
351+
dest='wppass')),
352+
(['--proxy'],
353+
dict(help="create proxy for site", nargs='+'))
341354
]
342355

343356
@expose(hide=True)
344357
def default(self):
345358
# self.app.render((data), 'default.mustache')
346359
# Check domain name validation
347360
data = dict()
361+
host, port = None, None
348362
try:
349363
stype, cache = detSitePar(vars(self.app.pargs))
350364
except RuntimeError as e:
351365
Log.debug(self, str(e))
352366
Log.error(self, "Please provide valid options to creating site")
353367

368+
if stype is None and self.app.pargs.proxy:
369+
stype, cache = 'proxy', ''
370+
proxyinfo = self.app.pargs.proxy[0].strip()
371+
if not proxyinfo:
372+
Log.error(self, "Please provide proxy server host information")
373+
proxyinfo = proxyinfo.split(':')
374+
host = proxyinfo[0].strip()
375+
port = '80' if len(proxyinfo) < 2 else proxyinfo[1].strip()
376+
elif stype is None and not self.app.pargs.proxy:
377+
stype, cache = 'html', 'basic'
378+
elif stype and self.app.pargs.proxy:
379+
Log.error(self, "proxy should not be used with other site types")
380+
if (self.app.pargs.proxy and (self.app.pargs.pagespeed
381+
or self.app.pargs.hhvm)):
382+
Log.error(self, "Proxy site can not run on pagespeed or hhvm")
383+
354384
if not self.app.pargs.site_name:
355385
try:
356386
while not self.app.pargs.site_name:
@@ -377,6 +407,14 @@ def default(self):
377407
Log.error(self, "Nginx configuration /etc/nginx/sites-available/"
378408
"{0} already exists".format(ee_domain))
379409

410+
if stype == 'proxy':
411+
data['site_name'] = ee_domain
412+
data['www_domain'] = ee_www_domain
413+
data['proxy'] = True
414+
data['host'] = host
415+
data['port'] = port
416+
ee_site_webroot = ""
417+
380418
if stype in ['html', 'php']:
381419
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
382420
static=True, basic=False, wp=False, w3tc=False,
@@ -386,6 +424,7 @@ def default(self):
386424
if stype == 'php':
387425
data['static'] = False
388426
data['basic'] = True
427+
389428
elif stype in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
390429

391430
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
@@ -399,10 +438,15 @@ def default(self):
399438
data['wp'] = True
400439
data['basic'] = False
401440
data[cache] = True
441+
data['wp-user'] = self.app.pargs.user
442+
data['wp-email'] = self.app.pargs.email
443+
data['wp-pass'] = self.app.pargs.wppass
402444
if stype in ['wpsubdir', 'wpsubdomain']:
403445
data['multisite'] = True
404446
if stype == 'wpsubdir':
405447
data['wpsubdir'] = True
448+
else:
449+
pass
406450

407451
if stype == "html" and self.app.pargs.hhvm:
408452
Log.error(self, "Can not create HTML site with HHVM")
@@ -421,13 +465,12 @@ def default(self):
421465
data['pagespeed'] = False
422466
pagespeed = 0
423467

424-
if not data:
425-
self.app.args.print_help()
426-
self.app.close(1)
468+
# if not data:
469+
# self.app.args.print_help()
470+
# self.app.close(1)
427471

428472
# Check rerequired packages are installed or not
429473
ee_auth = site_package_check(self, stype)
430-
431474
try:
432475
try:
433476
# setup NGINX configuration, and webroot
@@ -442,12 +485,23 @@ def default(self):
442485
Log.error(self, "Check logs for reason "
443486
"`tail /var/log/ee/ee.log` & Try Again!!!")
444487

488+
if 'proxy' in data.keys() and data['proxy']:
489+
addNewSite(self, ee_domain, stype, cache, ee_site_webroot)
490+
# Service Nginx Reload
491+
EEService.reload_service(self, 'nginx')
492+
if ee_auth and len(ee_auth):
493+
for msg in ee_auth:
494+
Log.info(self, Log.ENDC + msg, log=False)
495+
Log.info(self, "Successfully created site"
496+
" http://{0}".format(ee_domain))
497+
return
445498
# Update pagespeed config
446499
if self.app.pargs.pagespeed:
447500
operateOnPagespeed(self, data)
448501

449502
addNewSite(self, ee_domain, stype, cache, ee_site_webroot,
450503
hhvm=hhvm, pagespeed=pagespeed)
504+
451505
# Setup database for MySQL site
452506
if 'ee_db_name' in data.keys() and not data['wp']:
453507
try:
@@ -605,6 +659,8 @@ class Meta:
605659
dict(help='Use PageSpeed for site',
606660
action='store' or 'store_const',
607661
choices=('on', 'off'), const='on', nargs='?')),
662+
(['--proxy'],
663+
dict(help="update to prxy site", nargs='+')),
608664
(['--all'],
609665
dict(help="update all sites", action='store_true')),
610666
]
@@ -652,6 +708,21 @@ def doupdatesite(self, pargs):
652708
Log.error(self, "Please provide valid options combination for"
653709
" site update")
654710

711+
if stype is None and pargs.proxy:
712+
stype, cache = 'proxy', ''
713+
proxyinfo = pargs.proxy[0].strip()
714+
if not proxyinfo:
715+
Log.error(self, "Please provide proxy server host information")
716+
proxyinfo = proxyinfo.split(':')
717+
host = proxyinfo[0].strip()
718+
port = '80' if len(proxyinfo) < 2 else proxyinfo[1].strip()
719+
elif stype is None and not pargs.proxy:
720+
stype, cache = 'html', 'basic'
721+
elif stype and pargs.proxy:
722+
Log.error(self, "--proxy can not be used with other site types")
723+
if (pargs.proxy and (pargs.pagespeed or pargs.hhvm)):
724+
Log.error(self, "Proxy site can not run on pagespeed or hhvm")
725+
655726
if not pargs.site_name:
656727
try:
657728
while not pargs.site_name:
@@ -685,14 +756,21 @@ def doupdatesite(self, pargs):
685756
Log.info(self, "Password Unchanged.")
686757
return 0
687758

759+
if ((stype == "proxy" and stype == oldsitetype and self.app.pargs.hhvm)
760+
or (stype == "proxy" and
761+
stype == oldsitetype and self.app.pargs.pagespeed)):
762+
Log.info(self, Log.FAIL +
763+
"Can not update proxy site to HHVM or Pagespeed")
764+
return 1
688765
if stype == "html" and stype == oldsitetype and self.app.pargs.hhvm:
689766
Log.info(self, Log.FAIL + "Can not update HTML site to HHVM")
690767
return 1
691768

692-
if ((stype == 'php' and oldsitetype != 'html') or
693-
(stype == 'mysql' and oldsitetype not in ['html', 'php']) or
769+
if ((stype == 'php' and oldsitetype not in ['html', 'proxy']) or
770+
(stype == 'mysql' and oldsitetype not in ['html', 'php',
771+
'proxy']) or
694772
(stype == 'wp' and oldsitetype not in ['html', 'php', 'mysql',
695-
'wp']) or
773+
'proxy', 'wp']) or
696774
(stype == 'wpsubdir' and oldsitetype in ['wpsubdomain']) or
697775
(stype == 'wpsubdomain' and oldsitetype in ['wpsubdir']) or
698776
(stype == oldsitetype and cache == oldcachetype) and
@@ -701,6 +779,18 @@ def doupdatesite(self, pargs):
701779
format(oldsitetype, oldcachetype, stype, cache))
702780
return 1
703781

782+
if stype == 'proxy':
783+
data['site_name'] = ee_domain
784+
data['www_domain'] = ee_www_domain
785+
data['proxy'] = True
786+
data['host'] = host
787+
data['port'] = port
788+
pagespeed = False
789+
hhvm = False
790+
data['webroot'] = ee_site_webroot
791+
data['currsitetype'] = oldsitetype
792+
data['currcachetype'] = oldcachetype
793+
704794
if stype == 'php':
705795
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
706796
static=False, basic=True, wp=False, w3tc=False,
@@ -736,8 +826,7 @@ def doupdatesite(self, pargs):
736826

737827
stype = oldsitetype
738828
cache = oldcachetype
739-
740-
if oldsitetype == 'html':
829+
if oldsitetype == 'html' or oldsitetype == 'proxy':
741830
data['static'] = True
742831
data['wp'] = False
743832
data['multisite'] = False
@@ -871,6 +960,13 @@ def doupdatesite(self, pargs):
871960
"`tail /var/log/ee/ee.log` & Try Again!!!")
872961
return 1
873962

963+
if 'proxy' in data.keys() and data['proxy']:
964+
updateSiteInfo(self, ee_domain, stype=stype, cache=cache,
965+
hhvm=hhvm, pagespeed=pagespeed)
966+
Log.info(self, "Successfully updated site"
967+
" http://{0}".format(ee_domain))
968+
return 0
969+
874970
# Update pagespeed config
875971
if pargs.pagespeed:
876972
operateOnPagespeed(self, data)
@@ -917,7 +1013,7 @@ def doupdatesite(self, pargs):
9171013
return 1
9181014

9191015
# Setup WordPress if old sites are html/php/mysql sites
920-
if data['wp'] and oldsitetype in ['html', 'php', 'mysql']:
1016+
if data['wp'] and oldsitetype in ['html', 'proxy', 'php', 'mysql']:
9211017
try:
9221018
ee_wp_creds = setupwordpress(self, data)
9231019
except SiteError as e:

ee/cli/plugins/site_functions.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def check_domain_exists(self, domain):
5252
def setupdomain(self, data):
5353

5454
ee_domain_name = data['site_name']
55-
ee_site_webroot = data['webroot']
55+
ee_site_webroot = data['webroot'] if 'webroot' in data.keys() else ''
5656

5757
# Check if nginx configuration already exists
5858
# if os.path.isfile('/etc/nginx/sites-available/{0}'
@@ -90,6 +90,9 @@ def setupdomain(self, data):
9090
raise SiteError("created nginx configuration failed for site."
9191
" check with `nginx -t`")
9292

93+
if 'proxy' in data.keys() and data['proxy']:
94+
return
95+
9396
# create symbolic link for
9497
EEFileUtils.create_symlink(self, ['/etc/nginx/sites-available/{0}'
9598
.format(ee_domain_name),
@@ -235,6 +238,13 @@ def setupwordpress(self, data):
235238
# ee_wp_user = ''
236239
# ee_wp_pass = ''
237240

241+
if 'wp-user' in data.keys() and data['wp-user']:
242+
ee_wp_user = data['wp-user']
243+
if 'wp-email' in data.keys() and data['wp-email']:
244+
ee_wp_email = data['wp-email']
245+
if 'wp-pass' in data.keys() and data['wp-pass']:
246+
ee_wp_pass = data['wp-pass']
247+
238248
Log.info(self, "Downloading Wordpress \t\t", end='')
239249
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
240250
try:
@@ -510,7 +520,7 @@ def sitebackup(self, data):
510520
EEFileUtils.copyfile(self, '/etc/nginx/sites-available/{0}'
511521
.format(data['site_name']), backup_path)
512522

513-
if data['currsitetype'] in ['html', 'php', 'mysql']:
523+
if data['currsitetype'] in ['html', 'php', 'proxy', 'mysql']:
514524
Log.info(self, "Backing up Webroot \t\t", end='')
515525
EEFileUtils.mvfile(self, ee_site_webroot + '/htdocs', backup_path)
516526
Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
@@ -534,7 +544,7 @@ def sitebackup(self, data):
534544
raise SiteError("mysqldump failed to backup database")
535545
Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
536546
# move wp-config.php/ee-config.php to backup
537-
if data['currsitetype'] in ['mysql']:
547+
if data['currsitetype'] in ['mysql', 'proxy']:
538548
EEFileUtils.mvfile(self, configfiles[0], backup_path)
539549
else:
540550
EEFileUtils.copyfile(self, configfiles[0], backup_path)
@@ -545,7 +555,8 @@ def site_package_check(self, stype):
545555
packages = []
546556
stack = EEStackController()
547557
stack.app = self.app
548-
if stype in ['html', 'php', 'mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
558+
if stype in ['html', 'proxy', 'php', 'mysql', 'wp', 'wpsubdir',
559+
'wpsubdomain']:
549560
Log.debug(self, "Setting apt_packages variable for Nginx")
550561

551562
if EEVariables.ee_platform_distro == 'debian':
@@ -790,8 +801,8 @@ def detSitePar(opts):
790801
raise RuntimeError("could not determine site and cache type")
791802
else:
792803
if not typelist and not cachelist:
793-
sitetype = 'html'
794-
cachetype = 'basic'
804+
sitetype = None
805+
cachetype = None
795806
elif (not typelist) and cachelist:
796807
sitetype = 'wp'
797808
cachetype = cachelist[0]

ee/cli/templates/siteinfo.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Nginx configuration {{type}} {{enable}}
55
{{#hhvm}}HHVM {{hhvm}}{{/hhvm}}
66
access_log {{accesslog}}
77
error_log {{errorlog}}
8-
Webroot {{webroot}}
8+
{{#webroot}}Webroot {{webroot}}{{/webroot}}
99
{{#dbname}}DB_NAME {{dbname}}{{/dbname}}
1010
{{#dbname}}DB_USER {{dbuser}}{{/dbname}}
1111
{{#dbname}}DB_PASS {{dbpass}}{{/dbname}}

0 commit comments

Comments
 (0)