Implement --wprocket

* cleanup templates by using variables
* add configuration for wp-rocket
* update mapping for wp-rocket
This commit is contained in:
VirtuBox
2019-08-05 19:17:59 +02:00
parent 3211a74940
commit 01e6eaecb0
22 changed files with 131 additions and 259 deletions

View File

@@ -333,6 +333,9 @@ class WOSiteCreateController(CementBaseController):
(['--wpsc'],
dict(help="create WordPress single/multi site with wpsc cache",
action='store_true')),
(['--wprocket'],
dict(help="create WordPress single/multi site with WP-Rocket",
action='store_true')),
(['--wpredis'],
dict(help="create WordPress single/multi site "
"with redis cache",
@@ -423,7 +426,8 @@ class WOSiteCreateController(CementBaseController):
if stype == 'proxy':
data = dict(site_name=wo_domain, www_domain=wo_www_domain,
static=True, basic=False, php73=False, wp=False,
wpfc=False, wpsc=False, multisite=False,
wpfc=False, wpsc=False, wprocket=False,
multisite=False,
wpsubdir=False, webroot=wo_site_webroot)
data['proxy'] = True
data['host'] = host
@@ -433,14 +437,16 @@ class WOSiteCreateController(CementBaseController):
if self.app.pargs.php73:
data = dict(site_name=wo_domain, www_domain=wo_www_domain,
static=False, basic=False, php73=True, wp=False,
wpfc=False, wpsc=False, multisite=False,
wpfc=False, wpsc=False, wprocket=False,
multisite=False,
wpsubdir=False, webroot=wo_site_webroot)
data['basic'] = True
if stype in ['html', 'php']:
data = dict(site_name=wo_domain, www_domain=wo_www_domain,
static=True, basic=False, php73=False, wp=False,
wpfc=False, wpsc=False, multisite=False,
wpfc=False, wpsc=False, wprocket=False,
multisite=False,
wpsubdir=False, webroot=wo_site_webroot)
if stype == 'php':
@@ -451,7 +457,8 @@ class WOSiteCreateController(CementBaseController):
data = dict(site_name=wo_domain, www_domain=wo_www_domain,
static=False, basic=True, wp=False, wpfc=False,
wpsc=False, wpredis=False, multisite=False,
wpsc=False, wpredis=False, wprocket=False,
multisite=False,
wpsubdir=False, webroot=wo_site_webroot,
wo_db_name='', wo_db_user='', wo_db_pass='',
wo_db_host='')
@@ -479,6 +486,7 @@ class WOSiteCreateController(CementBaseController):
if ((not self.app.pargs.wpfc) and
(not self.app.pargs.wpsc) and
(not self.app.pargs.wprocket) and
(not self.app.pargs.wpredis)):
data['basic'] = True
@@ -488,6 +496,7 @@ class WOSiteCreateController(CementBaseController):
data['basic'] = False
self.app.pargs.wpredis = True
# Check rerequired packages are installed or not
wo_auth = site_package_check(self, stype)
@@ -825,6 +834,8 @@ class WOSiteUpdateController(CementBaseController):
dict(help="update to wpfc cache", action='store_true')),
(['--wpsc'],
dict(help="update to wpsc cache", action='store_true')),
(['--wprocket'],
dict(help="update to WP-Rocket cache", action='store_true')),
(['--wpredis'],
dict(help="update to redis cache", action='store_true')),
(['-le', '--letsencrypt'],
@@ -868,6 +879,7 @@ class WOSiteUpdateController(CementBaseController):
if not (pargs.php or pargs.php73 or
pargs.mysql or pargs.wp or pargs.wpsubdir or
pargs.wpsubdomain or pargs.wpfc or pargs.wpsc or
pargs.wprocket or
pargs.wpredis or pargs.letsencrypt or pargs.hsts or
pargs.dns or pargs.force):
Log.error(self, "Please provide options to update sites.")
@@ -946,6 +958,7 @@ class WOSiteUpdateController(CementBaseController):
if (pargs.password and not (pargs.html or
pargs.php or pargs.php73 or pargs.mysql or
pargs.wp or pargs.wpfc or pargs.wpsc or
pargs.wprocket or
pargs.wpsubdir or pargs.wpsubdomain or
pargs.hsts)):
try:
@@ -958,6 +971,7 @@ class WOSiteUpdateController(CementBaseController):
if (pargs.hsts and not (pargs.html or
pargs.php or pargs.php73 or pargs.mysql or
pargs.wp or pargs.wpfc or pargs.wpsc or
pargs.wprocket or
pargs.wpsubdir or pargs.wpsubdomain or
pargs.password)):
try:
@@ -999,7 +1013,7 @@ class WOSiteUpdateController(CementBaseController):
if stype == 'php':
data = dict(site_name=wo_domain, www_domain=wo_www_domain,
static=False, basic=True, wp=False, wpfc=False,
wpsc=False, wpredis=False, multisite=False,
wpsc=False, wpredis=False, wprocket=False, multisite=False,
wpsubdir=False, webroot=wo_site_webroot,
currsitetype=oldsitetype, currcachetype=oldcachetype)
@@ -1007,7 +1021,7 @@ class WOSiteUpdateController(CementBaseController):
data = dict(site_name=wo_domain, www_domain=wo_www_domain,
static=False, basic=True, wp=False, wpfc=False,
wpsc=False, wpredis=False, multisite=False,
wpsc=False, wpredis=False, wprocket=False, multisite=False,
wpsubdir=False, webroot=wo_site_webroot,
wo_db_name='', wo_db_user='', wo_db_pass='',
wo_db_host='',
@@ -1061,21 +1075,31 @@ class WOSiteUpdateController(CementBaseController):
data['wpfc'] = False
data['wpsc'] = False
data['wpredis'] = False
data['wprocket'] = False
elif oldcachetype == 'wpfc':
data['basic'] = False
data['wpfc'] = True
data['wpsc'] = False
data['wpredis'] = False
data['wprocket'] = False
elif oldcachetype == 'wpsc':
data['basic'] = False
data['wpfc'] = False
data['wpsc'] = True
data['wpredis'] = False
data['wprocket'] = False
elif oldcachetype == 'wpredis':
data['basic'] = False
data['wpfc'] = False
data['wpsc'] = False
data['wpredis'] = True
data['wprocket'] = False
elif oldcachetype == 'wprocket':
data['basic'] = False
data['wpfc'] = False
data['wpsc'] = False
data['wpredis'] = False
data['wprocket'] = True
if pargs.php73 == 'on':
data['php73'] = True
@@ -1233,6 +1257,11 @@ class WOSiteUpdateController(CementBaseController):
data['basic'] = False
cache = 'wpredis'
if pargs.wprocket and data['currcachetype'] != 'wprocket':
data['wprocket'] = True
data['basic'] = False
cache = 'wprocket'
if (php73 is old_php73) and (stype == oldsitetype and
cache == oldcachetype):
return 1
@@ -1620,6 +1649,16 @@ class WOSiteUpdateController(CementBaseController):
"`tail /var/log/wo/wordops.log` and please try again")
return 1
if oldcachetype == 'wprocket' and not data['wprocket']:
try:
uninstallwp_plugin(self, 'wp-rocket', data)
except SiteError as e:
Log.debug(self, str(e))
Log.info(self, Log.FAIL + "Update site failed."
"Check the log for details: "
"`tail /var/log/wo/wordops.log` and please try again")
return 1
# Service Nginx Reload
if not WOService.reload_service(self, 'nginx'):
Log.error(self, "service nginx reload failed. "

View File

@@ -897,12 +897,12 @@ def site_package_check(self, stype):
if (os.path.isdir("/etc/nginx/common") and
not os.path.isfile("/etc/nginx/common/locations-wo.conf")):
data = dict()
data = dict(upstream="php73")
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/locations-wo.conf')
wo_nginx = open('/etc/nginx/common/locations-wo.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'locations-php7.mustache',
self.app.render((data), 'locations.mustache',
out=wo_nginx)
wo_nginx.close()
@@ -910,7 +910,7 @@ def site_package_check(self, stype):
'file /etc/nginx/common/php73.conf')
wo_nginx = open('/etc/nginx/common/php73.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'php7.mustache',
self.app.render((data), 'php.mustache',
out=wo_nginx)
wo_nginx.close()
@@ -918,7 +918,7 @@ def site_package_check(self, stype):
'file /etc/nginx/common/wpcommon-php73.conf')
wo_nginx = open('/etc/nginx/common/wpcommon-php73.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'wpcommon-php7.mustache',
self.app.render((data), 'wpcommon.mustache',
out=wo_nginx)
wo_nginx.close()
@@ -926,7 +926,7 @@ def site_package_check(self, stype):
'file /etc/nginx/common/wpfc-php73.conf')
wo_nginx = open('/etc/nginx/common/wpfc-php73.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'wpfc-php7.mustache',
self.app.render((data), 'wpfc.mustache',
out=wo_nginx)
wo_nginx.close()
@@ -934,18 +934,26 @@ def site_package_check(self, stype):
'file /etc/nginx/common/wpsc-php73.conf')
wo_nginx = open('/etc/nginx/common/wpsc-php73.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'wpsc-php7.mustache',
self.app.render((data), 'wpsc.mustache',
out=wo_nginx)
wo_nginx.close()
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/wprocket-php73.conf')
wo_nginx = open('/etc/nginx/common/wprocket-php73.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'wprocket.mustache',
out=wo_nginx)
wo_nginx.close()
if (os.path.isfile("/etc/nginx/nginx.conf") and
not os.path.isfile("/etc/nginx/common/redis-php73.conf")):
data = dict()
data = dict(upstream="php73")
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/redis-php73.conf')
wo_nginx = open('/etc/nginx/common/redis-php73.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'redis-php7.mustache',
self.app.render((data), 'redis.mustache',
out=wo_nginx)
wo_nginx.close()

View File

@@ -230,7 +230,7 @@ def post_pref(self, apt_packages, packages):
os.makedirs('/etc/nginx/common')
if os.path.exists('/etc/nginx/common'):
data = dict(webroot=WOVariables.wo_webroot)
data = dict()
# Common Configuration
Log.debug(self, 'Writting the nginx configuration to '
@@ -248,7 +248,7 @@ def post_pref(self, apt_packages, packages):
self.app.render((data), 'wpsubdir.mustache',
out=wo_nginx)
wo_nginx.close()
data = dict(upstream="php72")
# PHP 7.2 conf
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/php72.conf')
@@ -258,6 +258,14 @@ def post_pref(self, apt_packages, packages):
out=wo_nginx)
wo_nginx.close()
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/redis-php72.conf')
wo_nginx = open('/etc/nginx/common/redis-php72.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'redis.mustache',
out=wo_nginx)
wo_nginx.close()
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/wpcommon-php72.conf')
wo_nginx = open('/etc/nginx/common/wpcommon-php72.conf',
@@ -282,15 +290,23 @@ def post_pref(self, apt_packages, packages):
out=wo_nginx)
wo_nginx.close()
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/wprocket-php72.conf')
wo_nginx = open('/etc/nginx/common/wprocket-php72.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'wprocket.mustache',
out=wo_nginx)
wo_nginx.close()
# PHP 7.3 conf
if os.path.isdir("/etc/nginx/common"):
data = dict()
data = dict(upstream="php73")
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/php73.conf')
wo_nginx = open('/etc/nginx/common/php73.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'php7.mustache',
self.app.render((data), 'php.mustache',
out=wo_nginx)
wo_nginx.close()
@@ -298,7 +314,7 @@ def post_pref(self, apt_packages, packages):
'file /etc/nginx/common/wpcommon-php73.conf')
wo_nginx = open('/etc/nginx/common/wpcommon-php73.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'wpcommon-php7.mustache',
self.app.render((data), 'wpcommon.mustache',
out=wo_nginx)
wo_nginx.close()
@@ -306,7 +322,7 @@ def post_pref(self, apt_packages, packages):
'file /etc/nginx/common/wpfc-php73.conf')
wo_nginx = open('/etc/nginx/common/wpfc-php73.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'wpfc-php7.mustache',
self.app.render((data), 'wpfc.mustache',
out=wo_nginx)
wo_nginx.close()
@@ -314,26 +330,23 @@ def post_pref(self, apt_packages, packages):
'file /etc/nginx/common/wpsc-php73.conf')
wo_nginx = open('/etc/nginx/common/wpsc-php73.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'wpsc-php7.mustache',
self.app.render((data), 'wpsc.mustache',
out=wo_nginx)
wo_nginx.close()
# create redis conf
data = dict()
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/redis-php72.conf')
wo_nginx = open('/etc/nginx/common/redis-php72.conf',
'file /etc/nginx/common/wprocket-php73.conf')
wo_nginx = open('/etc/nginx/common/wprocket-php73.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'redis.mustache',
self.app.render((data), 'wprocket.mustache',
out=wo_nginx)
wo_nginx.close()
data = dict()
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/redis-php73.conf')
wo_nginx = open('/etc/nginx/common/redis-php73.conf',
encoding='utf-8', mode='w')
self.app.render((data), 'redis-php7.mustache',
self.app.render((data), 'redis.mustache',
out=wo_nginx)
wo_nginx.close()