Exemple #1
0
    def migrate_mariadb(self, ci=False):
        # Backup all database
        WOMysql.backupAll(self, fulldump=True)

        # Remove previous MariaDB repository
        wo_mysql_old_repo = ("deb [arch=amd64,ppc64el] "
                             "http://mariadb.mirrors.ovh.net/MariaDB/repo/"
                             "10.3/{distro} {codename} main".format(
                                 distro=WOVar.wo_distro,
                                 codename=WOVar.wo_platform_codename))
        if WOFileUtils.grepcheck(self, '/etc/apt/sources.list.d/wo-repo.list',
                                 wo_mysql_old_repo):
            WORepo.remove(self, repo_url=wo_mysql_old_repo)
        # Add MariaDB repo
        pre_pref(self, WOVar.wo_mysql)

        # Install MariaDB

        Log.wait(self, "Updating apt-cache          ")
        WOAptGet.update(self)
        Log.valide(self, "Updating apt-cache          ")
        Log.wait(self, "Upgrading MariaDB          ")
        WOAptGet.remove(self, ["mariadb-server"])
        WOAptGet.auto_remove(self)
        WOAptGet.install(self, WOVar.wo_mysql)
        if not ci:
            WOAptGet.dist_upgrade(self)
        WOAptGet.auto_remove(self)
        Log.valide(self, "Upgrading MariaDB          ")
        WOFileUtils.mvfile(self, '/etc/mysql/my.cnf', '/etc/mysql/my.cnf.old')
        WOFileUtils.create_symlink(
            self, ['/etc/mysql/mariadb.cnf', '/etc/mysql/my.cnf'])
        WOShellExec.cmd_exec(self, 'systemctl daemon-reload')
        WOShellExec.cmd_exec(self, 'systemctl enable mariadb')
        post_pref(self, WOVar.wo_mysql, [])
Exemple #2
0
    def migrate_mariadb(self):
        # Backup all database
        WOMysql.backupAll(self)

        # Add MariaDB repo
        Log.info(self, "Adding repository for MariaDB, please wait...")

        mysql_pref = ("Package: *\nPin: origin sfo1.mirrors.digitalocean.com"
                      "\nPin-Priority: 1000\n")
        with open('/etc/apt/preferences.d/'
                  'MariaDB.pref', 'w') as mysql_pref_file:
            mysql_pref_file.write(mysql_pref)

        WORepo.add(self, repo_url=WOVariables.wo_mysql_repo)
        Log.debug(self, 'Adding key for {0}'
                  .format(WOVariables.wo_mysql_repo))
        WORepo.add_key(self, '0xcbcb082a1bb943db',
                       keyserver="keyserver.ubuntu.com")

        config = configparser.ConfigParser()
        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:
            Log.error(self, "Error: process exited with error %s"
                            % e)

        Log.debug(self, "Pre-seeding MariaDB")
        Log.debug(self, "echo \"mariadb-server-10.0 "
                        "mysql-server/root_password "
                        "password \" | "
                        "debconf-set-selections")
        WOShellExec.cmd_exec(self, "echo \"mariadb-server-10.0 "
                                   "mysql-server/root_password "
                                   "password {chars}\" | "
                                   "debconf-set-selections"
                                   .format(chars=chars),
                                   log=False)
        Log.debug(self, "echo \"mariadb-server-10.0 "
                        "mysql-server/root_password_again "
                        "password \" | "
                        "debconf-set-selections")
        WOShellExec.cmd_exec(self, "echo \"mariadb-server-10.0 "
                                   "mysql-server/root_password_again "
                                   "password {chars}\" | "
                                   "debconf-set-selections"
                                   .format(chars=chars),
                                   log=False)

        # Install MariaDB
        apt_packages = WOVariables.wo_mysql

        # If PHP is installed then install php5-mysql
        if WOAptGet.is_installed(self, "php5-fpm"):
            apt_packages = apt_packages + ["php5-mysql"]

        Log.info(self, "Updating apt-cache, hang on...")
        WOAptGet.update(self)
        Log.info(self, "Installing MariaDB, hang on...")
        WOAptGet.remove(self, ["mysql-common", "libmysqlclient18"])
        WOAptGet.auto_remove(self)
        WOAptGet.install(self, apt_packages)
Exemple #3
0
    def purge(self):
        """Start purging of packages"""
        apt_packages = []
        packages = []
        pargs = self.app.pargs
        # Default action for stack purge
        if ((not pargs.web) and (not pargs.admin) and (not pargs.nginx)
                and (not pargs.php) and (not pargs.mysql) and (not pargs.wpcli)
                and (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 (not pargs.mysqltuner)
                and (not pargs.adminer) and (not pargs.utils)
                and (not pargs.redis) and (not pargs.proftpd)
                and (not pargs.extplorer) and (not pargs.clamav)
                and (not pargs.ufw) and (not pargs.phpredisadmin)
                and (not pargs.sendmail) and (not pargs.php73)):
            pargs.web = True
            pargs.admin = True
            pargs.security = True

        if pargs.all:
            pargs.web = True
            pargs.admin = True
            pargs.php73 = True
            pargs.fail2ban = True
            pargs.proftpd = True
            pargs.utils = True
            pargs.redis = True
            packages = packages + ['/var/www/22222/htdocs']

        if pargs.web:
            pargs.nginx = True
            pargs.php = True
            pargs.mysql = True
            pargs.wpcli = True
            pargs.sendmail = True

        if pargs.admin:
            pargs.utils = True
            pargs.composer = True
            pargs.netdata = True
            pargs.mysqltuner = True

        if pargs.security:
            pargs.fail2ban = True
            pargs.clamav = True
            pargs.ufw = True

        # NGINX
        if pargs.nginx:
            if WOAptGet.is_installed(self, 'nginx-custom'):
                Log.debug(self, "Add Nginx to apt_packages list")
                apt_packages = apt_packages + WOVariables.wo_nginx
            else:
                Log.info(self, "Nginx is not installed")

        # PHP
        if pargs.php:
            Log.debug(self, "Add PHP to apt_packages list")
            if WOAptGet.is_installed(self, 'php7.2-fpm'):
                if not (WOAptGet.is_installed(self, 'php7.3-fpm')):
                    apt_packages = apt_packages + WOVariables.wo_php + \
                        WOVariables.wo_php_extra
                else:
                    apt_packages = apt_packages + WOVariables.wo_php

        # PHP 7.3
        if pargs.php73:
            Log.debug(self, "Removing apt_packages variable of PHP 7.3")
            if WOAptGet.is_installed(self, 'php7.3-fpm'):
                if not (WOAptGet.is_installed(self, 'php7.2-fpm')):
                    apt_packages = apt_packages + WOVariables.wo_php73 + \
                        WOVariables.wo_php_extra
                else:
                    apt_packages = apt_packages + WOVariables.wo_php73

        # REDIS
        if pargs.redis:
            if WOAptGet.is_installed(self, 'redis-server'):
                Log.debug(self, "Remove apt_packages variable of Redis")
                apt_packages = apt_packages + ["redis-server"]
            else:
                Log.info(self, "Redis is not installed")

        # MariaDB
        if pargs.mysql:
            if WOAptGet.is_installed(self, 'mariadb-server'):
                Log.debug(self, "Add MySQL to apt_packages list")
                apt_packages = apt_packages + [
                    'mariadb-server', 'mysql-common', 'mariadb-client'
                ]
                packages = packages + ['/etc/mysql', '/var/lib/mysql']
            else:
                Log.info(self, "MariaDB is not installed")

        # mysqlclient
        if pargs.mysqlclient:
            if WOShellExec.cmd_exec(self, "mysqladmin ping"):
                Log.debug(self, "Add MySQL client to apt_packages list")
                apt_packages = apt_packages + WOVariables.wo_mysql_client

        # fail2ban
        if pargs.fail2ban:
            if WOAptGet.is_installed(self, 'fail2ban'):
                Log.debug(self, "Add Fail2ban to apt_packages list")
                apt_packages = apt_packages + WOVariables.wo_fail2ban

        # ClamAV
        if pargs.clamav:
            if WOAptGet.is_installed(self, 'clamav'):
                Log.debug(self, "Add ClamAV to apt_packages list")
                apt_packages = apt_packages + WOVariables.wo_clamav

        # UFW
        if pargs.ufw:
            if WOAptGet.is_installed(self, 'ufw'):
                Log.debug(self, "Add UFW to apt_packages list")
                apt_packages = apt_packages + ["ufw"]

        # sendmail
        if pargs.sendmail:
            if WOAptGet.is_installed(self, 'sendmail'):
                Log.debug(self, "Add sendmail to apt_packages list")
                apt_packages = apt_packages + ["sendmail"]

        # proftpd
        if pargs.proftpd:
            if WOAptGet.is_installed(self, 'proftpd-basic'):
                Log.debug(self, "Add Proftpd to apt_packages list")
                apt_packages = apt_packages + ["proftpd-basic"]

        # WP-CLI
        if pargs.wpcli:
            if os.path.isfile('/usr/local/bin/wp'):
                Log.debug(self, "Purge package variable WPCLI")
                packages = packages + ['/usr/local/bin/wp']

        # PHPMYADMIN
        if pargs.phpmyadmin:
            if os.path.isdir('{0}22222/htdocs/db/pma'.format(
                    WOVariables.wo_webroot)):
                Log.debug(self, "Removing package of phpMyAdmin ")
                packages = packages + [
                    '{0}22222/htdocs/db/pma'.format(WOVariables.wo_webroot)
                ]

        # Composer
        if pargs.composer:
            if os.path.isfile('/usr/local/bin/composer'):
                Log.debug(self, "Removing package variable of Composer ")
                packages = packages + ['/usr/local/bin/composer']

        # MySQLTuner
        if pargs.mysqltuner:
            if os.path.isfile('/usr/bin/mysqltuner'):
                Log.debug(self, "Removing packages for MySQLTuner ")
                packages = packages + ['/usr/bin/mysqltuner']

        # PHPREDISADMIN
        if pargs.phpredisadmin:
            Log.debug(self, "Removing package variable of phpRedisAdmin ")
            if os.path.isdir('{0}22222/htdocs/cache/redis'.format(
                    WOVariables.wo_webroot)):
                packages = packages + [
                    '{0}22222/htdocs/'
                    'cache/redis'.format(WOVariables.wo_webroot)
                ]
        # ADMINER
        if pargs.adminer:
            if os.path.isdir('{0}22222/htdocs/db/adminer'.format(
                    WOVariables.wo_webroot)):
                Log.debug(self, "Removing package variable of Adminer ")
                packages = packages + [
                    '{0}22222/htdocs/db/adminer'.format(WOVariables.wo_webroot)
                ]
        # utils
        if pargs.utils:
            Log.debug(self, "Purge package variable utils")
            packages = packages + [
                '{0}22222/htdocs/php/webgrind/'.format(WOVariables.wo_webroot),
                '{0}22222/htdocs/cache/opcache'.format(
                    WOVariables.wo_webroot), '{0}22222/htdocs/cache/nginx/'
                'clean.php'.format(
                    WOVariables.wo_webroot), '/usr/bin/pt-query-advisor',
                '{0}22222/htdocs/db/anemometer'.format(WOVariables.wo_webroot)
            ]

        if pargs.netdata:
            Log.debug(self, "Removing Netdata")
            if os.path.isfile('/opt/netdata/usr/'
                              'libexec/netdata/netdata-uninstaller.sh'):
                packages = packages + ['/var/lib/wo/tmp/kickstart.sh']

        if pargs.dashboard:
            Log.debug(self, "Removing Wo-Dashboard")
            packages = packages + [
                '{0}22222/htdocs/assets/'.format(WOVariables.wo_webroot),
                '{0}22222/htdocs/index.php'.format(WOVariables.wo_webroot)
            ]

        if (packages) or (apt_packages):
            if (not pargs.force):
                start_purge = input('Are you sure you to want to'
                                    ' purge stacks from this server ?'
                                    '\nPackage configuration and data '
                                    'will not remain'
                                    ' on this server after this operation.\n'
                                    'Purge stacks [y/N]')
                if start_purge != "Y" and start_purge != "y":
                    Log.error(self, "Not starting stack purge")

            if (set(["nginx-custom"]).issubset(set(apt_packages))):
                WOService.stop_service(self, 'nginx')

            if (set(["fail2ban"]).issubset(set(apt_packages))):
                WOService.stop_service(self, 'fail2ban')

            if (set(["mariadb-server"]).issubset(set(apt_packages))):
                if (os.path.isfile('/usr/bin/mysql')
                        and os.path.isdir('/var/lib/mysql')):
                    WOMysql.backupAll(self)
                    WOService.stop_service(self, 'mysql')

            # Netdata uninstaller
            if (set(['/var/lib/wo/tmp/'
                     'kickstart.sh']).issubset(set(packages))):
                if WOVariables.wo_distro == 'Raspbian':
                    WOShellExec.cmd_exec(self, "bash /usr/"
                                         "libexec/netdata/netdata-"
                                         "uninstaller.sh -y -f",
                                         errormsg='',
                                         log=False)
                else:
                    WOShellExec.cmd_exec(
                        self, "bash /opt/netdata/usr/"
                        "libexec/netdata/netdata-"
                        "uninstaller.sh -y -f")

            if (apt_packages):
                Log.wait(self, "Purging APT Packages        ")
                WOAptGet.remove(self, apt_packages, purge=True)
                WOAptGet.auto_remove(self)
                Log.valide(self, "Purging APT Packages        ")

            if (packages):
                Log.wait(self, "Purging Packages            ")
                WOFileUtils.remove(self, packages)
                Log.valide(self, "Purging Packages            ")
            Log.info(self, "Successfully purged packages")
Exemple #4
0
    def remove(self):
        """Start removal of packages"""
        apt_packages = []
        packages = []
        pargs = self.app.pargs
        if ((not pargs.web) and (not pargs.admin) and (not pargs.nginx)
                and (not pargs.php) and (not pargs.mysql) and (not pargs.wpcli)
                and (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 (not pargs.mysqltuner)
                and (not pargs.adminer) and (not pargs.utils)
                and (not pargs.redis) and (not pargs.proftpd)
                and (not pargs.extplorer) and (not pargs.clamav)
                and (not pargs.ufw) and (not pargs.phpredisadmin)
                and (not pargs.sendmail) and (not pargs.php73)):
            pargs.web = True
            pargs.admin = True

        if pargs.all:
            pargs.web = True
            pargs.admin = True
            pargs.php73 = True
            pargs.fail2ban = True
            pargs.proftpd = True
            pargs.utils = True
            pargs.redis = True
            pargs.security = True
            packages = packages + ['/var/www/22222/htdocs']

        if pargs.web:
            pargs.nginx = True
            pargs.php = True
            pargs.mysql = True
            pargs.wpcli = True
            pargs.sendmail = True

        if pargs.admin:
            pargs.composer = True
            pargs.utils = True
            pargs.netdata = True
            pargs.mysqltuner = True

        if pargs.security:
            pargs.fail2ban = True
            pargs.clamav = True
            pargs.ufw = True

        # NGINX
        if pargs.nginx:
            if WOAptGet.is_installed(self, 'nginx-custom'):
                Log.debug(self, "Removing apt_packages variable of Nginx")
                apt_packages = apt_packages + WOVariables.wo_nginx

        # PHP 7.2
        if pargs.php:
            Log.debug(self, "Removing apt_packages variable of PHP")
            if WOAptGet.is_installed(self, 'php7.2-fpm'):
                if not WOAptGet.is_installed(self, 'php7.3-fpm'):
                    apt_packages = apt_packages + WOVariables.wo_php + \
                        WOVariables.wo_php_extra
                else:
                    apt_packages = apt_packages + WOVariables.wo_php

        # PHP7.3
        if pargs.php73:
            Log.debug(self, "Removing apt_packages variable of PHP 7.3")
            if WOAptGet.is_installed(self, 'php7.3-fpm'):
                if not (WOAptGet.is_installed(self, 'php7.2-fpm')):
                    apt_packages = apt_packages + WOVariables.wo_php73 + \
                        WOVariables.wo_php_extra
                else:
                    apt_packages = apt_packages + WOVariables.wo_php73

        # REDIS
        if pargs.redis:
            if WOAptGet.is_installed(self, 'redis-server'):
                Log.debug(self, "Remove apt_packages variable of Redis")
                apt_packages = apt_packages + ["redis-server"]

        # MariaDB
        if pargs.mysql:
            if WOAptGet.is_installed(self, 'mariadb-server'):
                Log.debug(self, "Removing apt_packages variable of MySQL")
                apt_packages = apt_packages + [
                    'mariadb-server', 'mysql-common', 'mariadb-client'
                ]

        # mysqlclient
        if pargs.mysqlclient:
            Log.debug(self, "Removing apt_packages variable "
                      "for MySQL Client")
            if WOShellExec.cmd_exec(self, "mysqladmin ping"):
                apt_packages = apt_packages + WOVariables.wo_mysql_client

        # 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

        # ClamAV
        if pargs.clamav:
            Log.debug(self, "Setting apt_packages variable for ClamAV")
            if WOAptGet.is_installed(self, 'clamav'):
                apt_packages = apt_packages + WOVariables.wo_clamav

        # sendmail
        if pargs.sendmail:
            Log.debug(self, "Setting apt_packages variable for Sendmail")
            if WOAptGet.is_installed(self, 'sendmail'):
                apt_packages = apt_packages + ["sendmail"]

        # 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"]

        # UFW
        if pargs.ufw:
            if WOAptGet.is_installed(self, 'ufw'):
                Log.debug(self, "Remove apt_packages variable for UFW")
                apt_packages = apt_packages + ["ufw"]

        # 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']

        # PHPMYADMIN
        if pargs.phpmyadmin:
            if os.path.isdir('{0}22222/htdocs/db/pma'.format(
                    WOVariables.wo_webroot)):
                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 of Composer ")
            if os.path.isfile('/usr/local/bin/composer'):
                packages = packages + ['/usr/local/bin/composer']

        # MySQLTuner
        if pargs.mysqltuner:
            if os.path.isfile('/usr/bin/mysqltuner'):
                Log.debug(self, "Removing packages for MySQLTuner ")
                packages = packages + ['/usr/bin/mysqltuner']

        # PHPREDISADMIN
        if pargs.phpredisadmin:
            Log.debug(self, "Removing package variable of phpRedisAdmin ")
            if os.path.isdir('{0}22222/htdocs/cache/redis'.format(
                    WOVariables.wo_webroot)):
                packages = packages + [
                    '{0}22222/htdocs/'
                    'cache/redis'.format(WOVariables.wo_webroot)
                ]
        # ADMINER
        if pargs.adminer:
            if os.path.isdir('{0}22222/htdocs/db/adminer'.format(
                    WOVariables.wo_webroot)):
                Log.debug(self, "Removing package variable of Adminer ")
                packages = packages + [
                    '{0}22222/htdocs/db/adminer'.format(WOVariables.wo_webroot)
                ]
        if pargs.utils:
            Log.debug(self, "Removing package variable of utils ")
            packages = packages + [
                '{0}22222/htdocs/php/webgrind/'.format(WOVariables.wo_webroot),
                '{0}22222/htdocs/cache/opcache'.format(
                    WOVariables.wo_webroot), '{0}22222/htdocs/cache/nginx/'
                'clean.php'.format(
                    WOVariables.wo_webroot), '/usr/bin/pt-query-advisor',
                '{0}22222/htdocs/db/anemometer'.format(WOVariables.wo_webroot)
            ]

        if pargs.netdata:
            Log.debug(self, "Removing Netdata")
            if os.path.isfile('/opt/netdata/usr/'
                              'libexec/netdata/netdata-uninstaller.sh'):
                packages = packages + ['/var/lib/wo/tmp/kickstart.sh']

        if pargs.dashboard:
            if (os.path.isfile('{0}22222/htdocs/index.php'.format(
                    WOVariables.wo_webroot))
                    or os.path.isfile('{0}22222/htdocs/index.html'.format(
                        WOVariables.wo_webroot))):
                Log.debug(self, "Removing Wo-Dashboard")
                packages = packages + [
                    '{0}22222/htdocs/assets'.format(WOVariables.wo_webroot),
                    '{0}22222/htdocs/index.php'.format(WOVariables.wo_webroot),
                    '{0}22222/htdocs/index.html'.format(WOVariables.wo_webroot)
                ]

        if (packages) or (apt_packages):
            if (not pargs.force):
                start_remove = input('Are you sure you to want to'
                                     ' remove from server.'
                                     '\nPackage configuration will remain'
                                     ' on server after this operation.\n'
                                     'Remove stacks [y/N]?')
                if start_remove != "Y" and start_remove != "y":
                    Log.error(self, "Not starting stack removal")

            if 'nginx-custom' in apt_packages:
                WOService.stop_service(self, 'nginx')

            if 'mariadb-server' in apt_packages:
                WOMysql.backupAll(self)
                WOService.stop_service(self, 'mysql')

            # Netdata uninstaller
            if (set(['/var/lib/wo/tmp/'
                     'kickstart.sh']).issubset(set(packages))):
                if WOVariables.wo_distro == 'Raspbian':
                    WOShellExec.cmd_exec(
                        self, "bash /usr/"
                        "libexec/netdata/"
                        "netdata-uninstaller.sh -y -f")
                else:
                    WOShellExec.cmd_exec(self, "bash /opt/netdata/usr/"
                                         "libexec/netdata/"
                                         "netdata-uninstaller.sh - y - f",
                                         errormsg='',
                                         log=False)

            if (packages):
                Log.wait(self, "Removing packages           ")
                WOFileUtils.remove(self, packages)
                Log.valide(self, "Removing packages           ")
            if (apt_packages):
                Log.debug(self, "Removing apt_packages")
                Log.wait(self, "Removing APT packages       ")
                WOAptGet.remove(self, apt_packages)
                WOAptGet.auto_remove(self)
                Log.valide(self, "Removing APT packages       ")

            Log.info(self, "Successfully removed packages")
Exemple #5
0
    def debug_mysql(self):
        """Start/Stop MySQL debug"""
        # MySQL start global debug
        if (self.app.pargs.mysql == 'on' and not self.app.pargs.site_name):
            if not WOShellExec.cmd_exec(
                    self, "mysql -e \"show variables like"
                    " \'slow_query_log\';\" | "
                    "grep ON"):
                Log.info(self, "Setting up MySQL slow log")
                WOMysql.execute(self, "set global slow_query_log = " "\'ON\';")
                WOMysql.execute(
                    self, "set global slow_query_log_file = "
                    "\'/var/log/mysql/mysql-slow.log\';")
                WOMysql.execute(self, "set global long_query_time = 2;")
                WOMysql.execute(
                    self, "set global log_queries_not_using"
                    "_indexes = \'ON\';")
            else:
                Log.info(self, "MySQL slow log is already enabled")

            self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']

        # MySQL stop global debug
        elif (self.app.pargs.mysql == 'off' and not self.app.pargs.site_name):
            if WOShellExec.cmd_exec(
                    self, "mysql -e \"show variables like \'"
                    "slow_query_log\';\" | grep ON"):
                Log.info(self, "Disabling MySQL slow log")
                WOMysql.execute(self, "set global slow_query_log = \'OFF\';")
                WOMysql.execute(
                    self, "set global slow_query_log_file = \'"
                    "/var/log/mysql/mysql-slow.log\';")
                WOMysql.execute(self, "set global long_query_time = 10;")
                WOMysql.execute(
                    self, "set global log_queries_not_using_index"
                    "es = \'OFF\';")
                WOShellExec.cmd_exec(
                    self, "crontab -l | sed \'/#WordOps "
                    "start/,/#WordOps end/d\' | crontab -")
            else:
                Log.info(self, "MySQL slow log already disabled")
Exemple #6
0
    def default(self):
        """Default function of log reset"""
        self.msg = []

        if self.app.pargs.php:
            self.app.pargs.nginx = True

        if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
                and (not self.app.pargs.mysql) and (not self.app.pargs.access)
                and (not self.app.pargs.wp) and (not self.app.pargs.site_name)
                and (not self.app.pargs.slow_log_db)):
            self.app.pargs.nginx = True
            self.app.pargs.fpm = True
            self.app.pargs.mysql = True
            self.app.pargs.access = True
            self.app.pargs.slow_log_db = True

        if ((not self.app.pargs.nginx) and (not self.app.pargs.fpm)
                and (not self.app.pargs.mysql) and (not self.app.pargs.access)
                and (not self.app.pargs.wp) and (self.app.pargs.site_name)
                and (not self.app.pargs.slow_log_db)):
            self.app.pargs.nginx = True
            self.app.pargs.wp = True
            self.app.pargs.access = True
            self.app.pargs.mysql = True

        if self.app.pargs.slow_log_db:
            if os.path.isdir("/var/www/22222/htdocs/db/anemometer"):
                Log.info(self, "Resetting MySQL slow_query_log database table")
                WOMysql.execute(
                    self, "TRUNCATE TABLE  "
                    "slow_query_log.global_query_review_history")
                WOMysql.execute(
                    self, "TRUNCATE TABLE "
                    "slow_query_log.global_query_review")

        if self.app.pargs.nginx and (not self.app.pargs.site_name):
            self.msg = self.msg + ["/var/log/nginx/*error.log"]

        if self.app.pargs.access and (not self.app.pargs.site_name):
            self.msg = self.msg + ["/var/log/nginx/*access.log"]

        if self.app.pargs.fpm:
            open('/var/log/php/7.2/slow.log', 'a').close()
            open('/var/log/php7.2-fpm.log', 'a').close()
            self.msg = self.msg + [
                '/var/log/php/7.2/slow.log', '/var/log/php7.2-fpm.log'
            ]
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if WOVar.wo_mysql_host == "localhost":
                if os.path.isfile('/var/log/mysql/mysql-slow.log'):
                    self.msg = self.msg + ['/var/log/mysql/mysql-slow.log']
                else:
                    Log.info(self, "MySQL slow-log not found, skipped")
            else:
                Log.warn(
                    self, "Remote MySQL found, WordOps does not support"
                    "remote MySQL servers or log files")

        if self.app.pargs.site_name:
            webroot = "{0}{1}".format(WOVar.wo_webroot,
                                      self.app.pargs.site_name)

            if not os.path.isdir(webroot):
                Log.error(self, "Site not present, quitting")
            if self.app.pargs.access:
                self.msg = self.msg + [
                    "{0}/{1}/logs/access.log".format(WOVar.wo_webroot,
                                                     self.app.pargs.site_name)
                ]
            if self.app.pargs.nginx:
                self.msg = self.msg + [
                    "{0}/{1}/logs/error.log".format(WOVar.wo_webroot,
                                                    self.app.pargs.site_name)
                ]
            if self.app.pargs.wp:
                if os.path.isdir('{0}/htdocs/wp-content'.format(webroot)):
                    if not os.path.isfile(
                            '{0}/logs/debug.log'.format(webroot)):
                        if not os.path.isfile('{0}/htdocs/wp-content/debug.log'
                                              .format(webroot)):
                            open("{0}/htdocs/wp-content/debug.log".format(
                                webroot),
                                 encoding='utf-8',
                                 mode='a').close()
                            WOShellExec.cmd_exec(
                                self, "chown {1}: {0}/htdocs/"
                                "wp-content/debug.log"
                                "".format(webroot, WOVar.wo_php_user))
                    # create symbolic link for debug log
                    WOFileUtils.create_symlink(self, [
                        "{0}/htdocs/wp-content/"
                        "debug.log".format(webroot),
                        '{0}/logs/debug.log'.format(webroot)
                    ])

                    self.msg = self.msg + [
                        "{0}/{1}/logs/debug.log".format(
                            WOVar.wo_webroot, self.app.pargs.site_name)
                    ]
                else:
                    Log.info(
                        self, "Site is not WordPress site, skipping "
                        "WordPress logs")

        reset_list = []
        for r_list in self.msg:
            reset_list = reset_list + glob.glob(r_list)

        # Clearing content of file
        for r_list in reset_list:
            Log.info(self, "Resetting file {file}".format(file=r_list))
            open(r_list, 'w').close()
Exemple #7
0
    def sync(self):
        """
        1. reads database information from wp/wo-config.php
        2. updates records into wo database accordingly.
        """
        Log.info(self, "Synchronizing wo database, please wait...")
        sites = getAllsites(self)
        if not sites:
            pass
        for site in sites:
            if site.site_type in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
                wo_site_webroot = site.site_path
                # Read config files
                configfiles = glob.glob(wo_site_webroot + '/*-config.php')

                # search for wp-config.php inside htdocs/
                if not configfiles:
                    Log.debug(
                        self, "Config files not found in {0}/ ".format(
                            wo_site_webroot))
                    if site.site_type != 'mysql':
                        Log.debug(
                            self,
                            "Searching wp-config.php in {0}/htdocs/".format(
                                wo_site_webroot))
                        configfiles = glob.glob(wo_site_webroot +
                                                '/htdocs/wp-config.php')

                if configfiles:
                    if WOFileUtils.isexist(self, configfiles[0]):
                        wo_db_name = (WOFileUtils.grep(self, configfiles[0],
                                                       'DB_NAME').split(',')
                                      [1].split(')')[0].strip().replace(
                                          '\'', ''))
                        wo_db_user = (WOFileUtils.grep(self, configfiles[0],
                                                       'DB_USER').split(',')
                                      [1].split(')')[0].strip().replace(
                                          '\'', ''))
                        wo_db_pass = (WOFileUtils.grep(
                            self, configfiles[0],
                            'DB_PASSWORD').split(',')[1].split(')')
                                      [0].strip().replace('\'', ''))
                        wo_db_host = (WOFileUtils.grep(self, configfiles[0],
                                                       'DB_HOST').split(',')
                                      [1].split(')')[0].strip().replace(
                                          '\'', ''))

                        # Check if database really exist
                        try:
                            if not WOMysql.check_db_exists(self, wo_db_name):
                                # Mark it as deleted if not exist
                                wo_db_name = 'deleted'
                                wo_db_user = '******'
                                wo_db_pass = '******'
                        except StatementExcecutionError as e:
                            Log.debug(self, str(e))
                        except Exception as e:
                            Log.debug(self, str(e))

                        if site.db_name != wo_db_name:
                            # update records if any mismatch found
                            Log.debug(
                                self, "Updating wo db record for {0}".format(
                                    site.sitename))
                            updateSiteInfo(self,
                                           site.sitename,
                                           db_name=wo_db_name,
                                           db_user=wo_db_user,
                                           db_password=wo_db_pass,
                                           db_host=wo_db_host)
                else:
                    Log.debug(
                        self, "Config files not found for {0} ".format(
                            site.sitename))