diff --git a/.gitignore b/.gitignore index d30a7b1f..41b775bf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] +.idea/ # C extensions *.so diff --git a/.travis.yml b/.travis.yml index b0f9871e..d3f8073d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -77,6 +77,13 @@ script: - yes | sudo ee site create site.hhvm.pagespeed11.in --w3tc --wpsubdomain --hhvm --pagespeed - yes | sudo ee site create site.hhvm.pagespeed12.in --wpfc --wpsubdomain --hhvm --pagespeed + - sudo ee site create site.localtest.me --php --mysql --html + - sudo ee site create site1.localtest.me --php --mysql + - sudo ee site create site2.localtest.me --mysql --html + - sudo ee site create site3.localtest.me --php --html + - sudo ee site create site4.localtest.me --wp --wpsubdomain + - sudo ee site create site5.localtest.me --wp --wpsubdir --wpfc + - sudo ee debug --all - sudo ee debug --all=off - sudo ee debug site12.net diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 24d7a243..5c24768a 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,23 @@ +v 3.3.5 - Aug 26, 2015 +- Introduced new support of --force/-f in delete command of site + - Removes database entry or nginx configuration of site from system + - ee site delete example.com --force/-f + - ee site delete example.com --force/-f --db/--files +- Moved ~/.my.cnf to /etc/mysql/conf.d/my.cnf + - Fixed MySQL credential issue +- Fixed Bug in cache clean --all command +- Improved 404 handling for static HTML sites #561 +- Improved cleanup action while site create command fail +- Updated wpfc config #543 +- Improved ee sync command https://github.com/rtCamp/easyengine/issues/575#issuecomment-126293815 +- Bug Fix #486 +- Bug Fix #555 +- Updated man page +- Fixed bug in ee update site to --wpredis +- Fixed Autocompletion Issue #519 +- Fixed minor bug in update --password +- Minor fix and improvements + v 3.3.4 - Aug 12, 2015 - Bug Fix for https://github.com/rtCamp/easyengine/issues/598#issue-98354466 diff --git a/config/bash_completion.d/ee_auto.rc b/config/bash_completion.d/ee_auto.rc index e905dbef..0b7011cc 100644 --- a/config/bash_completion.d/ee_auto.rc +++ b/config/bash_completion.d/ee_auto.rc @@ -11,7 +11,7 @@ _ee_complete() # SETUP THE BASE LEVEL (everything after "ee") if [ $COMP_CWORD -eq 1 ]; then COMPREPLY=( $(compgen \ - -W "stack site debug clean secure import-slow-log log update sync info" \ + -W "stack site debug clean secure import-slow-log log update sync info --version --help --quiet" \ -- $cur) ) @@ -22,7 +22,7 @@ _ee_complete() # HANDLE EVERYTHING AFTER THE SECOND LEVEL NAMESPACE "clean") COMPREPLY=( $(compgen \ - -W "--memcache --opcache --fastcgi --pagespeed --all" \ + -W "--memcache --opcache --fastcgi --pagespeed --redis --all" \ -- $cur) ) ;; @@ -176,7 +176,7 @@ _ee_complete() ;; "delete") COMPREPLY=( $(compgen \ - -W "--db --files --all --no-prompt" \ + -W "--db --files --all --no-prompt --force -f" \ -- $cur) ) ;; "show") @@ -214,10 +214,29 @@ _ee_complete() fi case "$prev" in - "--wp" | "--wpsubdir" | "--wpsubdomain") + "--wp") if [ ${COMP_WORDS[1]} != "debug" ]; then if [ ${COMP_WORDS[2]} == "create" ]; then - retlist="--w3tc --wpfc --wpsc --pagespeed --hhvm --user --email --pass --wpredis" + retlist="--wp --wpsc --w3tc --wpfc --pagespeed --hhvm --user --email --pass --wpredis" + elif [ ${COMP_WORDS[2]} == "update" ]; then + retlist="--wp --w3tc --wpfc --wpsc --pagespeed --hhvm --pagespeed=off --hhvm=off --wpredis" + else + retlist="" + fi + else + retlist="--wp --wp=off --rewrite --rewrite=off -i --interactive" + fi + + ret="${retlist[@]/$prev}" + COMPREPLY=( $(compgen \ + -W "$(echo $ret)" \ + -- $cur) ) + ;; + + "--wpsubdir" | "--wpsubdomain") + if [ ${COMP_WORDS[1]} != "debug" ]; then + if [ ${COMP_WORDS[2]} == "create" ]; then + retlist="--wpsc --w3tc --wpfc --pagespeed --hhvm --user --email --pass --wpredis" elif [ ${COMP_WORDS[2]} == "update" ]; then retlist="--w3tc --wpfc --wpsc --pagespeed --hhvm --pagespeed=off --hhvm=off --wpredis" else @@ -233,10 +252,21 @@ _ee_complete() -- $cur) ) ;; - "--pagespeed" | "--hhvm" | "--wpredis" ) + "--pagespeed" | "--hhvm" | "--wpredis" | "--w3tc" | "--wpfc" | "--wpsc" | "--wpsubdir" | "--wpsubdomain" | "--user" | "--pass" | "--email" | "--wp") if [ ${COMP_WORDS[2]} == "create" ]; then - retlist="--user --pass --email --html --php --mysql --wp --wpsubdir --wpsubdomain --w3tc --wpfc --wpsc --hhvm --pagespeed --experimenal --wpredis" - elif [ ${COMP_WORDS[2]} == "update" ]; then + retlist="--user --pass --email --wp --wpsubdir --wpsubdomain --w3tc --wpfc --wpsc --hhvm --pagespeed --experimenal --wpredis" + else + retlist="" + fi + + ret="${retlist[@]/$prev}" + COMPREPLY=( $(compgen \ + -W "$(echo $ret)" \ + -- $cur) ) + ;; + + "--pagespeed" | "--hhvm" | "--wpredis" | "--w3tc" | "--wpfc") + if [ ${COMP_WORDS[2]} == "update" ]; then retlist="--password --php --mysql --wp --wpsubdir --wpsubdomain --w3tc --wpfc --wpsc --hhvm --hhvm=off --pagespeed --pagespeed=off --experimenal --wpredis" else retlist="" @@ -276,8 +306,8 @@ _ee_complete() -- $cur) ) ;; - "--db" | "--files" ) - retlist="--db --files --all" + "--db" | "--files" | "--force") + retlist="--db --files --all --force" ret="${retlist[@]/$prev}" COMPREPLY=( $(compgen \ -W "$(echo $ret)" \ @@ -286,9 +316,9 @@ _ee_complete() "--all") if [ ${COMP_WORDS[1]} == "clean" ]; then - retlist="--memcache --opcache --fastcgi" + retlist="--memcache --opcache --fastcgi --redis" elif [ ${COMP_WORDS[2]} == "delete" ]; then - retlist="--db --files" + retlist="--db --files --force" elif [ ${COMP_WORDS[2]} == "update" ]; then retlist="--password --php --mysql --wp --wpsubdir --wpsubdomain --w3tc --wpfc --wpsc --hhvm --hhvm=off --pagespeed --pagespeed=off --wpredis" else @@ -300,8 +330,8 @@ _ee_complete() -- $cur) ) ;; - "--memcache" | "--opcache" | "--fastcgi" | "--all") - retlist="--memcache --opcache --fastcgi --all" + "--memcache" | "--opcache" | "--fastcgi" | "--all" | "--redis" | "--pagespeed") + retlist="--memcache --opcache --fastcgi --pagespeed --redis --all" ret="${retlist[@]/$prev}" COMPREPLY=( $(compgen \ -W "$(echo $ret)" \ diff --git a/docs/ee.8 b/docs/ee.8 index 77e39715..edb72505 100644 --- a/docs/ee.8 +++ b/docs/ee.8 @@ -1,21 +1,21 @@ -.TH ee 8 "EasyEngine (ee) version: 3.0" "Feb 2,2014" "EasyEngine" +.TH ee 8 "EasyEngine (ee) version: 3.3.5" "Aug 11,2015" "EasyEngine" .SH NAME .B EasyEngine (ee) \- Manage Nginx Based Websites. .SH SYNOPSIS -ee [ --version | --help | info | stack | site | debug | update ] +ee [ --version | --help | info | stack | site | debug | update | clean | import_slow_log | log | secure | sync] .TP -ee stack [ install | remove | purge ] [ --web | --mail | --all | --nginx | --php | --mysql | --postfix | --adminer | --phpmyadmin | --wpcli | --utils ] +ee stack [ install | remove | purge | migrate | upgrade] [ --web | --mail | --all | --nginx | --php | --mysql | --admin | --postfix | --mailscanner | --adminer | --redis | --hhvm | --phpmyadmin | --phpredisadmin | --wpcli | --utils ] .TP -ee stack [ status | start | stop | reload | restart ] +ee stack [ status | start | stop | reload | restart ] [--all | --nginx | --php | --mysql | --devcot | --web | --postfix | --memcache | --redis] .TP -ee site [ list | info | show | enable | disable | edit ] [ example.com ] +ee site [ list | info | show | enable | disable | edit | cd | show ] [ example.com ] .TP -ee site create example.com [ --html | --php | --mysql] [[--wp | --wpsubdir | --wpsubdomain ] [--basic | --wpsc | --w3tc | --wpfc]] +ee site create example.com [ --html | --php | --mysql] [[--wp | --wpsubdir | --wpsubdomain ] [--wpsc | --w3tc | --wpfc | --wpredis | --hhvm | --pagespeed ]] .TP -ee site update example.com [ --php | --mysql] [[--wp | --wpsubdir | --wpsubdomain ] [--basic | --wpsc | --w3tc | --wpfc]] +ee site update example.com [ --php | --mysql] [[--wp | --wpsubdir | --wpsubdomain ] [--wpsc | --w3tc | --wpfc | --wpredis | --hhvm | --pagespeed ] [--password]] .TP -ee site delete example.com [--db | --files | --all | --no-prompt ] +ee site delete example.com [--db | --files | --all | --no-prompt | --force/-f ] .TP ee debug [ -i | --all=on/off |--nginx=on/off | --rewrite=on/off | --php=on/off | --fpm=on/off | --mysql=on/off ] .TP @@ -46,19 +46,19 @@ Display easyengine (ee) help. .TP .B stack .TP -.B install [ --all | --web | --mail | --nginx | --php | --mysql | --postfix | --adminer | --phpmyadmin | --wpcli | --utils ] +.B install [ --all | --web | --mail | --nginx | --php | --mysql | --redis | --postfix | --adminer | --phpmyadmin | --phpredismyadmin | --wpcli | --utils ] .br Install Nginx PHP5 MySQL Postfix stack Packages if not used with .br any options.Installs specific package if used with option. .TP -.B remove [ --all | --web | --mail | --nginx | --php | --mysql | --postfix | --adminer | --phpmyadmin | --wpcli | --utils ] +.B remove [ --all | --web | --mail | --nginx | --php | --mysql | --redis | --postfix | --adminer | --phpmyadmin | --phpredismyadmin | --wpcli | --utils ] .br Remove Nginx PHP5 MySQL Postfix stack Packages if not used with .br any options. Remove specific package if used with option. .TP -.B purge [ --all | --web | --mail | --nginx | --php | --mysql | --postfix | --adminer | --phpmyadmin | --wpcli | --utils ] +.B purge [ --all | --web | --mail | --nginx | --php | --mysql | --redis | --postfix | --adminer | --phpmyadmin | --phpredismyadmin | --wpcli | --utils ] .br Purge Nginx PHP5 MySQL Postfix stack Packages if not used with any .br @@ -66,23 +66,23 @@ options.Purge specific package if used with option. .TP .B status .br -Display status of NGINX, PHP5-FPM, MySQL, Postfix services. +Display status of NGINX, PHP5-FPM, MySQL, Postfix, Redis-Server services. .TP .B start .br -Start services NGINX, PHP5-FPM, MySQL, Postfix. +Start services NGINX, PHP5-FPM, MySQL, Postfix, Redis-Server. .TP .B stop .br -Stop services NGINX, PHP5-FPM, MySQL, Postfix. +Stop services NGINX, PHP5-FPM, MySQL, Postfix, Redis-Server. .TP .B reload .br -Reload services NGINX, PHP5-FPM, MySQL, Postfix. +Reload services NGINX, PHP5-FPM, MySQL, Postfix, Redis-Server. .TP .B restart .br -Restart services NGINX, PHP5-FPM, MySQL, Postfix. +Restart services NGINX, PHP5-FPM, MySQL, Postfix, Redis-Server. .TP .B site .br @@ -129,19 +129,19 @@ Disable site by Destroying softlink with site file in .br Edit NGINX configuration of site. .TP -.B create [ example.com ] [ --html | --php | --mysql] [[--wp | --wpsubdir | --wpsubdomain ] [--basic | --wpsc | --w3tc | --wpfc]] +.B create [ example.com ] [ --html | --php | --mysql] [[--wp | --wpsubdir | --wpsubdomain ] [--wpsc | --w3tc | --wpfc | --wpredis | --hhvm | --pagespeed ]] .br Create new site according to given options. If no options provided .br create static site with html only. .TP -.B update [ example.com ] [ --html | --php | --mysql] [[--wp | --wpsubdir | --wpsubdomain ] [--basic | --wpsc | --w3tc | --wpfc]] +.B update [ example.com ] [ --html | --php | --mysql] [[--wp | --wpsubdir | --wpsubdomain ] [ --wpsc | --w3tc | --wpfc | --wpredis | --hhvm | --pagespeed ] [--password]] .br Update site configuration according to specified options. .TP -.B delete [ example.com ] [--no-prompt ] [ --db | --files ] +.B delete [ example.com ] [--no-prompt ] [--force/-f] [ --db | --files | --all ] .br -Delete site i.e webroot, database, ad configuration permenantly. +Delete site i.e webroot, database, ad configuration permanently. .TP .B debug [ -i | --nginx=on/off | --php=on/off | --mysql=on/off | --rewrite=on/off | --fpm=on/off ] .br @@ -159,13 +159,13 @@ services.Else it will debug only service provided with argument.This will Stop D .br if used with --all=off argument. .TP -.B secure [ --auth | --port ] +.B secure [ --auth | --port | --ip ] .br Update security settings. .TP -.B clean [ --fastcgi | --opcache | --memcache | --all ] +.B clean [ --fastcgi | --opcache | --memcache | --redis | --pagespeed | --all ] .br -Clean NGINX fastCGI cache, Opcache, Memcache. +Clean NGINX fastCGI cache, Opcache, Memcache, Redis cache, Pagespeed cache. .br Clean NGINX fastCGI cache if no option specified. .SH ARGUMENTS @@ -244,6 +244,12 @@ Delete website webroot. .B --no-prompt .br Does not prompt for confirmation when delete command used. +.br +.TP +.B --force/-f +.br +Delete website webroot and database forcefully.Remove nginx configuration for site. +.br .TP .B --auth .br @@ -258,10 +264,6 @@ used with ee secure command. Change EasyEngine admin port 22222. used with ee secure command. Update whitelist IP address .SH WORDPRESS CACHING OPTIONS .TP -.B --basic -.br -Create WordPress website without cache. -.TP .B --w3tc .br Install and activate Nginx-helper and W3 Total Cache plugin. @@ -275,6 +277,14 @@ Install and activate Nginx-helper and WP Super Cache plugin. Install and activate Nginx-helper and W3 Total Cache plugin with .br Nginx FastCGI cache. +.TP +.B --wpredis +.br +Install, activate, configure Nginx-helper and Redis Object Cache Plugin, Configure NGINX for Redis Page Caching. +.TP +.B --hhvm +.br +Install, activate Nginx-helper and configure NGINX for HHVM. .SH FILES .br /etc/easyengine/ee.conf @@ -300,6 +310,13 @@ Report bugs at .B Shital .I \ .br +.B Prabuddha +.I \ +.br +.B Rajdeep Sharma +.I \ +.br + .SH "SEE ALSO" .br EE: diff --git a/ee/cli/plugins/clean.py b/ee/cli/plugins/clean.py index 6d3617f1..b8657998 100644 --- a/ee/cli/plugins/clean.py +++ b/ee/cli/plugins/clean.py @@ -20,7 +20,7 @@ class EECleanController(CementBaseController): label = 'clean' stacked_on = 'base' stacked_type = 'nested' - description = ('Clean NGINX FastCGI cache, Opcacache, Memcache') + description = ('Clean NGINX FastCGI cache, Opcacache, Memcache, Pagespeed Cache, Redis Cache') arguments = [ (['--all'], dict(help='Clean all cache', action='store_true')), @@ -80,7 +80,7 @@ class EECleanController(CementBaseController): Log.info(self, "Memcache not installed") except Exception as e: Log.debug(self, "{0}".format(e)) - Log.error(self, "Unable to restart Memcached") + Log.error(self, "Unable to restart Memcached", False) @expose(hide=True) def clean_fastcgi(self): @@ -89,7 +89,7 @@ class EECleanController(CementBaseController): Log.info(self, "Cleaning NGINX FastCGI cache") EEShellExec.cmd_exec(self, "rm -rf /var/run/nginx-cache/*") else: - Log.error(self, "Unable to clean FastCGI cache") + Log.error(self, "Unable to clean FastCGI cache", False) @expose(hide=True) def clean_opcache(self): @@ -105,7 +105,7 @@ class EECleanController(CementBaseController): " please check you have admin tools installed") Log.debug(self, "please check you have admin tools installed," " or install them with `ee stack install --admin`") - Log.error(self, "Unable to clean opcache") + Log.error(self, "Unable to clean opcache", False) @expose(hide=True) def clean_pagespeed(self): @@ -116,7 +116,7 @@ class EECleanController(CementBaseController): else: Log.debug(self, "/var/ngx_pagespeed_cache does not exist," " so cache not cleared") - Log.error(self, "Unable to clean pagespeed cache") + Log.error(self, "Unable to clean pagespeed cache", False) def load(app): diff --git a/ee/cli/plugins/site.py b/ee/cli/plugins/site.py index 2ca4d800..fd2b7984 100644 --- a/ee/cli/plugins/site.py +++ b/ee/cli/plugins/site.py @@ -468,7 +468,7 @@ class EESiteCreateController(CementBaseController): if data and self.app.pargs.hhvm: if (not self.app.pargs.experimental): - Log.info(self, "HHVM is experimental feature and it may not" + Log.info(self, "HHVM is experimental feature and it may not " "work with all plugins of your site.\nYou can " "disable it by passing --hhvm=off later.\nDo you wish" " to enable HHVM now for {0}?".format(ee_domain)) @@ -493,7 +493,7 @@ class EESiteCreateController(CementBaseController): if data and self.app.pargs.pagespeed: if (not self.app.pargs.experimental): - Log.info(self, "PageSpeed is experimental feature and it may not" + Log.info(self, "PageSpeed is experimental feature and it may not " "work with all CSS/JS/Cache of your site.\nYou can " "disable it by passing --pagespeed=off later.\nDo you wish" " to enable PageSpeed now for {0}?".format(ee_domain)) @@ -863,7 +863,7 @@ class EESiteUpdateController(CementBaseController): updatewpuserpassword(self, ee_domain, ee_site_webroot) except SiteError as e: Log.debug(self, str(e)) - Log.info(self, "Password Unchanged.") + Log.info(self, "\nPassword Unchanged.") return 0 if ((stype == "proxy" and stype == oldsitetype and self.app.pargs.hhvm) @@ -1163,7 +1163,8 @@ class EESiteUpdateController(CementBaseController): " http://{0}".format(ee_domain)) return 0 - if data['ee_db_name'] and not data['wp']: + #if data['ee_db_name'] and not data['wp']: + if 'ee_db_name' in data.keys() and not data['wp']: try: data = setupdatabase(self, data) except SiteError as e: @@ -1305,7 +1306,24 @@ class EESiteUpdateController(CementBaseController): if oldcachetype != 'wpredis' and data['wpredis']: try: - installwp_plugin(self, 'redis-cache', data) + if installwp_plugin(self, 'redis-cache', data): + if EEShellExec.cmd_exec(self, "grep -q \"WP_CACHE_KEY_SALT\" {0}/wp-config.php" + .format(ee_site_webroot)): + pass + else: + try: + wpconfig = open("{0}/wp-config.php".format(ee_site_webroot), + encoding='utf-8', mode='a') + wpconfig.write("\n\ndefine( \'WP_CACHE_KEY_SALT\', \'{0}:\' );" + .format(ee_domain)) + wpconfig.close() + except IOError as e: + Log.debug(self, str(e)) + Log.debug(self, "Updating wp-config.php failed.") + Log.warn(self, "Updating wp-config.php failed. " + "Could not append:" + "\ndefine( \'WP_CACHE_KEY_SALT\', \'{0}:\' );".format(ee_domain) + + "\nPlease add manually") except SiteError as e: Log.debug(self, str(e)) Log.info(self, Log.FAIL + "Update site failed." @@ -1368,6 +1386,9 @@ class EESiteDeleteController(CementBaseController): (['--no-prompt'], dict(help="doesnt ask permission for delete", action='store_true')), + (['-f','--force'], + dict(help="forcefully delete site and configuration", + action='store_true')), (['--all'], dict(help="delete all", action='store_true')), (['--db'], @@ -1392,6 +1413,8 @@ class EESiteDeleteController(CementBaseController): ee_db_name = '' ee_prompt = '' ee_nginx_prompt = '' + mark_db_delete_prompt = False + mark_webroot_delete_prompt = False mark_db_deleted = False mark_webroot_deleted = False if not check_domain_exists(self, ee_domain): @@ -1429,11 +1452,13 @@ class EESiteDeleteController(CementBaseController): ' database [y/N]: ') else: ee_db_prompt = 'Y' + mark_db_delete_prompt = True if ee_db_prompt == 'Y' or ee_db_prompt == 'y': + mark_db_delete_prompt = True Log.info(self, "Deleting Database, {0}, user {1}" .format(ee_db_name, ee_db_user)) - deleteDB(self, ee_db_name, ee_db_user, ee_db_host) + deleteDB(self, ee_db_name, ee_db_user, ee_db_host, False) updateSiteInfo(self, ee_domain, db_name='deleted', db_user='deleted', @@ -1453,8 +1478,10 @@ class EESiteDeleteController(CementBaseController): 'webroot [y/N]: ') else: ee_web_prompt = 'Y' + mark_webroot_delete_prompt = True if ee_web_prompt == 'Y' or ee_web_prompt == 'y': + mark_webroot_delete_prompt = True Log.info(self, "Deleting Webroot, {0}" .format(ee_site_webroot)) deleteWebRoot(self, ee_site_webroot) @@ -1465,13 +1492,20 @@ class EESiteDeleteController(CementBaseController): mark_webroot_deleted = True Log.info(self, "Webroot seems to be already deleted") - if (mark_webroot_deleted and mark_db_deleted): + if not self.app.pargs.force: + if (mark_webroot_deleted and mark_db_deleted): + # TODO Delete nginx conf + removeNginxConf(self, ee_domain) + deleteSiteInfo(self, ee_domain) + Log.info(self, "Deleted site {0}".format(ee_domain)) + # else: + # Log.error(self, " site {0} does not exists".format(ee_domain)) + else: + if (mark_db_delete_prompt or mark_webroot_delete_prompt or (mark_webroot_deleted and mark_db_deleted)): # TODO Delete nginx conf removeNginxConf(self, ee_domain) deleteSiteInfo(self, ee_domain) Log.info(self, "Deleted site {0}".format(ee_domain)) - # else: - # Log.error(self, " site {0} does not exists".format(ee_domain)) class EESiteListController(CementBaseController): diff --git a/ee/cli/plugins/site_functions.py b/ee/cli/plugins/site_functions.py index 9bd0b907..be2327ff 100644 --- a/ee/cli/plugins/site_functions.py +++ b/ee/cli/plugins/site_functions.py @@ -250,8 +250,12 @@ def setupwordpress(self, data): Log.info(self, "Downloading Wordpress \t\t", end='') EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) try: - EEShellExec.cmd_exec(self, "wp --allow-root core" - " download") + if EEShellExec.cmd_exec(self, "wp --allow-root core" + " download"): + pass + else: + Log.info(self, "[" + Log.ENDC + Log.FAIL + "Fail" + Log.OKBLUE + "]") + raise SiteError("download wordpress core failed") except CommandExecutionError as e: Log.info(self, "[" + Log.ENDC + Log.FAIL + "Fail" + Log.OKBLUE + "]") raise SiteError(self, "download wordpress core failed") @@ -293,7 +297,7 @@ def setupwordpress(self, data): .format(data['ee_db_pass'], "\n\ndefine(\'WP_DEBUG\', false);")) try: - EEShellExec.cmd_exec(self, "bash -c \"php {0} --allow-root" + if EEShellExec.cmd_exec(self, "bash -c \"php {0} --allow-root" .format(EEVariables.ee_wpcli_path) + " core config " + "--dbname=\'{0}\' --dbprefix=\'{1}\' " @@ -309,7 +313,10 @@ def setupwordpress(self, data): .format(ee_domain_name) if data['wpredis'] else ''), log=False - ) + ): + pass + else : + raise SiteError("generate wp-config failed for wp single site") except CommandExecutionError as e: raise SiteError("generate wp-config failed for wp single site") else: @@ -328,7 +335,7 @@ def setupwordpress(self, data): " true);", "\n\ndefine(\'WP_DEBUG\', false);")) try: - EEShellExec.cmd_exec(self, "bash -c \"php {0} --allow-root" + if EEShellExec.cmd_exec(self, "bash -c \"php {0} --allow-root" .format(EEVariables.ee_wpcli_path) + " core config " + "--dbname=\'{0}\' --dbprefix=\'{1}\' " @@ -348,12 +355,26 @@ def setupwordpress(self, data): .format(ee_domain_name) if data['wpredis'] else ''), log=False - ) + ): + pass + else: + raise SiteError("generate wp-config failed for wp multi site") except CommandExecutionError as e: raise SiteError("generate wp-config failed for wp multi site") - EEFileUtils.mvfile(self, os.getcwd()+'/wp-config.php', - os.path.abspath(os.path.join(os.getcwd(), os.pardir))) + #EEFileUtils.mvfile(self, os.getcwd()+'/wp-config.php', + # os.path.abspath(os.path.join(os.getcwd(), os.pardir))) + + try: + import shutil + + Log.debug(self, "Moving file from {0} to {1}".format(os.getcwd()+'/wp-config.php',os.path.abspath(os.path.join(os.getcwd(), os.pardir)))) + shutil.move(os.getcwd()+'/wp-config.php',os.path.abspath(os.path.join(os.getcwd(), os.pardir))) + except Exception as e: + Log.error(self, 'Unable to move file from {0} to {1}' + .format(os.getcwd()+'/wp-config.php', os.path.abspath(os.path.join(os.getcwd(), os.pardir))),False) + raise SiteError("Unable to move wp-config.php") + if not ee_wp_user: ee_wp_user = EEVariables.ee_user @@ -399,7 +420,7 @@ def setupwordpress(self, data): + "--admin_password= --admin_email=\'{1}\'" .format(ee_wp_pass, ee_wp_email)) try: - EEShellExec.cmd_exec(self, "php {0} --allow-root core " + if EEShellExec.cmd_exec(self, "php {0} --allow-root core " .format(EEVariables.ee_wpcli_path) + "install --url=\'{0}\' --title=\'{0}\' " "--admin_name=\'{1}\' " @@ -407,8 +428,11 @@ def setupwordpress(self, data): + "--admin_password=\'{0}\' " "--admin_email=\'{1}\'" .format(ee_wp_pass, ee_wp_email), - log=False) - except CommandExceutionError as e: + log=False): + pass + else: + raise SiteError("setup wordpress tables failed for single site") + except CommandExecutionError as e: raise SiteError("setup wordpress tables failed for single site") else: Log.debug(self, "Creating tables for WordPress multisite") @@ -423,7 +447,7 @@ def setupwordpress(self, data): subdomains='--subdomains' if not data['wpsubdir'] else '')) try: - EEShellExec.cmd_exec(self, "php {0} --allow-root " + if EEShellExec.cmd_exec(self, "php {0} --allow-root " .format(EEVariables.ee_wpcli_path) + "core multisite-install " "--url=\'{0}\' --title=\'{0}\' " @@ -435,7 +459,10 @@ def setupwordpress(self, data): .format(ee_wp_pass, ee_wp_email, subdomains='--subdomains' if not data['wpsubdir'] else ''), - log=False) + log=False): + pass + else: + raise SiteError("setup wordpress tables failed for wp multi site") except CommandExecutionError as e: raise SiteError("setup wordpress tables failed for wp multi site") @@ -480,11 +507,16 @@ def setupwordpressnetwork(self, data): EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot)) Log.info(self, "Setting up WordPress Network \t", end='') try: - EEShellExec.cmd_exec(self, 'wp --allow-root core multisite-convert' + if EEShellExec.cmd_exec(self, 'wp --allow-root core multisite-convert' ' --title=\'{0}\' {subdomains}' .format(data['www_domain'], subdomains='--subdomains' - if not data['wpsubdir'] else '')) + if not data['wpsubdir'] else '')): + pass + else: + Log.info(self, "[" + Log.ENDC + Log.FAIL + "Fail" + Log.OKBLUE + "]") + raise SiteError("setup wordpress network failed") + except CommandExecutionError as e: Log.info(self, "[" + Log.ENDC + Log.FAIL + "Fail" + Log.OKBLUE + "]") raise SiteError("setup wordpress network failed") @@ -516,6 +548,8 @@ def installwp_plugin(self, plugin_name, data): except CommandExecutionError as e: raise SiteError("plugin activation failed") + return 1 + def uninstallwp_plugin(self, plugin_name, data): ee_site_webroot = data['webroot'] @@ -821,6 +855,11 @@ def updatewpuserpassword(self, ee_domain, ee_site_webroot): ee_wp_pass = getpass.getpass(prompt="Provide password for " "{0} user: " .format(ee_wp_user)) + + while not ee_wp_pass: + ee_wp_pass = getpass.getpass(prompt="Provide password for " + "{0} user: " + .format(ee_wp_user)) except Exception as e: Log.debug(self, "{0}".format(e)) raise SiteError("failed to read password input ") @@ -923,7 +962,47 @@ def detSitePar(opts): cachelist.append(key) if len(typelist) > 1 or len(cachelist) > 1: - raise RuntimeError("could not determine site and cache type") + if len(cachelist) > 1: + raise RuntimeError("Could not determine cache type.Multiple cache parameter entered") + elif False not in [x in ('php','mysql','html') for x in typelist]: + sitetype = 'mysql' + if not cachelist: + cachetype = 'basic' + else: + cachetype = cachelist[0] + elif False not in [x in ('php','mysql') for x in typelist]: + sitetype = 'mysql' + if not cachelist: + cachetype = 'basic' + else: + cachetype = cachelist[0] + elif False not in [x in ('html','mysql') for x in typelist]: + sitetype = 'mysql' + if not cachelist: + cachetype = 'basic' + else: + cachetype = cachelist[0] + elif False not in [x in ('php','html') for x in typelist]: + sitetype = 'php' + if not cachelist: + cachetype = 'basic' + else: + cachetype = cachelist[0] + elif False not in [x in ('wp','wpsubdir') for x in typelist]: + sitetype = 'wpsubdir' + if not cachelist: + cachetype = 'basic' + else: + cachetype = cachelist[0] + elif False not in [x in ('wp','wpsubdomain') for x in typelist]: + sitetype = 'wpsubdomain' + if not cachelist: + cachetype = 'basic' + else: + cachetype = cachelist[0] + else: + raise RuntimeError("could not determine site and cache type") + else: if not typelist and not cachelist: sitetype = None @@ -946,7 +1025,7 @@ def generate_random(): return ee_random10 -def deleteDB(self, dbname, dbuser, dbhost): +def deleteDB(self, dbname, dbuser, dbhost, exit=True): try: # Check if Database exists try: @@ -979,7 +1058,7 @@ def deleteDB(self, dbname, dbuser, dbhost): Log.debug(self, "drop database failed") Log.info(self, "Database {0} not dropped".format(dbname)) except Exception as e: - Log.error(self, "Error occured while deleting database") + Log.error(self, "Error occured while deleting database", exit) def deleteWebRoot(self, webroot): diff --git a/ee/cli/plugins/stack.py b/ee/cli/plugins/stack.py index f090dc86..59e42360 100644 --- a/ee/cli/plugins/stack.py +++ b/ee/cli/plugins/stack.py @@ -5,7 +5,7 @@ from cement.core import handler, hook from ee.core.variables import EEVariables from ee.core.aptget import EEAptGet from ee.core.download import EEDownload -from ee.core.shellexec import EEShellExec +from ee.core.shellexec import EEShellExec, CommandExecutionError from ee.core.fileutils import EEFileUtils from ee.core.apt_repo import EERepo from ee.core.extract import EEExtract @@ -153,9 +153,14 @@ class EEStackController(CementBaseController): config = configparser.ConfigParser() config.read_string(mysql_config) Log.debug(self, 'Writting configuration into MySQL file') - with open(os.path.expanduser("~")+'/.my.cnf', encoding='utf-8', + conf_path = "/etc/mysql/conf.d/my.cnf" + os.makedirs(os.path.dirname(conf_path), exist_ok=True) + with open(conf_path, encoding='utf-8', mode='w') as configfile: config.write(configfile) + Log.debug(self, 'Setting my.cnf permission') + EEFileUtils.chmod(self, "/etc/mysql/conf.d/my.cnf", 0o600) + if set(EEVariables.ee_nginx).issubset(set(apt_packages)): Log.info(self, "Adding repository for NGINX, please wait...") diff --git a/ee/cli/plugins/stack_migrate.py b/ee/cli/plugins/stack_migrate.py index e200036b..17a15123 100644 --- a/ee/cli/plugins/stack_migrate.py +++ b/ee/cli/plugins/stack_migrate.py @@ -46,7 +46,11 @@ class EEStackMigrateController(CementBaseController): keyserver="keyserver.ubuntu.com") config = configparser.ConfigParser() - config.read(os.path.expanduser("~")+'/.my.cnf') + if os.path.exists('/etc/mysql/conf.d/my.cnf'): + config.read('/etc/mysql/conf.d/my.cnf') + else: + config.read(os.path.expanduser("~")+'/.my.cnf') + try: chars = config['client']['password'] except Exception as e: diff --git a/ee/cli/plugins/sync.py b/ee/cli/plugins/sync.py index c260402f..dd89dfed 100644 --- a/ee/cli/plugins/sync.py +++ b/ee/cli/plugins/sync.py @@ -37,6 +37,16 @@ class EESyncController(CementBaseController): ee_site_webroot = site.site_path # Read config files configfiles = glob.glob(ee_site_webroot + '/*-config.php') + + #search for wp-config.php inside htdocs/ + if not configfiles: + Log.debug(self, "Config files not found in {0}/ " + .format(ee_site_webroot)) + if site.site_type != 'mysql': + Log.debug(self, "Searching wp-config.php in {0}/htdocs/ " + .format(ee_site_webroot)) + configfiles = glob.glob(ee_site_webroot + '/htdocs/wp-config.php') + if configfiles: if EEFileUtils.isexist(self, configfiles[0]): ee_db_name = (EEFileUtils.grep(self, configfiles[0], @@ -73,6 +83,9 @@ class EESyncController(CementBaseController): db_user=ee_db_user, db_password=ee_db_pass, db_host=ee_db_host) + else: + Log.debug(self, "Config files not found for {0} " + .format(site.sitename)) def load(app): diff --git a/ee/cli/templates/virtualconf.mustache b/ee/cli/templates/virtualconf.mustache index 71341373..8f9b4746 100644 --- a/ee/cli/templates/virtualconf.mustache +++ b/ee/cli/templates/virtualconf.mustache @@ -36,7 +36,7 @@ server { {{#static}} location / { - try_files $uri $uri/ /index.html; + try_files $uri $uri/ =404; } {{/static}} diff --git a/ee/cli/templates/wpfc-hhvm.mustache b/ee/cli/templates/wpfc-hhvm.mustache index 9de76275..6cce1e0d 100644 --- a/ee/cli/templates/wpfc-hhvm.mustache +++ b/ee/cli/templates/wpfc-hhvm.mustache @@ -33,4 +33,5 @@ location ~ \.php$ { } location ~ /purge(/.*) { fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1"; + access_log off; } diff --git a/ee/cli/templates/wpfc.mustache b/ee/cli/templates/wpfc.mustache index 72b88b8b..81794ec7 100644 --- a/ee/cli/templates/wpfc.mustache +++ b/ee/cli/templates/wpfc.mustache @@ -33,4 +33,5 @@ location ~ \.php$ { } location ~ /purge(/.*) { fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1"; + access_log off; } diff --git a/ee/core/download.py b/ee/core/download.py index c0796658..c47854d0 100644 --- a/ee/core/download.py +++ b/ee/core/download.py @@ -27,7 +27,7 @@ class EEDownload(): + Log.OKBLUE + "]")) except urllib.error.URLError as e: Log.debug(self, "[{err}]".format(err=str(e.reason))) - Log.error(self, "Unable to donwload file, {0}" + Log.error(self, "Unable to download file, {0}" .format(filename)) return False except urllib.error.HTTPError as e: diff --git a/ee/core/logging.py b/ee/core/logging.py index b7acb692..1fcb8da7 100644 --- a/ee/core/logging.py +++ b/ee/core/logging.py @@ -15,13 +15,14 @@ class Log: BOLD = '\033[1m' UNDERLINE = '\033[4m' - def error(self, msg): + def error(self, msg, exit=True): """ Logs error into log file """ print(Log.FAIL + msg + Log.ENDC) self.app.log.error(Log.FAIL + msg + Log.ENDC) - self.app.close(1) + if exit: + self.app.close(1) def info(self, msg, end='\n', log=True): """ diff --git a/ee/core/mysql.py b/ee/core/mysql.py index acea0505..ac87b7bb 100644 --- a/ee/core/mysql.py +++ b/ee/core/mysql.py @@ -30,7 +30,10 @@ class EEMysql(): def connect(self): """Makes connection with MySQL server""" try: - connection = pymysql.connect(read_default_file='~/.my.cnf') + if os.path.exists('/etc/mysql/conf.d/my.cnf'): + connection = pymysql.connect(read_default_file='/etc/mysql/conf.d/my.cnf') + else: + connection = pymysql.connect(read_default_file='~/.my.cnf') return connection except ValueError as e: Log.debug(self, str(e)) @@ -41,8 +44,11 @@ class EEMysql(): def dbConnection(self, db_name): try: - connection = pymysql.connect(db=db_name, - read_default_file='~/.my.cnf') + if os.path.exists('/etc/mysql/conf.d/my.cnf'): + connection = pymysql.connect(db=db_name,read_default_file='/etc/mysql/conf.d/my.cnf') + else: + connection = pymysql.connect(db=db_name,read_default_file='~/.my.cnf') + return connection except DatabaseError as e: if e.args[1] == '#42000Unknown database \'{0}\''.format(db_name): @@ -52,9 +58,12 @@ class EEMysql(): except pymysql.err.InternalError as e: Log.debug(self, str(e)) raise MySQLConnectionError + except Exception as e : + Log.debug(self, "[Error]Setting up database: \'" + str(e) + "\'") + raise MySQLConnectionError def execute(self, statement, errormsg='', log=True): - """Get login details from ~/.my.cnf & Execute MySQL query""" + """Get login details from /etc/mysql/conf.d/my.cnf & Execute MySQL query""" connection = EEMysql.connect(self) log and Log.debug(self, "Exceuting MySQL Statement : {0}" .format(statement)) @@ -124,4 +133,5 @@ class EEMysql(): return False except MySQLConnectionError as e: Log.debug(self, str(e)) - return False + raise MySQLConnectionError + #return False diff --git a/ee/core/variables.py b/ee/core/variables.py index 91b2896d..35f1249a 100644 --- a/ee/core/variables.py +++ b/ee/core/variables.py @@ -12,7 +12,8 @@ class EEVariables(): """Intialization of core variables""" # EasyEngine version - ee_version = "3.3.4" + ee_version = "3.3.5" + # EasyEngine packages versions ee_wp_cli = "0.19.2" @@ -70,7 +71,10 @@ class EEVariables(): # MySQL hostname ee_mysql_host = "" config = configparser.RawConfigParser() - cnfpath = os.path.expanduser("~")+"/.my.cnf" + if os.path.exists('/etc/mysql/conf.d/my.cnf'): + cnfpath = "/etc/mysql/conf.d/my.cnf" + else: + cnfpath = os.path.expanduser("~")+"/.my.cnf" if [cnfpath] == config.read(cnfpath): try: ee_mysql_host = config.get('client', 'host') diff --git a/install b/install index bb4c9822..4be444a2 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.3.4" +readonly ee_version_new="3.3.5" 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}') @@ -277,6 +277,31 @@ function ee_update() function ee_update_latest() { + #Move ~/.my.cnf to /etc/mysql/conf.d/my.cnf + if [ ! -f /etc/mysql/conf.d/my.cnf ] + then + #create conf.d folder if not exist + if [ ! -d /etc/mysql/conf.d ]; then + mkdir -p /etc/mysql/conf.d + chmod 755 /etc/mysql/conf.d + fi + if [ -d /etc/mysql/conf.d ] + then + if [ -f ~/.my.cnf ] + then + cp ~/.my.cnf /etc/mysql/conf.d/my.cnf &>> /dev/null + chmod 600 /etc/mysql/conf.d/my.cnf + else + if [ -f /root/.my.cnf ] + then + cp /root/.my.cnf /etc/mysql/conf.d/my.cnf &>> /dev/null + chmod 600 /etc/mysql/conf.d/my.cnf + else + ee_lib_echo_fail ".my.cnf cannot be located in your current user or root." + fi + fi + fi + fi ee_lib_echo "Updating Nginx configuration, please wait..." # From version 3.1.10 we are using Suse builder for repository if [ "$ee_distro_version" == "precise" ]; then @@ -476,18 +501,24 @@ if [ -f /usr/local/sbin/easyengine ]; then if [[ $? -ne 0 ]]; then ee_lib_echo "EasyEngine $ee_version_old not found on your system" | tee -ai $ee_install_log ee_lib_echo "Updating your EasyEngine to $ee_version_old for compability" | tee -ai $ee_install_log - wget -q https://raw.githubusercontent.com/rtCamp/easyengine/old-stable/bin/update && bash update | tee -ai $ee_install_log + wget -q https://raw.githubusercontent.com/rtCamp/easyengine/old-stable/bin/update && bash update if [[ $? -ne 0 ]]; then - ee_lib_echo_fail "Unbale to update EasyEngine to $ee_version_old, exit status = " $? + ee_lib_echo_fail "Unable to update EasyEngine to $ee_version_old, exit status = " $? + exit 100 fi fi - ee_install_dep | tee -ai $ee_install_log - ee_sync_db 2&>>1 $EE_INSTALL_LOG - secure_ee_db | tee -ai $EE_INSTALL_LOG - ee_install | tee -ai $ee_install_log - ee_update | tee -ai $ee_install_log - ee_update_latest | tee -ai $ee_install_log - ee_git_init | tee -ai $ee_install_log + read -p "Update EasyEngine to $ee_version_new (y/n): " ee_ans + if [ "$ee_ans" = "y" ] || [ "$ee_ans" = "Y" ]; then + ee_install_dep | tee -ai $ee_install_log + ee_sync_db 2&>>1 $EE_INSTALL_LOG + secure_ee_db | tee -ai $EE_INSTALL_LOG + ee_install | tee -ai $ee_install_log + ee_update | tee -ai $ee_install_log + ee_update_latest | tee -ai $ee_install_log + ee_git_init | tee -ai $ee_install_log + else + ee_lib_error "Not updating EasyEngine to $ee_version_new, exit status = " 1 + fi elif [ ! -f /usr/local/bin/ee ]; then ee_install_dep | tee -ai $ee_install_log ee_install | tee -ai $ee_install_log diff --git a/setup.py b/setup.py index 0c9f2263..f6be8d17 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.3.4', + version='3.3.5', description=long_description, long_description=long_description, classifiers=[],