From 5b654b64b3a8670fd4a29591ab5717a5cd5c59d1 Mon Sep 17 00:00:00 2001 From: VirtuBox Date: Fri, 16 Aug 2019 22:44:47 +0200 Subject: [PATCH] Fix MySQLTuner --- wo/cli/plugins/site_functions.py | 4 -- wo/cli/plugins/stack.py | 75 +++++++++++++++++--------------- wo/cli/plugins/stack_pref.py | 10 +++-- 3 files changed, 46 insertions(+), 43 deletions(-) diff --git a/wo/cli/plugins/site_functions.py b/wo/cli/plugins/site_functions.py index a3d110d..d925c78 100644 --- a/wo/cli/plugins/site_functions.py +++ b/wo/cli/plugins/site_functions.py @@ -840,10 +840,6 @@ def site_package_check(self, stype): Log.debug(self, "Setting apt_packages variable for MySQL") if not WOShellExec.cmd_exec(self, "/usr/bin/mysqladmin ping"): apt_packages = apt_packages + WOVariables.wo_mysql - packages = packages + [["https://raw.githubusercontent.com/" - "major/MySQLTuner-perl/master/" - "mysqltuner.pl", "/usr/bin/mysqltuner", - "MySQLTuner"]] if stype in ['wp', 'wpsubdir', 'wpsubdomain']: Log.debug(self, "Setting packages variable for WP-CLI") diff --git a/wo/cli/plugins/stack.py b/wo/cli/plugins/stack.py index 099ffe6..51905db 100644 --- a/wo/cli/plugins/stack.py +++ b/wo/cli/plugins/stack.py @@ -65,6 +65,8 @@ class WOStackController(CementBaseController): (['--mysqlclient'], dict(help='Install MySQL client for remote MySQL server', action='store_true')), + (['--mysqltuner'], + dict(help='Install MySQLTuner stack', action='store_true')), (['--wpcli'], dict(help='Install WPCLI stack', action='store_true')), (['--phpmyadmin'], @@ -113,7 +115,7 @@ class WOStackController(CementBaseController): (not pargs.phpmyadmin) and (not pargs.composer) and (not pargs.netdata) and (not pargs.dashboard) and (not pargs.fail2ban) and (not pargs.security) - and (not pargs.mysqlclient) and + and (not pargs.mysqlclient) and (not pargs.mysqltuner) and (not pargs.adminer) and (not pargs.utils) and (not pargs.redis) and (not pargs.proftpd) and (not pargs.phpredisadmin) and @@ -146,6 +148,7 @@ class WOStackController(CementBaseController): pargs.netdata = True pargs.dashboard = True pargs.phpredisadmin = True + pargs.mysqltuner = True if pargs.security: pargs.fail2ban = True @@ -212,12 +215,6 @@ class WOStackController(CementBaseController): Log.debug(self, "Setting apt_packages variable for MySQL") if not WOShellExec.cmd_exec(self, "mysqladmin ping"): apt_packages = apt_packages + WOVariables.wo_mysql - packages = packages + [["https://raw." - "githubusercontent.com/" - "major/MySQLTuner-perl" - "/master/mysqltuner.pl", - "/usr/bin/mysqltuner", - "MySQLTuner"]] if pargs.mysqlclient: Log.debug(self, "Setting apt_packages variable " @@ -318,6 +315,15 @@ class WOStackController(CementBaseController): .format(WOVariables.wo_webroot), "Adminer theme"]] + if pargs.mysqltuner: + Log.debug(self, "Setting packages variable for MySQLTuner ") + packages = packages + [["https://raw." + "githubusercontent.com/" + "major/MySQLTuner-perl" + "/master/mysqltuner.pl", + "/usr/bin/mysqltuner", + "MySQLTuner"]] + # Netdata if pargs.netdata: Log.debug(self, "Setting packages variable for Netdata") @@ -436,7 +442,8 @@ class WOStackController(CementBaseController): (not pargs.adminer) and (not pargs.utils) and (not pargs.composer) and (not pargs.netdata) and (not pargs.fail2ban) and (not pargs.proftpd) and - (not pargs.security) and + (not pargs.security) and (not pargs.mysqltuner) and + (not pargs.mysqlclient) and (not pargs.all) and (not pargs.redis) and (not pargs.phpredisadmin)): pargs.web = True @@ -447,6 +454,10 @@ class WOStackController(CementBaseController): pargs.web = True pargs.admin = True pargs.php73 = True + pargs.fail2ban = True + pargs.proftpd = True + pargs.utils = True + pargs.redis = True if pargs.web: pargs.nginx = True @@ -458,6 +469,7 @@ class WOStackController(CementBaseController): pargs.composer = True pargs.utils = True pargs.netdata = True + pargs.mysqltuner = True if os.path.isdir('{0}22222/htdocs' .format(WOVariables.wo_webroot)): packages = packages + ['{0}22222/htdocs/*' @@ -471,9 +483,7 @@ class WOStackController(CementBaseController): if WOAptGet.is_installed(self, 'nginx-custom'): Log.debug(self, "Removing apt_packages variable of Nginx") apt_packages = apt_packages + WOVariables.wo_nginx - else: - Log.error(self, "Cannot Remove! Nginx Stable " - "version not found.") + # PHP 7.2 if pargs.php: Log.debug(self, "Removing apt_packages variable of PHP") @@ -483,8 +493,6 @@ class WOStackController(CementBaseController): WOVariables.wo_php_extra else: apt_packages = apt_packages + WOVariables.wo_php - else: - Log.error(self, "PHP 7.2 not found") # PHP7.3 if pargs.php73: @@ -495,8 +503,6 @@ class WOStackController(CementBaseController): WOVariables.wo_php_extra else: apt_packages = apt_packages + WOVariables.wo_php73 - else: - Log.error(self, "PHP 7.3 not found") # REDIS if pargs.redis: @@ -507,43 +513,39 @@ class WOStackController(CementBaseController): if pargs.mysql: Log.debug(self, "Removing apt_packages variable of MySQL") apt_packages = apt_packages + WOVariables.wo_mysql - packages = packages + ['/usr/bin/mysqltuner'] # fail2ban if pargs.fail2ban: if WOAptGet.is_installed(self, 'fail2ban'): Log.debug(self, "Remove apt_packages variable of Fail2ban") apt_packages = apt_packages + WOVariables.wo_fail2ban - else: - Log.error(self, "Fail2ban not found") # proftpd if pargs.proftpd: if WOAptGet.is_installed(self, 'proftpd-basic'): Log.debug(self, "Remove apt_packages variable for ProFTPd") apt_packages = apt_packages + ["proftpd-basic"] - else: - Log.error(self, "ProFTPd not found") # WPCLI if pargs.wpcli: Log.debug(self, "Removing package variable of WPCLI ") if os.path.isfile('/usr/local/bin/wp'): packages = packages + ['/usr/local/bin/wp'] - else: - Log.warn(self, "WP-CLI is not installed with WordOps") + # PHPMYADMIN if pargs.phpmyadmin: - Log.debug(self, "Removing package variable of phpMyAdmin ") + Log.debug(self, "Removing package of phpMyAdmin ") packages = packages + ['{0}22222/htdocs/db/pma' .format(WOVariables.wo_webroot)] # Composer if pargs.composer: - Log.debug(self, "Removing package variable of Composer ") + Log.debug(self, "Removing package of Composer ") if os.path.isfile('/usr/local/bin/composer'): packages = packages + ['/usr/local/bin/composer'] - else: - Log.warn(self, "Composer is not installed with WordOps") + + if pargs.mysqltuner: + Log.debug(self, "Removing packages for MySQLTuner ") + packages = packages + [['/usr/bin/mysqltuner']] # PHPREDISADMIN if pargs.phpredisadmin: @@ -632,7 +634,8 @@ class WOStackController(CementBaseController): (not pargs.adminer) and (not pargs.utils) and (not pargs.composer) and (not pargs.netdata) and (not pargs.fail2ban) and (not pargs.proftpd) and - (not pargs.security) and + (not pargs.security) and (not pargs.mysqltuner) and + (not pargs.mysqlclient) and (not pargs.all) and (not pargs.redis) and (not pargs.phpredisadmin)): pargs.web = True @@ -643,6 +646,10 @@ class WOStackController(CementBaseController): pargs.web = True pargs.admin = True pargs.php73 = True + pargs.fail2ban = True + pargs.proftpd = True + pargs.utils = True + pargs.redis = True if pargs.web: pargs.nginx = True @@ -654,6 +661,7 @@ class WOStackController(CementBaseController): pargs.utils = True pargs.composer = True pargs.netdata = True + pargs.mysqltuner = True if os.path.isdir('{0}22222/htdocs' .format(WOVariables.wo_webroot)): packages = packages + ['{0}22222/htdocs/*' @@ -666,9 +674,6 @@ class WOStackController(CementBaseController): if WOAptGet.is_installed(self, 'nginx-custom'): Log.debug(self, "Purge apt_packages variable of Nginx") apt_packages = apt_packages + WOVariables.wo_nginx - else: - Log.error(self, "Cannot Purge! " - "Nginx Stable version not found.") # PHP if pargs.php: @@ -679,8 +684,6 @@ class WOStackController(CementBaseController): WOVariables.wo_php_extra else: apt_packages = apt_packages + WOVariables.wo_php - else: - Log.error(self, "Cannot Purge PHP 7.2. not found.") # PHP 7.3 if pargs.php73: @@ -709,8 +712,6 @@ class WOStackController(CementBaseController): Log.debug(self, "Purge package variable WPCLI") if os.path.isfile('/usr/local/bin/wp'): packages = packages + ['/usr/local/bin/wp'] - else: - Log.warn(self, "WP-CLI is not installed with WordOps") # PHPMYADMIN if pargs.phpmyadmin: @@ -723,8 +724,10 @@ class WOStackController(CementBaseController): Log.debug(self, "Removing package variable of Composer ") if os.path.isfile('/usr/local/bin/composer'): packages = packages + ['/usr/local/bin/composer'] - else: - Log.warn(self, "Composer is not installed with WordOps") + + if pargs.mysqltuner: + Log.debug(self, "Removing packages for MySQLTuner ") + packages = packages + [['/usr/bin/mysqltuner']] # PHPREDISADMIN if pargs.phpredisadmin: diff --git a/wo/cli/plugins/stack_pref.py b/wo/cli/plugins/stack_pref.py index adccc55..64b1e70 100644 --- a/wo/cli/plugins/stack_pref.py +++ b/wo/cli/plugins/stack_pref.py @@ -160,7 +160,7 @@ def post_pref(self, apt_packages, packages): (data), 'nginx-core.mustache', out=wo_nginx) wo_nginx.close() - if not os.path.isfile('/etc/nginx/conf.d/gzip.conf'): + if not os.path.isfile('/etc/nginx/conf.d/gzip.conf.disabled'): data = dict() Log.debug(self, 'Writting the nginx configuration to ' 'file /etc/nginx/conf.d/gzip.conf') @@ -170,7 +170,7 @@ def post_pref(self, apt_packages, packages): (data), 'gzip.mustache', out=wo_nginx) wo_nginx.close() - if not os.path.isfile('/etc/nginx/conf.d/brotli.conf.disabled'): + if not os.path.isfile('/etc/nginx/conf.d/brotli.conf'): Log.debug(self, 'Writting the nginx configuration to ' 'file /etc/nginx/conf.d/brotli.conf.disabled') wo_nginx = open('/etc/nginx/conf.d/brotli.conf.disabled', @@ -1070,7 +1070,6 @@ def post_pref(self, apt_packages, packages): '/var/lib/mysql/ib_logfile1.bak') WOService.start_service(self, 'mysql') - WOFileUtils.chmod(self, "/usr/bin/mysqltuner", 0o775) WOCron.setcron_weekly(self, 'mysqlcheck -Aos --auto-repair ' '> /dev/null 2>&1', comment='MySQL optimization cronjob ' @@ -1324,6 +1323,11 @@ def post_pref(self, apt_packages, packages): WOVariables.wo_php_user, recursive=True) + if any('/usr/bin/mysqltuner' == x[1] + for x in packages): + Log.debug(self, "CHMOD MySQLTuner in /usr/bin/mysqltuner") + WOFileUtils.chmod(self, "/usr/bin/mysqltuner", 0o775) + # netdata install if any('/var/lib/wo/tmp/kickstart.sh' == x[1] for x in packages):