Пример #1
0
    def default(self):
        """default function for info"""
        pargs = self.app.pargs
        if (not pargs.nginx and not pargs.php and not pargs.mysql
                and not pargs.php73 and not pargs.php74 and not pargs.php80
                and not pargs.php81):
            pargs.nginx = True
            pargs.php = True
            pargs.mysql = True
            if WOAptGet.is_installed(self, 'php7.3-fpm'):
                pargs.php73 = True
            if WOAptGet.is_installed(self, 'php7.4-fpm'):
                pargs.php74 = True
            if WOAptGet.is_installed(self, 'php8.0-fpm'):
                pargs.php80 = True
            if WOAptGet.is_installed(self, 'php8.1-fpm'):
                pargs.php81 = True

        if pargs.nginx:
            if ((not WOAptGet.is_installed(self, 'nginx-custom'))
                    and (not os.path.exists('/usr/bin/nginx'))):
                Log.info(self, "Nginx is not installed")
            else:
                self.info_nginx()

        if pargs.php:
            if WOAptGet.is_installed(self, 'php7.2-fpm'):
                self.info_php()
            else:
                Log.info(self, "PHP 7.2 is not installed")

        if pargs.php73:
            if WOAptGet.is_installed(self, 'php7.3-fpm'):
                self.info_php73()
            else:
                Log.info(self, "PHP 7.3 is not installed")

        if pargs.php74:
            if WOAptGet.is_installed(self, 'php7.4-fpm'):
                self.info_php74()
            else:
                Log.info(self, "PHP 7.4 is not installed")

        if pargs.php80:
            if WOAptGet.is_installed(self, 'php8.0-fpm'):
                self.info_php80()
            else:
                Log.info(self, "PHP 8.0 is not installed")

        if pargs.php81:
            if WOAptGet.is_installed(self, 'php8.1-fpm'):
                self.info_php81()
            else:
                Log.info(self, "PHP 8.1 is not installed")

        if pargs.mysql:
            if WOShellExec.cmd_exec(self, "/usr/bin/mysqladmin ping"):
                self.info_mysql()
            else:
                Log.info(self, "MySQL is not installed")
Пример #2
0
    def add(self):
        """Swap addition with WordOps"""
        # Get System RAM and SWAP details
        wo_ram = psutil.virtual_memory().total / (1024 * 1024)
        wo_swap = psutil.swap_memory().total / (1024 * 1024)
        if wo_ram < 512:
            if wo_swap < 1000:
                Log.info(self, "Adding SWAP file, please wait...")

                # Install dphys-swapfile
                WOAptGet.update(self)
                WOAptGet.install(self, ["dphys-swapfile"])
                # Stop service
                WOShellExec.cmd_exec(self, "service dphys-swapfile stop")
                # Remove Default swap created
                WOShellExec.cmd_exec(self, "/sbin/dphys-swapfile uninstall")

                # Modify Swap configuration
                if os.path.isfile("/etc/dphys-swapfile"):
                    WOFileUtils.searchreplace(self, "/etc/dphys-swapfile",
                                              "#CONF_SWAPFILE=/var/swap",
                                              "CONF_SWAPFILE=/wo-swapfile")
                    WOFileUtils.searchreplace(self, "/etc/dphys-swapfile",
                                              "#CONF_MAXSWAP=2048",
                                              "CONF_MAXSWAP=1024")
                    WOFileUtils.searchreplace(self, "/etc/dphys-swapfile",
                                              "#CONF_SWAPSIZE=",
                                              "CONF_SWAPSIZE=1024")
                else:
                    with open("/etc/dphys-swapfile", 'w') as conffile:
                        conffile.write("CONF_SWAPFILE=/wo-swapfile\n"
                                       "CONF_SWAPSIZE=1024\n"
                                       "CONF_MAXSWAP=1024\n")
                # Create swap file
                WOShellExec.cmd_exec(self, "service dphys-swapfile start")
Пример #3
0
    def upgrade_php56(self):
        if WOVariables.wo_platform_distro == "ubuntu":
            if os.path.isfile("/etc/apt/sources.list.d/ondrej-php5-5_6-{0}."
                              "list".format(WOVariables.wo_platform_codename)):
                Log.error(self, "Unable to find PHP 5.5")
        else:
            if not(os.path.isfile(WOVariables.wo_repo_file_path) and
                   WOFileUtils.grep(self, WOVariables.wo_repo_file_path,
                                    "php55")):
                Log.error(self, "Unable to find PHP 5.5")

        Log.info(self, "During PHP update process non nginx-cached"
                 " parts of your site may remain down.")

        # Check prompt
        if (not self.app.pargs.no_prompt):
            start_upgrade = input("Do you want to continue:[y/N]")
            if start_upgrade != "Y" and start_upgrade != "y":
                Log.error(self, "Not starting PHP package update")

        if WOVariables.wo_platform_distro == "ubuntu":
            WORepo.remove(self, ppa="ppa:ondrej/php5")
            WORepo.add(self, ppa=WOVariables.wo_php_repo)

        Log.info(self, "Updating apt-cache, please wait...")
        WOAptGet.update(self)
        Log.info(self, "Installing packages, please wait ...")
        WOAptGet.install(self, WOVariables.wo_php +
                         WOVariables.wo_php_extra)
Пример #4
0
    def default(self):
        """default function for info"""
        if (not self.app.pargs.nginx and not self.app.pargs.php
                and not self.app.pargs.mysql and not self.app.pargs.php73):
            self.app.pargs.nginx = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True
            if WOAptGet.is_installed(self, 'php7.3-fpm'):
                self.app.pargs.php73 = True

        if self.app.pargs.nginx:
            if (WOAptGet.is_installed(self, 'nginx-custom')
                    or WOAptGet.is_installed(self, 'nginx-common')):
                self.info_nginx()
            else:
                Log.error(self, "Nginx is not installed")

        if self.app.pargs.php:
            if WOAptGet.is_installed(self, 'php7.2-fpm'):
                self.info_php()
            else:
                Log.error(self, "PHP 7.2 is not installed")

        if self.app.pargs.php73:
            if WOAptGet.is_installed(self, 'php7.3-fpm'):
                self.info_php73()
            else:
                Log.error(self, "PHP 7.3 is not installed")

        if self.app.pargs.mysql:
            if WOShellExec.cmd_exec(self, "mysqladmin ping"):
                self.info_mysql()
            else:
                Log.error(self, "MySQL is not installed")
Пример #5
0
    def signal_handler(self, signal, frame):
        """Handle Ctrl+c hevent for -i option of debug"""
        self.start = False
        if self.app.pargs.nginx:
            self.app.pargs.nginx = 'off'
            self.debug_nginx()
        if self.app.pargs.php:
            self.app.pargs.php = 'off'
            self.debug_php()
        if self.app.pargs.php73:
            self.app.pargs.php73 = 'off'
            self.debug_php73()
        if self.app.pargs.fpm:
            self.app.pargs.fpm = 'off'
            self.debug_fpm()
        if self.app.pargs.fpm73:
            self.app.pargs.fpm73 = 'off'
            self.debug_fpm73()
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if WOVariables.wo_mysql_host is "localhost":
                self.app.pargs.mysql = 'off'
                self.debug_mysql()
            else:
                Log.warn(
                    self, "Remote MySQL found, WordOps does not support "
                    "debugging remote servers")
        if self.app.pargs.wp:
            self.app.pargs.wp = 'off'
            self.debug_wp()
        if self.app.pargs.rewrite:
            self.app.pargs.rewrite = 'off'
            self.debug_rewrite()

        # Reload Nginx
        if self.trigger_nginx:
            WOService.reload_service(self, 'nginx')

        # Reload PHP
        if self.trigger_php:
            if WOVariables.wo_platform_codename == 'trusty' or WOVariables.wo_platform_codename == 'xenial' or WOVariables.wo_platform_codename == 'bionic':
                if WOAptGet.is_installed(self, 'php7.2-fpm'):
                    WOService.reload_service(self, 'php7.2-fpm')
                if WOAptGet.is_installed(self, 'php7.3-fpm'):
                    WOService.reload_service(self, 'php7.3-fpm')
            else:
                WOService.reload_service(self, 'php7.2-fpm')
        self.app.close(0)
Пример #6
0
 def clean_redis(self):
     """This function clears Redis cache"""
     if (WOAptGet.is_installed(self, "redis-server")):
         Log.info(self, "Cleaning Redis cache")
         WOShellExec.cmd_exec(self, "redis-cli flushall")
     else:
         Log.info(self, "Redis is not installed")
Пример #7
0
    def default(self):
        if ((not self.app.pargs.mariadb)):
            self.app.args.print_help()
        if self.app.pargs.mariadb:
            if WOVariables.wo_mysql_host is not "localhost":
                Log.error(
                    self, "Remote MySQL server in use, skipping local install")

            if WOShellExec.cmd_exec(self, "mysqladmin ping") and (
                    not WOAptGet.is_installed(self, 'mariadb-server')):

                Log.info(
                    self, "If your database size is big, "
                    "migration may take some time.")
                Log.info(
                    self, "During migration non nginx-cached parts of "
                    "your site may remain down")
                start_migrate = input("Type \"mariadb\" to continue:")
                if start_migrate != "mariadb":
                    Log.error(self, "Not starting migration")
                self.migrate_mariadb()
            else:
                Log.error(
                    self, "Your current MySQL is not alive or "
                    "you allready installed MariaDB")
Пример #8
0
 def clean_memcache(self):
     try:
         if (WOAptGet.is_installed(self, "memcached")):
             WOService.restart_service(self, "memcached")
             Log.info(self, "Cleaning MemCache")
         else:
             Log.info(self, "Memcache not installed")
     except Exception as e:
         Log.debug(self, "{0}".format(e))
         Log.error(self, "Unable to restart Memcached", False)
Пример #9
0
    def upgrade_php56(self):
        if WOVariables.wo_platform_distro == "ubuntu":
            if os.path.isfile("/etc/apt/sources.list.d/ondrej-php5-5_6-{0}."
                              "list".format(WOVariables.wo_platform_codename)):
                Log.error(self, "Unable to find PHP 5.5")
        else:
            if not(os.path.isfile(WOVariables.wo_repo_file_path) and
                   WOFileUtils.grep(self, WOVariables.wo_repo_file_path,
                                    "php55")):
                Log.error(self, "Unable to find PHP 5.5")

        Log.info(self, "During PHP update process non nginx-cached"
                 " parts of your site may remain down.")

        # Check prompt
        if (not self.app.pargs.no_prompt):
            start_upgrade = input("Do you want to continue:[y/N]")
            if start_upgrade != "Y" and start_upgrade != "y":
                Log.error(self, "Not starting PHP package update")

        if WOVariables.wo_platform_distro == "ubuntu":
            WORepo.remove(self, ppa="ppa:ondrej/php5")
            WORepo.add(self, ppa=WOVariables.wo_php_repo)
        else:
            WOAptGet.remove(self, ["php5-xdebug"])
            WOFileUtils.searchreplace(self, WOVariables.wo_repo_file_path,
                                      "php55", "php56")

        Log.info(self, "Updating apt-cache, please wait...")
        WOAptGet.update(self)
        Log.info(self, "Installing packages, please wait ...")
        if (WOVariables.wo_platform_codename == 'trusty' or WOVariables.wo_platform_codename == 'xenial' or WOVariables.wo_platform_codename == 'bionic'):
            WOAptGet.install(self, WOVariables.wo_php5_6 + WOVariables.wo_php_extra)
        else:
            WOAptGet.install(self, WOVariables.wo_php)

        if WOVariables.wo_platform_distro == "debian":
            WOShellExec.cmd_exec(self, "pecl install xdebug")

            with open("/etc/php5/mods-available/xdebug.ini",
                      encoding='utf-8', mode='a') as myfile:
                myfile.write(";zend_extension=/usr/lib/php5/20131226/"
                             "xdebug.so\n")

            WOFileUtils.create_symlink(self, ["/etc/php5/mods-available/"
                                       "xdebug.ini", "/etc/php5/fpm/conf.d"
                                                     "/20-xedbug.ini"])

        Log.info(self, "Successfully upgraded from PHP 5.5 to PHP 5.6")
Пример #10
0
    def default(self):

        try:
            Log.info(self, "updating apt-cache, please wait...")
            WOAptGet.update(self)
            Log.info(self, "updating packages, please wait...")
            WOAptGet.dist_upgrade(self)
            Log.info(self, "cleaning-up packages, please wait...")
            WOAptGet.auto_remove(self)
            WOAptGet.auto_clean(self)
        except OSError as e:
            Log.debug(self, str(e))
            Log.error(self, "Package updates failed !")
        except Exception as e:
            Log.debug(self, str(e))
            Log.error(self, "Packages updates failed !")
Пример #11
0
    def default(self):
        """default function for info"""
        if (not self.app.pargs.nginx and not self.app.pargs.php
           and not self.app.pargs.mysql and not self.app.pargs.php7):
            self.app.pargs.nginx = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True
            if WOAptGet.is_installed(self, 'php7.0-fpm'):
                    self.app.pargs.php = True

        if self.app.pargs.nginx:
            if WOAptGet.is_installed(self, 'nginx-custom') or WOAptGet.is_installed(self, 'nginx-common'):
                self.info_nginx()
            else:
                Log.error(self, "Nginx is not installed")

        if self.app.pargs.php:
            if (WOVariables.wo_platform_distro == 'debian' or WOVariables.wo_platform_codename == 'precise'):
                if WOAptGet.is_installed(self, 'php5-fpm'):
                    self.info_php()
                else:
                    Log.error(self, "PHP5 is not installed")
            else:
                if WOAptGet.is_installed(self, 'php5.6-fpm'):
                    self.info_php()
                else:
                    Log.error(self, "PHP5.6 is not installed")

        if self.app.pargs.php7:
            if WOAptGet.is_installed(self, 'php7.0-fpm'):
                self.info_php7()
            else:
                Log.error(self, "PHP 7.0 is not installed")

        if self.app.pargs.mysql:
            if WOShellExec.cmd_exec(self, "mysqladmin ping"):
                self.info_mysql()
            else:
                Log.error(self, "MySQL is not installed")
Пример #12
0
    def install(self, packages=[], apt_packages=[], disp_msg=True):
        """Start installation of packages"""
        self.msg = []
        empty_packages = []
        wo_webroot = "/var/www/"
        pargs = self.app.pargs

        try:
            # Default action for stack installation
            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.fail2ban = True

            if pargs.all:
                pargs.web = True
                pargs.admin = True
                pargs.php73 = True
                pargs.redis = True
                pargs.proftpd = True

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

            if pargs.admin:
                pargs.web = True
                pargs.adminer = True
                pargs.phpmyadmin = True
                pargs.composer = True
                pargs.utils = True
                pargs.netdata = True
                pargs.dashboard = True
                pargs.phpredisadmin = True
                pargs.extplorer = True

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

            # Nginx
            if pargs.nginx:
                Log.debug(self, "Setting apt_packages variable for Nginx")

                if not (WOAptGet.is_installed(self, 'nginx-custom')):
                    if not (WOAptGet.is_installed(self, 'nginx-plus')
                            or WOAptGet.is_installed(self, 'nginx')):
                        apt_packages = apt_packages + WOVariables.wo_nginx
                    else:
                        if WOAptGet.is_installed(self, 'nginx-plus'):
                            Log.info(self, "NGINX PLUS Detected ...")
                            apt = ["nginx-plus"] + WOVariables.wo_nginx
                            self.post_pref(apt, empty_packages)
                        elif WOAptGet.is_installed(self, 'nginx'):
                            Log.info(
                                self, "WordOps detected an already "
                                "installed nginx package."
                                "It may or may not have "
                                "required modules.\n")
                            apt = ["nginx"] + WOVariables.wo_nginx
                            self.post_pref(apt, empty_packages)
                else:
                    Log.debug(self, "Nginx Stable already installed")

            # Redis
            if pargs.redis:
                if not WOAptGet.is_installed(self, 'redis-server'):
                    apt_packages = apt_packages + WOVariables.wo_redis

                else:
                    Log.info(self, "Redis already installed")

            # PHP 7.2
            if pargs.php:
                Log.debug(self, "Setting apt_packages variable for PHP 7.2")
                if not (WOAptGet.is_installed(self, 'php7.2-fpm')):
                    apt_packages = (apt_packages + WOVariables.wo_php +
                                    WOVariables.wo_php_extra)
                else:
                    Log.debug(self, "PHP 7.2 already installed")
                    Log.info(self, "PHP 7.2 already installed")

            # PHP 7.3
            if pargs.php73:
                Log.debug(self, "Setting apt_packages variable for PHP 7.3")
                if not WOAptGet.is_installed(self, 'php7.3-fpm'):
                    apt_packages = (apt_packages + WOVariables.wo_php +
                                    WOVariables.wo_php73 +
                                    WOVariables.wo_php_extra)
                else:
                    Log.debug(self, "PHP 7.3 already installed")
                    Log.info(self, "PHP 7.3 already installed")

            # MariaDB 10.3
            if pargs.mysql:
                pargs.mysqltuner = True
                Log.debug(self, "Setting apt_packages variable for MySQL")
                if not WOShellExec.cmd_exec(self, "mysqladmin ping"):
                    apt_packages = apt_packages + WOVariables.wo_mysql
                else:
                    Log.debug(self, "MySQL already installed and alive")
                    Log.info(self, "MySQL already installed and alive")

            # mysqlclient
            if pargs.mysqlclient:
                Log.debug(self, "Setting apt_packages variable "
                          "for MySQL Client")
                if not WOShellExec.cmd_exec(self, "mysqladmin ping"):
                    apt_packages = apt_packages + WOVariables.wo_mysql_client
                else:
                    Log.debug(self, "MySQL already installed and alive")
                    Log.info(self, "MySQL already installed and alive")

            # WP-CLI
            if pargs.wpcli:
                Log.debug(self, "Setting packages variable for WP-CLI")
                if ((not os.path.isfile("/usr/local/bin/wp"))
                        and (not os.path.isfile("/usr/bin/wp"))):
                    packages = packages + [[
                        "https://github.com/wp-cli/wp-cli/"
                        "releases/download/v{0}/"
                        "wp-cli-{0}.phar"
                        "".format(WOVariables.wo_wp_cli), "/usr/local/bin/wp",
                        "WP-CLI"
                    ]]
                else:
                    Log.debug(self, "WP-CLI is already installed")
                    Log.info(self, "WP-CLI is already installed")

            # fail2ban
            if pargs.fail2ban:
                Log.debug(self, "Setting apt_packages variable for Fail2ban")
                if not WOAptGet.is_installed(self, 'fail2ban'):
                    apt_packages = apt_packages + WOVariables.wo_fail2ban
                else:
                    Log.debug(self, "Fail2ban already installed")
                    Log.info(self, "Fail2ban already installed")

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

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

            # sendmail
            if pargs.sendmail:
                Log.debug(self, "Setting apt_packages variable for Sendmail")
                if (not WOAptGet.is_installed(self, 'sendmail')
                        and not WOAptGet.is_installed(self, 'postfix')):
                    apt_packages = apt_packages + ["sendmail"]
                else:
                    if WOAptGet.is_installed(self, 'sendmail'):
                        Log.debug(self, "Sendmail already installed")
                        Log.info(self, "Sendmail already installed")
                    else:
                        Log.debug(
                            self, "Another mta (Postfix) is already installed")
                        Log.info(self,
                                 "Another mta (Postfix) is already installed")

            # proftpd
            if pargs.proftpd:
                Log.debug(self, "Setting apt_packages variable for ProFTPd")
                if not WOAptGet.is_installed(self, 'proftpd-basic'):
                    apt_packages = apt_packages + ["proftpd-basic"]
                else:
                    Log.debug(self, "ProFTPd already installed")
                    Log.info(self, "ProFTPd already installed")

            # PHPMYADMIN
            if pargs.phpmyadmin:
                pargs.composer = True
                if not os.path.isdir('/var/www/22222/htdocs/db/pma'):
                    Log.debug(self, "Setting packages variable "
                              "for phpMyAdmin ")
                    packages = packages + [[
                        "https://github.com/phpmyadmin/"
                        "phpmyadmin/archive/STABLE.tar.gz",
                        "/var/lib/wo/tmp/pma.tar.gz", "phpMyAdmin"
                    ]]
                else:
                    Log.debug(self, "phpMyAdmin already installed")
                    Log.info(self, "phpMyAdmin already installed")

                    # PHPREDISADMIN
            if pargs.phpredisadmin:
                pargs.composer = True
                if not os.path.isdir('/var/www/22222/htdocs/'
                                     'cache/redis/phpRedisAdmin'):
                    Log.debug(self,
                              "Setting packages variable for phpRedisAdmin")
                    packages = packages + [[
                        "https://github.com/"
                        "erikdubbelboer/"
                        "phpRedisAdmin/archive"
                        "/v1.11.3.tar.gz", "/var/lib/wo/tmp/pra.tar.gz",
                        "phpRedisAdmin"
                    ]]
                else:
                    Log.debug(self, "phpRedisAdmin already installed")
                    Log.info(self, "phpRedisAdmin already installed")

            # Composer
            if pargs.composer:
                if ((not WOAptGet.is_installed(self, 'php7.2-fpm'))
                        and (not WOAptGet.is_installed(self, 'php7.3-fpm'))):
                    pargs.php = True
                if not os.path.isfile('/usr/local/bin/composer'):
                    Log.debug(self, "Setting packages variable for Composer ")
                    packages = packages + [[
                        "https://getcomposer.org/"
                        "installer", "/var/lib/wo/tmp/composer-install",
                        "Composer"
                    ]]
                else:
                    Log.debug(self, "Composer already installed")
                    Log.info(self, "Composer already installed")

            # ADMINER
            if pargs.adminer:
                if not os.path.isfile("{0}22222/htdocs/db/"
                                      "adminer/index.php".format(wo_webroot)):
                    Log.debug(self, "Setting packages variable for Adminer ")
                    packages = packages + [
                        [
                            "https://github.com/vrana/adminer/"
                            "releases/download/v{0}"
                            "/adminer-{0}.php".format(WOVariables.wo_adminer),
                            "{0}22222/"
                            "htdocs/db/adminer/index.php".format(
                                WOVariables.wo_webroot), "Adminer"
                        ],
                        [
                            "https://raw.githubusercontent.com"
                            "/vrana/adminer/master/designs/"
                            "pepa-linha/adminer.css", "{0}22222/"
                            "htdocs/db/adminer/adminer.css".format(
                                WOVariables.wo_webroot), "Adminer theme"
                        ]
                    ]
                else:
                    Log.debug(self, "Adminer already installed")
                    Log.info(self, "Adminer already installed")

            # mysqltuner
            if pargs.mysqltuner:
                if not os.path.isfile("/usr/bin/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"
                    ]]
                else:
                    Log.debug(self, "MySQLtuner already installed")
                    Log.info(self, "MySQLtuner already installed")

            # Netdata
            if pargs.netdata:
                if (not os.path.isdir('/opt/netdata')
                        and not os.path.isdir("/etc/netdata")):
                    Log.debug(self, "Setting packages variable for Netdata")
                    if WOVariables.wo_distro == 'raspbian':
                        packages = packages + [[
                            'https://my-netdata.io/'
                            'kickstart.sh', '/var/lib/wo/tmp/kickstart.sh',
                            'Netdata'
                        ]]
                    else:
                        packages = packages + [[
                            'https://my-netdata.io/'
                            'kickstart-static64.sh',
                            '/var/lib/wo/tmp/kickstart.sh', 'Netdata'
                        ]]
                else:
                    Log.debug(self, "Netdata already installed")
                    Log.info(self, "Netdata already installed")

            # WordOps Dashboard
            if pargs.dashboard:
                if not os.path.isfile('/var/www/22222/htdocs/index.php'):
                    Log.debug(self,
                              "Setting packages variable for WO-Dashboard")
                    packages = \
                        packages + [["https://github.com/WordOps"
                                     "/wordops-dashboard/"
                                     "releases/download/v{0}/"
                                     "wordops-dashboard.tar.gz"
                                     .format(WOVariables.wo_dashboard),
                                     "/var/lib/wo/tmp/wo-dashboard.tar.gz",
                                     "WordOps Dashboard"]]
                else:
                    Log.debug(self, "WordOps dashboard already installed")
                    Log.info(self, "WordOps dashboard already installed")

            # eXtplorer
            if pargs.extplorer:
                if not os.path.isdir('/var/www/22222/htdocs/files'):
                    Log.debug(self, "Setting packages variable for eXtplorer")
                    packages = packages + \
                        [["https://github.com/soerennb/"
                          "extplorer/archive/v{0}.tar.gz"
                          .format(WOVariables.wo_extplorer),
                          "/var/lib/wo/tmp/extplorer.tar.gz",
                          "eXtplorer"]]
                else:
                    Log.debug(self, "eXtplorer is already installed")
                    Log.info(self, "eXtplorer is already installed")

            # UTILS
            if pargs.utils:
                Log.debug(self, "Setting packages variable for utils")
                packages = packages + [
                    [
                        "https://raw.githubusercontent.com"
                        "/rtCamp/eeadmin/master/cache/nginx/"
                        "clean.php", "{0}22222/htdocs/cache/"
                        "nginx/clean.php".format(WOVariables.wo_webroot),
                        "clean.php"
                    ],
                    [
                        "https://raw.github.com/rlerdorf/"
                        "opcache-status/master/opcache.php",
                        "{0}22222/htdocs/cache/"
                        "opcache/opcache.php".format(
                            WOVariables.wo_webroot), "opcache.php"
                    ],
                    [
                        "https://raw.github.com/amnuts/"
                        "opcache-gui/master/index.php", "{0}22222/htdocs/"
                        "cache/opcache/opgui.php".format(
                            WOVariables.wo_webroot), "Opgui"
                    ],
                    [
                        "https://raw.githubusercontent.com/"
                        "mlazarov/ocp/master/ocp.php", "{0}22222/htdocs/cache/"
                        "opcache/ocp.php".format(WOVariables.wo_webroot),
                        "OCP.php"
                    ],
                    [
                        "https://github.com/jokkedk/webgrind/"
                        "archive/master.tar.gz",
                        '/var/lib/wo/tmp/webgrind.tar.gz', 'Webgrind'
                    ],
                    [
                        "https://www.percona.com/"
                        "get/pt-query-digest", "/usr/bin/pt-query-advisor",
                        "pt-query-advisor"
                    ],
                    [
                        "https://github.com/box/Anemometer/"
                        "archive/master.tar.gz",
                        '/var/lib/wo/tmp/anemometer.tar.gz', 'Anemometer'
                    ]
                ]

        except Exception as e:
            Log.debug(self, "{0}".format(e))

        if (apt_packages) or (packages):
            if (apt_packages):
                Log.debug(self, "Calling pre_pref")
                pre_pref(self, apt_packages)
                # meminfo = (os.popen('/bin/cat /proc/meminfo '
                #                    '| grep MemTotal').read()).split(":")
                # memsplit = re.split(" kB", meminfo[1])
                # wo_mem = int(memsplit[0])
                # if (wo_mem < 4000000):
                #    WOSwap.add(self)
                Log.wait(self, "Updating apt-cache          ")
                WOAptGet.update(self)
                Log.valide(self, "Updating apt-cache          ")
                Log.wait(self, "Installing APT packages     ")
                WOAptGet.install(self, apt_packages)
                Log.valide(self, "Installing APT packages     ")
                Log.wait(self, "Configuring APT packages    ")
                post_pref(self, apt_packages, [])
                Log.valide(self, "Configuring APT packages    ")
            if (packages):
                Log.debug(self, "Downloading following: {0}".format(packages))
                WODownload.download(self, packages)
                Log.debug(self, "Calling post_pref")
                Log.wait(self, "Configuring packages")
                post_pref(self, [], packages)
                Log.valide(self, "Configuring packages")

            if disp_msg:
                if (self.msg):
                    for msg in self.msg:
                        Log.info(self, Log.ENDC + msg)
                Log.info(self, "Successfully installed packages")
            else:
                return self.msg
Пример #13
0
    def default(self):
        # All package update
        apt_packages = []
        packages = []

        if ((not self.app.pargs.web) and (not self.app.pargs.nginx) and
            (not self.app.pargs.php) and (not self.app.pargs.mysql) and
            (not self.app.pargs.all) and (not self.app.pargs.wpcli) and
            (not self.app.pargs.netdata) and (not self.app.pargs.composer) and
            (not self.app.pargs.phpmyadmin) and
                (not self.app.pargs.redis)):
            self.app.pargs.web = True

        if self.app.pargs.all:
            self.app.pargs.web = True

        if self.app.pargs.web:
            if WOAptGet.is_installed(self, 'nginx-custom'):
                self.app.pargs.nginx = True
            else:
                Log.info(self, "Nginx is not already installed")
            self.app.pargs.php = True
            self.app.pargs.mysql = True
            self.app.pargs.wpcli = True
            self.app.pargs.netdata = True

        if self.app.pargs.nginx:
            if WOAptGet.is_installed(self, 'nginx-custom'):
                apt_packages = apt_packages + WOVariables.wo_nginx
            else:
                Log.info(self, "Nginx Stable is not already installed")

        if self.app.pargs.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
            else:
                Log.info(self, "PHP 7.2 is not installed")

        if self.app.pargs.mysql:
            if WOAptGet.is_installed(self, 'mariadb-server'):
                apt_packages = apt_packages + WOVariables.wo_mysql
            else:
                Log.info(self, "MariaDB is not installed")

        if self.app.pargs.redis:
            if WOAptGet.is_installed(self, 'redis-server'):
                apt_packages = apt_packages + WOVariables.wo_redis
            else:
                Log.info(self, "Redis is not installed")

        if self.app.pargs.wpcli:
            if os.path.isfile('/usr/local/bin/wp'):
                packages = packages + [["https://github.com/wp-cli/wp-cli/"
                                        "releases/download/v{0}/"
                                        "wp-cli-{0}.phar"
                                        "".format(WOVariables.wo_wp_cli),
                                        "/usr/local/bin/wp",
                                        "WP-CLI"]]
            else:
                Log.info(self, "WPCLI is not installed with WordOps")

        if self.app.pargs.netdata:
            if os.path.isdir('/opt/netdata'):
                packages = packages + [['https://my-netdata.io/'
                                        'kickstart-static64.sh',
                                        '/var/lib/wo/tmp/kickstart.sh',
                                        'Netdata']]
        if self.app.pargs.phpmyadmin:
            if os.path.isdir('/var/www/22222/htdocs/db/pma'):
                packages = packages + \
                    [["https://files.phpmyadmin.net"
                      "/phpMyAdmin/{0}/"
                      "phpMyAdmin-{0}-"
                      "all-languages"
                      ".tar.gz".format(WOVariables.wo_phpmyadmin),
                      "/var/lib/wo/tmp/pma.tar.gz",
                      "PHPMyAdmin"]]
            else:
                Log.error(self, "phpMyAdmin isn't installed")

        if self.app.pargs.composer:
            if os.path.isfile('/usr/local/bin/composer'):
                packages = packages + [["https://getcomposer.org/installer",
                                        "/var/lib/wo/tmp/composer-install",
                                        "Composer"]]
            else:
                Log.error(self, "Composer isn't installed")

        if len(packages) or len(apt_packages):

            Log.info(self, "During package update process non nginx-cached"
                     " parts of your site may remain down")
            # Check prompt
            if (not self.app.pargs.no_prompt):
                start_upgrade = input("Do you want to continue:[y/N]")
                if start_upgrade != "Y" and start_upgrade != "y":
                    Log.error(self, "Not starting package update")

            Log.info(self, "Updating packages, please wait...")
            if len(apt_packages):
                # apt-get update
                WOAptGet.update(self)
                # Update packages
                WOAptGet.install(self, apt_packages)

                # Post Actions after package updates
                if (set(WOVariables.wo_nginx).issubset(set(apt_packages))):
                    WOService.restart_service(self, 'nginx')
                if set(WOVariables.wo_php).issubset(set(apt_packages)):
                    WOService.restart_service(self, 'php7.2-fpm')
                if set(WOVariables.wo_mysql).issubset(set(apt_packages)):
                    WOService.restart_service(self, 'mysql')
                if set(WOVariables.wo_redis).issubset(set(apt_packages)):
                    WOService.restart_service(self, 'redis-server')

            if len(packages):
                if self.app.pargs.wpcli:
                    WOFileUtils.remove(self, ['/usr/local/bin/wp'])

                if self.app.pargs.netdata:
                    WOFileUtils.remove(self, ['/var/lib/wo/tmp/kickstart.sh'])

                Log.debug(self, "Downloading following: {0}".format(packages))
                WODownload.download(self, packages)

                if self.app.pargs.wpcli:
                    WOFileUtils.chmod(self, "/usr/local/bin/wp", 0o775)

                if self.app.pargs.netdata:
                    Log.info(self, "Upgrading Netdata, please wait...")
                    WOShellExec.cmd_exec(self, "/bin/bash /var/lib/wo/tmp/"
                                         "kickstart.sh "
                                         "--dont-wait")

                if self.app.pargs.composer:
                    Log.info(self, "Upgrading Composer, please wait...")
                    WOShellExec.cmd_exec(self, "php -q /var/lib/wo"
                                         "/tmp/composer-install "
                                         "--install-dir=/var/lib/wo/tmp/")
                    shutil.copyfile('/var/lib/wo/tmp/composer.phar',
                                    '/usr/local/bin/composer')
                    WOFileUtils.chmod(self, "/usr/local/bin/composer", 0o775)

                if self.app.pargs.phpmyadmin:
                    Log.info(self, "Upgrading phpMyAdmin, please wait...")
                    WOExtract.extract(self, '/var/lib/wo/tmp/pma.tar.gz',
                                      '/var/lib/wo/tmp/')
                    shutil.copyfile(('{0}22222/htdocs/db/pma'
                                     '/config.inc.php'
                                     .format(WOVariables.wo_webroot)),
                                    ('/var/lib/wo/tmp/phpMyAdmin-{0}'
                                     '-all-languages/config.inc.php'
                                     .format(WOVariables.wo_phpmyadmin))
                                    )
                    WOFileUtils.rm(self, '{0}22222/htdocs/db/pma'
                                   .format(WOVariables.wo_webroot))
                    shutil.move('/var/lib/wo/tmp/phpMyAdmin-{0}'
                                '-all-languages/'
                                .format(WOVariables.wo_phpmyadmin),
                                '{0}22222/htdocs/db/pma/'
                                .format(WOVariables.wo_webroot))

            Log.info(self, "Successfully updated packages")
        else:
            self.app.args.print_help()
Пример #14
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")
Пример #15
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")
Пример #16
0
    def reload(self):
        """Reload service"""
        services = []
        pargs = self.app.pargs
        if not (pargs.nginx or pargs.php or
                pargs.php73 or
                pargs.mysql or
                pargs.netdata or
                pargs.proftpd or
                pargs.redis or
                pargs.fail2ban):
            pargs.nginx = True
            pargs.php = True
            pargs.mysql = True
            pargs.fail2ban = True

        if pargs.nginx:
            if (WOAptGet.is_installed(self, 'nginx-custom') or
                    WOAptGet.is_installed(self, 'nginx-mainline')):
                services = services + ['nginx']
            else:
                Log.info(self, "Nginx is not installed")

        if pargs.php:
            if WOAptGet.is_installed(self, 'php7.2-fpm'):
                services = services + ['php7.2-fpm']
            else:
                Log.info(self, "PHP7.2-FPM is not installed")

            if WOAptGet.is_installed(self, 'php7.3-fpm'):
                services = services + ['php7.3-fpm']
            else:
                Log.info(self, "PHP7.3-FPM is not installed")

        if pargs.php73:
            if WOAptGet.is_installed(self, 'php7.3-fpm'):
                services = services + ['php7.3-fpm']
            else:
                Log.info(self, "PHP7.3-FPM is not installed")

        if pargs.mysql:
            if ((WOVariables.wo_mysql_host == "localhost") or
                    (WOVariables.wo_mysql_host == "127.0.0.1")):
                if (WOAptGet.is_installed(self, 'mysql-server') or
                    WOAptGet.is_installed(self, 'percona-server-server-5.6') or
                        WOAptGet.is_installed(self, 'mariadb-server')):
                    services = services + ['mysql']
                else:
                    Log.info(self, "MySQL is not installed")
            else:
                Log.warn(self, "Remote MySQL found, "
                         "Unable to check MySQL service status")

        if pargs.redis:
            if WOAptGet.is_installed(self, 'redis-server'):
                services = services + ['redis-server']
            else:
                Log.info(self, "Redis server is not installed")

        if pargs.fail2ban:
            if WOAptGet.is_installed(self, 'fail2ban'):
                services = services + ['fail2ban']
            else:
                Log.info(self, "fail2ban is not installed")

        # proftpd
        if pargs.proftpd:
            if WOAptGet.is_installed(self, 'proftpd-basic'):
                services = services + ['proftpd']
            else:
                Log.info(self, "ProFTPd is not installed")

        # netdata
        if pargs.netdata:
            if (os.path.isdir("/opt/netdata") or
                    os.path.isdir("/etc/netdata")):
                services = services + ['netdata']
            else:
                Log.info(self, "Netdata is not installed")

        for service in services:
            Log.debug(self, "Reloading service: {0}".format(service))
            WOService.reload_service(self, service)
Пример #17
0
    def stop(self):
        """Stop services"""
        services = []
        if not (self.app.pargs.nginx or self.app.pargs.php
                or self.app.pargs.php73 or self.app.pargs.mysql
                or self.app.pargs.fail2ban or self.app.pargs.netdata
                or self.app.pargs.proftpd or self.app.pargs.redis):
            self.app.pargs.nginx = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True

        # nginx
        if self.app.pargs.nginx:
            if (WOAptGet.is_installed(self, 'nginx-custom')):
                services = services + ['nginx']
            else:
                Log.info(self, "Nginx is not installed")

        # php7.2
        if self.app.pargs.php:
            if WOAptGet.is_installed(self, 'php7.2-fpm'):
                services = services + ['php7.2-fpm']
            else:
                Log.info(self, "PHP7.2-FPM is not installed")

            if WOAptGet.is_installed(self, 'php7.3-fpm'):
                services = services + ['php7.3-fpm']
            else:
                Log.info(self, "PHP7.3-FPM is not installed")

        # php7.3
        if self.app.pargs.php73:
            if WOAptGet.is_installed(self, 'php7.3-fpm'):
                services = services + ['php7.3-fpm']
            else:
                Log.info(self, "PHP7.3-FPM is not installed")

        # mysql
        if self.app.pargs.mysql:
            if ((WOVariables.wo_mysql_host is "localhost")
                    or (WOVariables.wo_mysql_host is "127.0.0.1")):
                if (WOAptGet.is_installed(self, 'mysql-server')
                        or WOAptGet.is_installed(self,
                                                 'percona-server-server-5.6')
                        or WOAptGet.is_installed(self, 'mariadb-server')):
                    services = services + ['mysql']
                else:
                    Log.info(self, "MySQL is not installed")
            else:
                Log.warn(
                    self, "Remote MySQL found, "
                    "Unable to check MySQL service status")

        # redis
        if self.app.pargs.redis:
            if WOAptGet.is_installed(self, 'redis-server'):
                services = services + ['redis-server']
            else:
                Log.info(self, "Redis server is not installed")

        # fail2ban
        if self.app.pargs.fail2ban:
            if WOAptGet.is_installed(self, 'fail2ban'):
                services = services + ['fail2ban']
            else:
                Log.info(self, "fail2ban is not installed")

        # proftpd
        if self.app.pargs.proftpd:
            if WOAptGet.is_installed(self, 'proftpd-basic'):
                services = services + ['proftpd']
            else:
                Log.info(self, "ProFTPd is not installed")

        # netdata
        if self.app.pargs.netdata:
            if os.path.isdir("/opt/netdata"):
                services = services + ['netdata']
            else:
                Log.info(self, "Netdata is not installed")

        for service in services:
            Log.debug(self, "Stopping service: {0}".format(service))
            WOService.stop_service(self, service)
Пример #18
0
    def default(self, disp_msg=False):
        # All package update
        apt_packages = []
        packages = []
        self.msg = []
        pargs = self.app.pargs
        wo_phpmyadmin = WODownload.pma_release(self)
        if not (pargs.web or pargs.nginx or pargs.php or
                pargs.php72 or pargs.php73 or pargs.php74 or pargs.mysql or
                pargs.ngxblocker or pargs.all or pargs.netdata or
                pargs.wpcli or pargs.composer or pargs.phpmyadmin or
                pargs.adminer or pargs.dashboard or pargs.mysqltuner or
                pargs.redis or pargs.fail2ban or pargs.security):
            pargs.web = True
            pargs.admin = True
            pargs.security = True

        if pargs.php:
            pargs.php72 = True

        if pargs.all:
            pargs.web = True
            pargs.admin = True
            pargs.security = True
            pargs.redis = True

        if pargs.web:
            pargs.nginx = True
            pargs.php72 = True
            pargs.php73 = True
            pargs.php74 = True
            pargs.mysql = True
            pargs.wpcli = True

        if pargs.admin:
            pargs.netdata = True
            pargs.composer = True
            pargs.dashboard = True
            pargs.phpmyadmin = True
            pargs.wpcli = True
            pargs.adminer = True
            pargs.mysqltuner = True

        if pargs.security:
            pargs.ngxblocker = True
            pargs.fail2ban = True

        # nginx
        if pargs.nginx:
            if WOAptGet.is_installed(self, 'nginx-custom'):
                apt_packages = apt_packages + WOVar.wo_nginx
            else:
                if os.path.isfile('/usr/sbin/nginx'):
                    Log.info(self, "Updating Nginx templates")
                    post_pref(self, WOVar.wo_nginx, [])
                else:
                    Log.info(self, "Nginx Stable is not already installed")

        # php 7.2
        if pargs.php72:
            if WOAptGet.is_installed(self, 'php7.2-fpm'):
                apt_packages = apt_packages + WOVar.wo_php72 + \
                    WOVar.wo_php_extra

        # php 7.3
        if pargs.php73:
            if WOAptGet.is_installed(self, 'php7.3-fpm'):
                apt_packages = apt_packages + WOVar.wo_php73 + \
                    WOVar.wo_php_extra

        # php 7.4
        if pargs.php74:
            if WOAptGet.is_installed(self, 'php7.4-fpm'):
                apt_packages = apt_packages + WOVar.wo_php74 + \
                    WOVar.wo_php_extra

        # mysql
        if pargs.mysql:
            if WOShellExec.cmd_exec(self, 'mysqladmin ping'):
                apt_packages = apt_packages + ['mariadb-server']

        # redis
        if pargs.redis:
            if WOAptGet.is_installed(self, 'redis-server'):
                apt_packages = apt_packages + ['redis-server']

        # fail2ban
        if pargs.fail2ban:
            if WOAptGet.is_installed(self, 'fail2ban'):
                apt_packages = apt_packages + ['fail2ban']

        # wp-cli
        if pargs.wpcli:
            if os.path.isfile('/usr/local/bin/wp'):
                packages = packages + [[
                    "https://github.com/wp-cli/wp-cli/"
                    "releases/download/v{0}/"
                    "wp-cli-{0}.phar".format(WOVar.wo_wp_cli),
                    "/usr/local/bin/wp",
                    "WP-CLI"]]
            else:
                Log.info(self, "WPCLI is not installed with WordOps")

        # netdata
        if pargs.netdata:
            # detect static binaries install
            if os.path.isdir('/opt/netdata'):
                packages = packages + [[
                    'https://my-netdata.io/kickstart-static64.sh',
                    '/var/lib/wo/tmp/kickstart.sh', 'Netdata']]
            # detect install from source
            elif os.path.isdir('/etc/netdata'):
                packages = packages + [[
                    'https://my-netdata.io/kickstart.sh',
                    '/var/lib/wo/tmp/kickstart.sh', 'Netdata']]
            else:
                Log.info(self, 'Netdata is not installed')

        # wordops dashboard
        if pargs.dashboard:
            if (os.path.isfile('/var/www/22222/htdocs/index.php') or
                    os.path.isfile('/var/www/22222/htdocs/index.html')):
                packages = packages + [[
                    "https://github.com/WordOps/wordops-dashboard/"
                    "releases/download/v{0}/wordops-dashboard.tar.gz"
                    .format(WOVar.wo_dashboard),
                    "/var/lib/wo/tmp/wo-dashboard.tar.gz",
                    "WordOps Dashboard"]]
            else:
                Log.info(self, 'WordOps dashboard is not installed')

        # phpmyadmin
        if pargs.phpmyadmin:
            if os.path.isdir('/var/www/22222/htdocs/db/pma'):
                packages = packages + [[
                    "https://files.phpmyadmin.net"
                    "/phpMyAdmin/{0}/phpMyAdmin-{0}-"
                    "all-languages.tar.gz"
                    .format(wo_phpmyadmin),
                    "/var/lib/wo/tmp/pma.tar.gz",
                    "PHPMyAdmin"]]
            else:
                Log.info(self, "phpMyAdmin isn't installed")

        # adminer
        if pargs.adminer:
            if os.path.isfile("{0}22222/htdocs/db/"
                              "adminer/index.php"
                              .format(WOVar.wo_webroot)):
                Log.debug(self, "Setting packages variable for Adminer ")
                packages = packages + [[
                    "https://www.adminer.org/latest.php",
                    "{0}22222/"
                    "htdocs/db/adminer/index.php"
                    .format(WOVar.wo_webroot),
                    "Adminer"],
                    ["https://raw.githubusercontent.com"
                     "/vrana/adminer/master/designs/"
                     "pepa-linha/adminer.css",
                     "{0}22222/"
                     "htdocs/db/adminer/adminer.css"
                     .format(WOVar.wo_webroot),
                     "Adminer theme"]]
            else:
                Log.debug(self, "Adminer isn't installed")
                Log.info(self, "Adminer isn't installed")

        # composer
        if pargs.composer:
            if os.path.isfile('/usr/local/bin/composer'):
                packages = packages + [[
                    "https://getcomposer.org/installer",
                    "/var/lib/wo/tmp/composer-install",
                    "Composer"]]
            else:
                Log.info(self, "Composer isn't installed")

        # mysqltuner
        if pargs.mysqltuner:
            if WOAptGet.is_exec(self, '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"]]

        # ngxblocker
        if pargs.ngxblocker:
            if os.path.exists('/usr/local/sbin/install-ngxblocker'):
                packages = packages + [[
                    'https://raw.githubusercontent.com/mitchellkrogza/'
                    'nginx-ultimate-bad-bot-blocker/master/update-ngxblocker',
                    '/usr/local/sbin/update-ngxblocker',
                    'ngxblocker'
                ]]

        if ((not (apt_packages)) and (not(packages))):
            self.app.args.print_help()
        else:
            pre_stack(self)
            if (apt_packages):
                if not ("php7.2-fpm" in apt_packages or
                        "php7.3-fpm" in apt_packages or
                        "php7.4-fpm" in apt_packages or
                        "redis-server" in apt_packages or
                        "nginx-custom" in apt_packages or
                        "mariadb-server" in apt_packages):
                    pass
                else:
                    Log.warn(
                        self, "Your sites may be down for few seconds if "
                        "you are upgrading Nginx, PHP-FPM, MariaDB or Redis")
                # Check prompt
                if not (pargs.no_prompt or pargs.force):
                    start_upgrade = input("Do you want to continue:[y/N]")
                    if start_upgrade != "Y" and start_upgrade != "y":
                        Log.error(self, "Not starting package update")
                Log.wait(self, "Updating APT cache")
                # apt-get update
                WOAptGet.update(self)
                Log.valide(self, "Updating APT cache")

                # additional pre_pref
                if "nginx-custom" in apt_packages:
                    pre_pref(self, WOVar.wo_nginx)
                if "php7.2-fpm" in apt_packages:
                    WOAptGet.remove(self, ['php7.2-fpm'],
                                    auto=False, purge=True)
                if "php7.3-fpm" in apt_packages:
                    WOAptGet.remove(self, ['php7.3-fpm'],
                                    auto=False, purge=True)
                if "php7.4-fpm" in apt_packages:
                    WOAptGet.remove(self, ['php7.4-fpm'],
                                    auto=False, purge=True)
                # check if nginx upgrade is blocked
                if os.path.isfile(
                        '/etc/apt/preferences.d/nginx-block'):
                    post_pref(self, WOVar.wo_nginx, [], True)
                # upgrade packages
                WOAptGet.install(self, apt_packages)
                Log.wait(self, "Configuring APT Packages")
                post_pref(self, apt_packages, [], True)
                if "mariadb-server" in apt_packages:
                    WOShellExec.cmd_exec(self, 'mysql_upgrade')
                Log.valide(self, "Configuring APT Packages")
                # Post Actions after package updates

            if (packages):
                if WOAptGet.is_selected(self, 'WP-CLI', packages):
                    WOFileUtils.rm(self, '/usr/local/bin/wp')

                if WOAptGet.is_selected(self, 'Netdata', packages):
                    WOFileUtils.rm(self, '/var/lib/wo/tmp/kickstart.sh')

                if WOAptGet.is_selected(self, 'ngxblocker', packages):
                    WOFileUtils.rm(self, '/usr/local/sbin/update-ngxblocker')

                if WOAptGet.is_selected(self, 'WordOps Dashboard', packages):
                    if os.path.isfile('/var/www/22222/htdocs/index.php'):
                        WOFileUtils.rm(self, '/var/www/22222/htdocs/index.php')
                    if os.path.isfile('/var/www/22222/htdocs/index.html'):
                        WOFileUtils.rm(
                            self, '/var/www/22222/htdocs/index.html')

                Log.debug(self, "Downloading following: {0}".format(packages))
                WODownload.download(self, packages)

                if WOAptGet.is_selected(self, 'WP-CLI', packages):
                    WOFileUtils.chmod(self, "/usr/local/bin/wp", 0o775)

                if WOAptGet.is_selected(self, 'ngxblocker', packages):
                    if os.path.exists('/etc/nginx/conf.d/variables-hash.conf'):
                        WOFileUtils.rm(
                            self, '/etc/nginx/conf.d/variables-hash.conf')
                    WOFileUtils.chmod(
                        self, '/usr/local/sbin/update-ngxblocker', 0o775)
                    WOShellExec.cmd_exec(
                        self, '/usr/local/sbin/update-ngxblocker -nq')

                if WOAptGet.is_selected(self, 'MySQLTuner', packages):
                    WOFileUtils.chmod(self, "/usr/bin/mysqltuner", 0o775)
                    if os.path.exists('/usr/local/bin/mysqltuner'):
                        WOFileUtils.rm(self, '/usr/local/bin/mysqltuner')

                # Netdata
                if WOAptGet.is_selected(self, 'Netdata', packages):
                    WOService.stop_service(self, 'netdata')
                    Log.wait(self, "Upgrading Netdata")
                    # detect static binaries install
                    WOShellExec.cmd_exec(
                        self,
                        "bash /var/lib/wo/tmp/kickstart.sh "
                        "--dont-wait --no-updates",
                        errormsg='', log=False)
                    Log.valide(self, "Upgrading Netdata")

                if WOAptGet.is_selected(self, 'WordOps Dashboard', packages):
                    post_pref(
                        self, [], [["https://github.com/WordOps"
                                    "/wordops-dashboard/"
                                    "releases/download/v{0}/"
                                    "wordops-dashboard.tar.gz"
                                    .format(WOVar.wo_dashboard),
                                    "/var/lib/wo/tmp/wo-dashboard.tar.gz",
                                    "WordOps Dashboard"]])

                if WOAptGet.is_selected(self, 'Composer', packages):
                    Log.wait(self, "Upgrading Composer")
                    if WOShellExec.cmd_exec(
                            self, '/usr/bin/php -v'):
                        WOShellExec.cmd_exec(
                            self, "php -q /var/lib/wo"
                            "/tmp/composer-install "
                            "--install-dir=/var/lib/wo/tmp/")
                    shutil.copyfile('/var/lib/wo/tmp/composer.phar',
                                    '/usr/local/bin/composer')
                    WOFileUtils.chmod(self, "/usr/local/bin/composer", 0o775)
                    Log.valide(self, "Upgrading Composer    ")

                if WOAptGet.is_selected(self, 'PHPMyAdmin', packages):
                    Log.wait(self, "Upgrading phpMyAdmin")
                    WOExtract.extract(self, '/var/lib/wo/tmp/pma.tar.gz',
                                      '/var/lib/wo/tmp/')
                    shutil.copyfile(('{0}22222/htdocs/db/pma'
                                     '/config.inc.php'
                                     .format(WOVar.wo_webroot)),
                                    ('/var/lib/wo/tmp/phpMyAdmin-{0}'
                                     '-all-languages/config.inc.php'
                                     .format(wo_phpmyadmin))
                                    )
                    WOFileUtils.rm(self, '{0}22222/htdocs/db/pma'
                                   .format(WOVar.wo_webroot))
                    shutil.move('/var/lib/wo/tmp/phpMyAdmin-{0}'
                                '-all-languages/'
                                .format(wo_phpmyadmin),
                                '{0}22222/htdocs/db/pma/'
                                .format(WOVar.wo_webroot))
                    WOFileUtils.chown(self, "{0}22222/htdocs"
                                      .format(WOVar.wo_webroot),
                                      'www-data',
                                      'www-data', recursive=True)
                    Log.valide(self, "Upgrading phpMyAdmin")
                if os.path.exists('{0}22222/htdocs'.format(WOVar.wo_webroot)):
                    WOFileUtils.chown(self, "{0}22222/htdocs"
                                      .format(WOVar.wo_webroot),
                                      'www-data',
                                      'www-data', recursive=True)

            Log.info(self, "Successfully updated packages")
Пример #19
0
    def default(self):
        """Default function of debug"""
        # self.start = True
        self.interactive = False
        self.msg = []
        self.trigger_nginx = False
        self.trigger_php = False

        if ((not self.app.pargs.nginx) and (not self.app.pargs.php)
                and (not self.app.pargs.php73) and (not self.app.pargs.fpm)
                and (not self.app.pargs.fpm73) and (not self.app.pargs.mysql)
                and (not self.app.pargs.wp) and (not self.app.pargs.rewrite)
                and (not self.app.pargs.all) and (not self.app.pargs.site_name)
                and (not self.app.pargs.import_slow_log)
                and (not self.app.pargs.interval)):
            if self.app.pargs.stop or self.app.pargs.start:
                print("--start/stop option is deprecated since wo v3.0.5")
                self.app.args.print_help()
            else:
                self.app.args.print_help()

        if self.app.pargs.import_slow_log:
            self.import_slow_log()

        if self.app.pargs.interval:
            try:
                cron_time = int(self.app.pargs.interval)
            except Exception as e:
                Log.debug(self, "{0}".format(e))
                cron_time = 5

            try:
                if not WOShellExec.cmd_exec(
                        self, "crontab -l | grep "
                        "'wo debug --import-slow-log'"):
                    if not cron_time == 0:
                        Log.info(self, "setting up crontab entry,"
                                 " please wait...")
                        WOShellExec.cmd_exec(
                            self, "/bin/bash -c \"crontab -l "
                            "2> /dev/null | {{ cat; echo -e"
                            " \\\"#WordOps start MySQL "
                            "slow log \\n*/{0} * * * * "
                            "/usr/local/bin/wo debug"
                            " --import-slow-log\\n"
                            "#WordOps end MySQL slow log"
                            "\\\"; }} | crontab -\"".format(cron_time))
                else:
                    if not cron_time == 0:
                        Log.info(self, "updating crontab entry,"
                                 " please wait...")
                        if not WOShellExec.cmd_exec(
                                self, "/bin/bash -c "
                                "\"crontab "
                                "-l | sed '/WordOps "
                                "start MySQL slow "
                                "log/!b;n;c\*\/{0} "
                                "\* \* \* "
                                "\* \/usr"
                                "\/local\/bin\/wo debug "
                                "--import\-slow\-log' "
                                "| crontab -\"".format(cron_time)):
                            Log.error(self, "failed to update crontab entry")
                    else:
                        Log.info(self, "removing crontab entry,"
                                 " please wait...")
                        if not WOShellExec.cmd_exec(
                                self, "/bin/bash -c "
                                "\"crontab "
                                "-l | sed '/WordOps "
                                "start MySQL slow "
                                "log/,+2d'"
                                "| crontab -\"".format(cron_time)):
                            Log.error(self, "failed to remove crontab entry")
            except CommandExecutionError as e:
                Log.debug(self, str(e))

        if self.app.pargs.all == 'on':
            if self.app.pargs.site_name:
                self.app.pargs.wp = 'on'
            self.app.pargs.nginx = 'on'
            self.app.pargs.php = 'on'
            self.app.pargs.fpm = 'on'
            if WOAptGet.is_installed(self, 'php7.2-fpm'):
                self.app.pargs.php73 = 'on'
                self.app.pargs.fpm73 = 'on'
            self.app.pargs.mysql = 'on'
            self.app.pargs.rewrite = 'on'

        if self.app.pargs.all == 'off':
            if self.app.pargs.site_name:
                self.app.pargs.wp = 'off'
            self.app.pargs.nginx = 'off'
            self.app.pargs.php = 'off'
            self.app.pargs.fpm = 'off'
            if WOAptGet.is_installed(self, 'php7.2-fpm'):
                self.app.pargs.php73 = 'off'
                self.app.pargs.fpm73 = 'off'
            self.app.pargs.mysql = 'off'
            self.app.pargs.rewrite = 'off'

        if ((not self.app.pargs.nginx) and (not self.app.pargs.php)
                and (not self.app.pargs.php73) and (not self.app.pargs.fpm)
                and (not self.app.pargs.fpm73) and (not self.app.pargs.mysql)
                and (not self.app.pargs.wp) and (not self.app.pargs.rewrite)
                and self.app.pargs.site_name):
            self.app.args.print_help()
            # self.app.pargs.nginx = 'on'
            # self.app.pargs.wp = 'on'
            # self.app.pargs.rewrite = 'on'

        if self.app.pargs.nginx:
            self.debug_nginx()
        if self.app.pargs.php:
            self.debug_php()
        if self.app.pargs.fpm:
            self.debug_fpm()
        if self.app.pargs.php73:
            self.debug_php73()
        if self.app.pargs.fpm73:
            self.debug_fpm73()
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if WOVar.wo_mysql_host == "localhost":
                self.debug_mysql()
            else:
                Log.warn(
                    self, "Remote MySQL found, WordOps does not support "
                    "debugging remote servers")
        if self.app.pargs.wp:
            self.debug_wp()
        if self.app.pargs.rewrite:
            self.debug_rewrite()

        if self.app.pargs.interactive:
            self.interactive = True

        # Reload Nginx
        if self.trigger_nginx:
            WOService.reload_service(self, 'nginx')
        # Reload PHP
        if self.trigger_php:
            if WOAptGet.is_installed(self, 'php7.2-fpm'):
                WOService.restart_service(self, 'php7.2-fpm')
            if WOAptGet.is_installed(self, 'php7.3-fpm'):
                WOService.restart_service(self, 'php7.3-fpm')

        if len(self.msg) > 0:
            if not self.app.pargs.interactive:
                disp_msg = ' '.join(self.msg)
                Log.info(
                    self, "Use following command to check debug logs:\n" +
                    Log.ENDC + "tail -f {0}".format(disp_msg))
            else:
                signal.signal(signal.SIGINT, self.signal_handler)
                watch_list = []
                for w_list in self.msg:
                    watch_list = watch_list + glob.glob(w_list)

                logwatch(self, watch_list)
Пример #20
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, [])
Пример #21
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.cheat) and (not pargs.clamav)
                and (not pargs.phpredisadmin) 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

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

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

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

        # PHP
        if pargs.php:
            Log.debug(self, "Purge apt_packages variable 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

        # 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:
            Log.debug(self, "Remove apt_packages variable of Redis")
            apt_packages = apt_packages + WOVariables.wo_redis

        # MariaDB
        if pargs.mysql:
            Log.debug(self, "Removing apt_packages variable of MySQL")
            apt_packages = apt_packages + WOVariables.wo_mysql

        # 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 + ["clamav"]

        # proftpd
        if pargs.proftpd:
            if WOAptGet.is_installed(self, 'proftpd-basic'):
                Log.debug(self, "Purge apt_packages variable for ProFTPd")
                apt_packages = apt_packages + ["proftpd-basic"]

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

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

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

        if pargs.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:
            Log.debug(self, "Purge  package variable 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-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')

            # 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-"
                        "uninstaller.sh -y -f")
                else:
                    WOShellExec.cmd_exec(
                        self, "bash /opt/netdata/usr/"
                        "libexec/netdata-"
                        "uninstaller.sh -y -f")

            if (apt_packages):
                Log.info(self, "Purging apt packages, please wait...")
                WOAptGet.remove(self, apt_packages, purge=True)
                WOAptGet.auto_remove(self)

            if (packages):
                Log.info(self, "Purging packages, please wait...")
                WOFileUtils.remove(self, packages)
                WOAptGet.auto_remove(self)

            Log.info(self, "Successfully purged packages")
Пример #22
0
    def default(self):
        # All package update
        apt_packages = []
        packages = []
        nginx_packages = []
        empty_packages = []
        pargs = self.app.pargs

        if ((not pargs.web) and (not pargs.nginx) and (not pargs.php)
                and (not pargs.php73) and (not pargs.mysql) and (not pargs.all)
                and (not pargs.wpcli) and (not pargs.netdata)
                and (not pargs.composer) and (not pargs.phpmyadmin)
                and (not pargs.dashboard) and (not pargs.redis)):
            pargs.web = True

        if pargs.all:
            pargs.web = True
            pargs.netdata = True
            pargs.composer = True
            pargs.dashboard = True
            pargs.phpmyadmin = True
            pargs.redis = True
            pargs.wpcli = True
            pargs.php73 = True

        if pargs.web:
            if WOAptGet.is_installed(self, 'nginx-custom'):
                pargs.nginx = True
            else:
                Log.info(self, "Nginx is not already installed")
            pargs.php = True
            pargs.mysql = True
            pargs.wpcli = True

        if pargs.nginx:
            if WOAptGet.is_installed(self, 'nginx-custom'):
                apt_packages = apt_packages + WOVariables.wo_nginx
                nginx_packages = nginx_packages + WOVariables.wo_nginx
            else:
                Log.info(self, "Nginx Stable is not already installed")

        if pargs.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
            else:
                Log.info(self, "PHP 7.2 is not installed")

        if pargs.php73:
            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
            else:
                Log.info(self, "PHP 7.3 is not installed")

        if pargs.mysql:
            if WOAptGet.is_installed(self, 'mariadb-server'):
                apt_packages = apt_packages + WOVariables.wo_mysql
            else:
                Log.info(self, "MariaDB is not installed")

        if pargs.redis:
            if WOAptGet.is_installed(self, 'redis-server'):
                apt_packages = apt_packages + WOVariables.wo_redis
            else:
                Log.info(self, "Redis is not installed")

        if pargs.wpcli:
            if os.path.isfile('/usr/local/bin/wp'):
                packages = packages + [[
                    "https://github.com/wp-cli/wp-cli/"
                    "releases/download/v{0}/"
                    "wp-cli-{0}.phar"
                    "".format(WOVariables.wo_wp_cli), "/usr/local/bin/wp",
                    "WP-CLI"
                ]]
            else:
                Log.info(self, "WPCLI is not installed with WordOps")

        if pargs.netdata:
            if os.path.isdir('/opt/netdata'):
                packages = packages + [[
                    'https://my-netdata.io/'
                    'kickstart-static64.sh', '/var/lib/wo/tmp/kickstart.sh',
                    'Netdata'
                ]]

        if pargs.dashboard:
            if os.path.isfile('/var/www/22222/htdocs/index.php'):
                packages = packages + \
                    [["https://github.com/WordOps/wordops-dashboard/"
                      "releases/download/v{0}/wordops-dashboard.tar.gz"
                      .format(WOVariables.wo_dashboard),
                      "/var/lib/wo/tmp/wo-dashboard.tar.gz",
                      "WordOps Dashboard"]]

        if pargs.phpmyadmin:
            if os.path.isdir('/var/www/22222/htdocs/db/pma'):
                packages = packages + \
                    [["https://files.phpmyadmin.net"
                      "/phpMyAdmin/{0}/"
                      "phpMyAdmin-{0}-"
                      "all-languages"
                      ".tar.gz".format(WOVariables.wo_phpmyadmin),
                      "/var/lib/wo/tmp/pma.tar.gz",
                      "PHPMyAdmin"]]
            else:
                Log.error(self, "phpMyAdmin isn't installed")

        if pargs.composer:
            if os.path.isfile('/usr/local/bin/composer'):
                packages = packages + [[
                    "https://getcomposer.org/installer",
                    "/var/lib/wo/tmp/composer-install", "Composer"
                ]]
            else:
                Log.error(self, "Composer isn't installed")
        if len(apt_packages) or len(packages):
            if len(apt_packages):
                Log.info(
                    self, "Your site may be down for few seconds if "
                    "you are upgrading Nginx, PHP-FPM, MariaDB or Redis")
                # Check prompt
                if ((not pargs.no_prompt) and (not pargs.force)):
                    start_upgrade = input("Do you want to continue:[y/N]")
                    if start_upgrade != "Y" and start_upgrade != "y":
                        Log.error(self, "Not starting package update")
                Log.info(self, "Updating APT packages, please wait...")
                if set(WOVariables.wo_nginx).issubset(set(apt_packages)):
                    pre_pref(self, ["nginx-custom", "nginx-wo"])
                # apt-get update
                WOAptGet.update(self)
                if set(WOVariables.wo_php).issubset(set(apt_packages)):
                    WOAptGet.remove(self, ['php7.2-fpm'],
                                    auto=False,
                                    purge=True)
                if set(WOVariables.wo_php73).issubset(set(apt_packages)):
                    WOAptGet.remove(self, ['php7.3-fpm'],
                                    auto=False,
                                    purge=True)
                # Update packages
                WOAptGet.install(self, apt_packages)
                post_pref(self, apt_packages, empty_packages, True)
                # Post Actions after package updates

            if len(packages):
                if pargs.wpcli:
                    WOFileUtils.rm(self, '/usr/local/bin/wp')

                if pargs.netdata:
                    WOFileUtils.rm(self, '/var/lib/wo/tmp/kickstart.sh')

                if pargs.dashboard:
                    WOFileUtils.rm(self, '/var/www/22222/htdocs/index.php')

                Log.debug(self, "Downloading following: {0}".format(packages))
                WODownload.download(self, packages)

                if pargs.wpcli:
                    WOFileUtils.chmod(self, "/usr/local/bin/wp", 0o775)

                if pargs.netdata:
                    Log.info(self, "Upgrading Netdata, please wait...")
                    WOShellExec.cmd_exec(
                        self, "/bin/bash /var/lib/wo/tmp/"
                        "kickstart.sh "
                        "--dont-wait")

                if pargs.dashboard:
                    Log.debug(
                        self, "Extracting wo-dashboard.tar.gz "
                        "to location {0}22222/htdocs/".format(
                            WOVariables.wo_webroot))
                    WOExtract.extract(
                        self, '/var/lib/wo/tmp/'
                        'wo-dashboard.tar.gz',
                        '{0}22222/htdocs'.format(WOVariables.wo_webroot))
                    WOFileUtils.chown(self,
                                      "{0}22222/htdocs".format(
                                          WOVariables.wo_webroot),
                                      WOVariables.wo_php_user,
                                      WOVariables.wo_php_user,
                                      recursive=True)

                if pargs.composer:
                    Log.info(self, "Upgrading Composer, please wait...")
                    WOShellExec.cmd_exec(
                        self, "php -q /var/lib/wo"
                        "/tmp/composer-install "
                        "--install-dir=/var/lib/wo/tmp/")
                    shutil.copyfile('/var/lib/wo/tmp/composer.phar',
                                    '/usr/local/bin/composer')
                    WOFileUtils.chmod(self, "/usr/local/bin/composer", 0o775)

                if pargs.phpmyadmin:
                    Log.info(self, "Upgrading phpMyAdmin, please wait...")
                    WOExtract.extract(self, '/var/lib/wo/tmp/pma.tar.gz',
                                      '/var/lib/wo/tmp/')
                    shutil.copyfile(
                        ('{0}22222/htdocs/db/pma'
                         '/config.inc.php'.format(WOVariables.wo_webroot)),
                        ('/var/lib/wo/tmp/phpMyAdmin-{0}'
                         '-all-languages/config.inc.php'.format(
                             WOVariables.wo_phpmyadmin)))
                    WOFileUtils.rm(
                        self, '{0}22222/htdocs/db/pma'.format(
                            WOVariables.wo_webroot))
                    shutil.move(
                        '/var/lib/wo/tmp/phpMyAdmin-{0}'
                        '-all-languages/'.format(WOVariables.wo_phpmyadmin),
                        '{0}22222/htdocs/db/pma/'.format(
                            WOVariables.wo_webroot))
                    WOFileUtils.chown(self,
                                      "{0}22222/htdocs".format(
                                          WOVariables.wo_webroot),
                                      WOVariables.wo_php_user,
                                      WOVariables.wo_php_user,
                                      recursive=True)

            Log.info(self, "Successfully updated packages")
        else:
            self.app.args.print_help()
Пример #23
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)
Пример #24
0
    def status(self):
        """Status of services"""
        services = []
        if not (self.app.pargs.nginx or self.app.pargs.php or
                self.app.pargs.php73 or
                self.app.pargs.mysql or
                self.app.pargs.memcached or
                self.app.pargs.redis or
                self.app.pargs.fail2ban):
            self.app.pargs.nginx = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True

        if self.app.pargs.nginx:
            if (WOAptGet.is_installed(self, 'nginx-custom')):
                services = services + ['nginx']
            else:
                Log.info(self, "Nginx is not installed")

        if self.app.pargs.php:
            if WOAptGet.is_installed(self, 'php7.2-fpm'):
                services = services + ['php7.2-fpm']
            else:
                Log.info(self, "PHP7.2-FPM is not installed")

            if WOAptGet.is_installed(self, 'php7.3-fpm'):
                services = services + ['php7.3-fpm']
            else:
                Log.info(self, "PHP7.3-FPM is not installed")

        if self.app.pargs.php73:
            if WOAptGet.is_installed(self, 'php7.3-fpm'):
                services = services + ['php7.3-fpm']
            else:
                Log.info(self, "PHP7.3-FPM is not installed")

        if self.app.pargs.mysql:
            if ((WOVariables.wo_mysql_host is "localhost") or
                    (WOVariables.wo_mysql_host is "127.0.0.1")):
                if (WOAptGet.is_installed(self, 'mysql-server') or
                    WOAptGet.is_installed(self, 'percona-server-server-5.6') or
                        WOAptGet.is_installed(self, 'mariadb-server')):
                    services = services + ['mysql']
                else:
                    Log.info(self, "MySQL is not installed")
            else:
                Log.warn(self, "Remote MySQL found, "
                         "Unable to check MySQL service status")

        if self.app.pargs.memcached:
            if WOAptGet.is_installed(self, 'memcached'):
                services = services + ['memcached']
            else:
                Log.info(self, "Memcached is not installed")

        if self.app.pargs.redis:
            if WOAptGet.is_installed(self, 'redis-server'):
                services = services + ['redis-server']
            else:
                Log.info(self, "Redis server is not installed")

        if self.app.pargs.fail2ban:
            if WOAptGet.is_installed(self, 'fail2ban'):
                services = services + ['fail2ban-client']
            else:
                Log.info(self, "fail2ban is not installed")

        for service in services:
            if WOService.get_service_status(self, service):
                Log.info(self, "{0:10}:  {1}".format(service, "Running"))
Пример #25
0
    def stop(self):
        """Stop services"""
        services = []
        if not (self.app.pargs.nginx or self.app.pargs.php or
                self.app.pargs.php73 or
                self.app.pargs.mysql or
                self.app.pargs.memcached or
                self.app.pargs.redis):
            self.app.pargs.nginx = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True

        if self.app.pargs.nginx:
            if (WOAptGet.is_installed(self, 'nginx-custom')):
                services = services + ['nginx']
            else:
                Log.info(self, "Nginx is not installed")

        if self.app.pargs.php:
            if WOAptGet.is_installed(self, 'php7.2-fpm'):
                services = services + ['php7.2-fpm']
            else:
                Log.info(self, "PHP7.2-FPM is not installed")

            if WOAptGet.is_installed(self, 'php7.3-fpm'):
                services = services + ['php7.3-fpm']
            else:
                Log.info(self, "PHP7.3-FPM is not installed")

        if self.app.pargs.php73:
            if WOAptGet.is_installed(self, 'php7.3-fpm'):
                services = services + ['php7.3-fpm']
            else:
                Log.info(self, "PHP7.3-FPM is not installed")

        if self.app.pargs.mysql:
            if ((WOVariables.wo_mysql_host is "localhost") or
                    (WOVariables.wo_mysql_host is "127.0.0.1")):
                if (WOAptGet.is_installed(self, 'mysql-server') or
                    WOAptGet.is_installed(self, 'percona-server-server-5.6') or
                        WOAptGet.is_installed(self, 'mariadb-server')):
                    services = services + ['mysql']
                else:
                    Log.info(self, "MySQL is not installed")
            else:
                Log.warn(self, "Remote MySQL found, "
                         "Unable to check MySQL service status")

        if self.app.pargs.memcached:
            if WOAptGet.is_installed(self, 'memcached'):
                services = services + ['memcached']
            else:
                Log.info(self, "Memcached is not installed")

        if self.app.pargs.redis:
            if WOAptGet.is_installed(self, 'redis-server'):
                services = services + ['redis-server']
            else:
                Log.info(self, "Redis server is not installed")

        for service in services:
            Log.debug(self, "Stopping service: {0}".format(service))
            WOService.stop_service(self, service)
Пример #26
0
    def default(self, disp_msg=False):
        # All package update
        apt_packages = []
        packages = []
        self.msg = []
        pargs = self.app.pargs

        if ((not pargs.web) and (not pargs.nginx) and
            (not pargs.php) and (not pargs.php73) and
            (not pargs.mysql) and (not pargs.ngxblocker) and
            (not pargs.all) and (not pargs.wpcli) and
            (not pargs.netdata) and (not pargs.composer) and
            (not pargs.phpmyadmin) and (not pargs.dashboard) and
                (not pargs.redis)):
            pargs.web = True
            pargs.admin = True

        if pargs.all:
            pargs.web = True
            pargs.admin = True
            pargs.redis = True
            pargs.php73 = True
            pargs.ngxblocker = True

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

        if pargs.admin:
            pargs.netdata = True
            pargs.composer = True
            pargs.dashboard = True
            pargs.phpmyadmin = True
            pargs.wpcli = True

        # nginx
        if pargs.nginx:
            if WOAptGet.is_installed(self, 'nginx-custom'):
                apt_packages = apt_packages + WOVar.wo_nginx
            else:
                if os.path.isfile('/usr/sbin/nginx'):
                    Log.info(self, "Updating Nginx templates")
                    post_pref(self, WOVar.wo_nginx, [])
                else:
                    Log.info(self, "Nginx Stable is not already installed")

        # php 7.2
        if pargs.php:
            if WOAptGet.is_installed(self, 'php7.2-fpm'):
                apt_packages = apt_packages + WOVar.wo_php + \
                    WOVar.wo_php_extra
            else:
                Log.info(self, "PHP 7.2 is not installed")

        # php 7.3
        if pargs.php73:
            if WOAptGet.is_installed(self, 'php7.3-fpm'):
                apt_packages = apt_packages + WOVar.wo_php73 + \
                    WOVar.wo_php_extra
            else:
                Log.info(self, "PHP 7.3 is not installed")

        # mysql
        if pargs.mysql:
            if WOShellExec.cmd_exec(self, 'mysqladmin ping'):
                apt_packages = apt_packages + ['mariadb-server']
            else:
                Log.info(self, "MariaDB is not installed")

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

        # wp-cli
        if pargs.wpcli:
            if os.path.isfile('/usr/local/bin/wp'):
                packages = packages + [[
                    "https://github.com/wp-cli/wp-cli/"
                    "releases/download/v{0}/"
                    "wp-cli-{0}.phar".format(WOVar.wo_wp_cli),
                    "/usr/local/bin/wp",
                    "WP-CLI"]]
            else:
                Log.info(self, "WPCLI is not installed with WordOps")

        # netdata
        if pargs.netdata:
            # detect static binaries install
            if os.path.isdir('/opt/netdata'):
                packages = packages + [[
                    'https://my-netdata.io/kickstart-static64.sh',
                    '/var/lib/wo/tmp/kickstart.sh', 'Netdata']]
            # detect install from source
            elif os.path.isdir('/etc/netdata'):
                packages = packages + [[
                    'https://my-netdata.io/kickstart.sh',
                    '/var/lib/wo/tmp/kickstart.sh', 'Netdata']]
            else:
                Log.info(self, 'Netdata us not installed')

        # wordops dashboard
        if pargs.dashboard:
            if (os.path.isfile('/var/www/22222/htdocs/index.php') or
                    os.path.isfile('/var/www/22222/htdocs/index.html')):
                packages = packages + [[
                    "https://github.com/WordOps/wordops-dashboard/"
                    "releases/download/v{0}/wordops-dashboard.tar.gz"
                    .format(WOVar.wo_dashboard),
                    "/var/lib/wo/tmp/wo-dashboard.tar.gz",
                    "WordOps Dashboard"]]
            else:
                Log.info(self, 'WordOps dashboard is not installed')

        # phpmyadmin
        if pargs.phpmyadmin:
            if os.path.isdir('/var/www/22222/htdocs/db/pma'):
                packages = packages + [[
                    "https://files.phpmyadmin.net"
                    "/phpMyAdmin/{0}/phpMyAdmin-{0}-"
                    "all-languages.tar.gz"
                    .format(WOVar.wo_phpmyadmin),
                    "/var/lib/wo/tmp/pma.tar.gz",
                    "PHPMyAdmin"]]
            else:
                Log.info(self, "phpMyAdmin isn't installed")

        # composer
        if pargs.composer:
            if os.path.isfile('/usr/local/bin/composer'):
                packages = packages + [[
                    "https://getcomposer.org/installer",
                    "/var/lib/wo/tmp/composer-install",
                    "Composer"]]
            else:
                Log.info(self, "Composer isn't installed")

        # ngxblocker
        if pargs.ngxblocker:
            if os.path.exists('/usr/local/sbin/install-ngxblocker'):
                packages = packages + [[
                    'https://raw.githubusercontent.com/mitchellkrogza/'
                    'nginx-ultimate-bad-bot-blocker/master/update-ngxblocker',
                    '/usr/local/sbin/update-ngxblocker',
                    'ngxblocker'
                ]]
            else:
                Log.info(self, "ngxblocker is not installed")

        if ((not (apt_packages)) and (not(packages))):
            self.app.args.print_help()
        else:
            pre_stack(self)
            if (apt_packages):
                if (("php7.2-fpm" not in apt_packages) and
                        ("php7.3-fpm" not in apt_packages) and
                        ("nginx-custom" not in apt_packages) and
                        ("mariadb-server" not in apt_packages)):
                    pass
                else:
                    Log.info(
                        self, "Your sites may be down for few seconds if "
                        "you are upgrading Nginx, PHP-FPM, MariaDB or Redis")
                # Check prompt
                if ((not pargs.no_prompt) and (not pargs.force)):
                    start_upgrade = input("Do you want to continue:[y/N]")
                    if start_upgrade != "Y" and start_upgrade != "y":
                        Log.error(self, "Not starting package update")
                Log.wait(self, "Updating APT packages")
                # apt-get update
                WOAptGet.update(self)
                Log.valide(self, "Updating APT packages")

                # additional pre_pref
                if "nginx-custom" in apt_packages:
                    pre_pref(self, WOVar.wo_nginx)
                if "php7.2-fpm" in apt_packages:
                    WOAptGet.remove(self, ['php7.2-fpm'],
                                    auto=False, purge=True)
                if "php7.3-fpm" in apt_packages:
                    WOAptGet.remove(self, ['php7.3-fpm'],
                                    auto=False, purge=True)
                # check if nginx upgrade is blocked
                if os.path.isfile(
                        '/etc/apt/preferences.d/nginx-block'):
                    post_pref(self, WOVar.wo_nginx, [], True)
                # upgrade packages
                WOAptGet.install(self, apt_packages)
                Log.wait(self, "Configuring APT Packages")
                post_pref(self, apt_packages, [], True)
                if "mariadb-server" in apt_packages:
                    WOShellExec.cmd_exec(self, 'mysql_upgrade')
                Log.valide(self, "Configuring APT Packages")
                # Post Actions after package updates

            if (packages):
                if pargs.wpcli:
                    WOFileUtils.rm(self, '/usr/local/bin/wp')

                if pargs.netdata:
                    WOFileUtils.rm(self, '/var/lib/wo/tmp/kickstart.sh')

                if pargs.ngxblocker:
                    WOFileUtils.rm(self, '/usr/local/sbin/update-ngxblocker')

                if pargs.dashboard:
                    if os.path.isfile('/var/www/22222/htdocs/index.php'):
                        WOFileUtils.rm(self, '/var/www/22222/htdocs/index.php')
                    if os.path.isfile('/var/www/22222/htdocs/index.html'):
                        WOFileUtils.rm(
                            self, '/var/www/22222/htdocs/index.html')

                Log.debug(self, "Downloading following: {0}".format(packages))
                WODownload.download(self, packages)

                if pargs.wpcli:
                    WOFileUtils.chmod(self, "/usr/local/bin/wp", 0o775)

                if pargs.ngxblocker:
                    WOFileUtils.chmod(
                        self, '/usr/local/sbin/update-ngxblocker', 0o700)
                    WOShellExec.cmd_exec(
                        self, '/usr/local/sbin/update-ngxblocker -nq'
                    )

                # Netdata
                if pargs.netdata:
                    Log.wait(self, "Upgrading Netdata")
                    # detect static binaries install
                    if os.path.isdir('/opt/netdata'):
                        if os.path.exists(
                            '/opt/netdata/usr/libexec/'
                                'netdata/netdata-updater.sh'):
                            WOShellExec.cmd_exec(
                                self, "bash /opt/netdata/usr/"
                                "libexec/netdata/netdata-"
                                "updater.sh")
                        else:
                            WOShellExec.cmd_exec(
                                self, "bash /var/lib/wo/tmp/kickstart.sh")
                    # detect install from source
                    elif os.path.isdir('/etc/netdata'):
                        if os.path.exists(
                                '/usr/libexec/netdata/netdata-updater.sh'):
                            WOShellExec.cmd_exec(
                                self,
                                'bash /usr/libexec/netdata/netdata-updater.sh')
                        else:
                            WOShellExec.cmd_exec(
                                self, "bash /var/lib/wo/tmp/kickstart.sh")
                    Log.valide(self, "Upgrading Netdata")

                if pargs.dashboard:
                    post_pref(
                        self, [], [["https://github.com/WordOps"
                                    "/wordops-dashboard/"
                                    "releases/download/v{0}/"
                                    "wordops-dashboard.tar.gz"
                                    .format(WOVar.wo_dashboard),
                                    "/var/lib/wo/tmp/wo-dashboard.tar.gz",
                                    "WordOps Dashboard"]])

                if pargs.composer:
                    Log.wait(self, "Upgrading Composer")
                    if WOShellExec.cmd_exec(
                            self, '/usr/bin/php -v'):
                        WOShellExec.cmd_exec(
                            self, "php -q /var/lib/wo"
                            "/tmp/composer-install "
                            "--install-dir=/var/lib/wo/tmp/")
                    shutil.copyfile('/var/lib/wo/tmp/composer.phar',
                                    '/usr/local/bin/composer')
                    WOFileUtils.chmod(self, "/usr/local/bin/composer", 0o775)
                    Log.valide(self, "Upgrading Composer    ")

                if pargs.phpmyadmin:
                    Log.wait(self, "Upgrading phpMyAdmin")
                    WOExtract.extract(self, '/var/lib/wo/tmp/pma.tar.gz',
                                      '/var/lib/wo/tmp/')
                    shutil.copyfile(('{0}22222/htdocs/db/pma'
                                     '/config.inc.php'
                                     .format(WOVar.wo_webroot)),
                                    ('/var/lib/wo/tmp/phpMyAdmin-{0}'
                                     '-all-languages/config.inc.php'
                                     .format(WOVar.wo_phpmyadmin))
                                    )
                    WOFileUtils.rm(self, '{0}22222/htdocs/db/pma'
                                   .format(WOVar.wo_webroot))
                    shutil.move('/var/lib/wo/tmp/phpMyAdmin-{0}'
                                '-all-languages/'
                                .format(WOVar.wo_phpmyadmin),
                                '{0}22222/htdocs/db/pma/'
                                .format(WOVar.wo_webroot))
                    WOFileUtils.chown(self, "{0}22222/htdocs"
                                      .format(WOVar.wo_webroot),
                                      'www-data',
                                      'www-data', recursive=True)
                    Log.valide(self, "Upgrading phpMyAdmin")

            Log.info(self, "Successfully updated packages")
Пример #27
0
    def default(self):
        # All package update
        apt_packages = []
        packages = []

        if ((not self.app.pargs.web) and (not self.app.pargs.nginx) and
           (not self.app.pargs.php) and (not self.app.pargs.mysql) and
           (not self.app.pargs.hhvm) and (not self.app.pargs.all) and
           (not self.app.pargs.wpcli) and (not self.app.pargs.redis) and
           (not self.app.pargs.nginxmainline)):
            self.app.pargs.web = True

        if self.app.pargs.all:
            self.app.pargs.web = True

        if self.app.pargs.web:
            if WOAptGet.is_installed(self, 'nginx-custom'):
                self.app.pargs.nginx = True
            else:
                Log.info(self, "Nginx is not already installed")
            self.app.pargs.php = True
            self.app.pargs.mysql = True
            self.app.pargs.wpcli = True

        if self.app.pargs.nginx:
            if WOAptGet.is_installed(self, 'nginx-custom'):
                apt_packages = apt_packages + WOVariables.wo_nginx
            else:
                Log.info(self, "Nginx Stable is not already installed")

        if self.app.pargs.php:
            if WOAptGet.is_installed(self, 'php7.2-fpm'):
                apt_packages = apt_packages + WOVariables.wo_php + WOVariables.wo_php_extra
            else:
                Log.info(self, "PHP 7.2 is not installed")

        if self.app.pargs.hhvm:
            if WOAptGet.is_installed(self, 'hhvm'):
                apt_packages = apt_packages + WOVariables.wo_hhvm
            else:
                Log.info(self, "HHVM is not installed")

        if self.app.pargs.mysql:
            if WOAptGet.is_installed(self, 'mariadb-server'):
                apt_packages = apt_packages + WOVariables.wo_mysql
            else:
                Log.info(self, "MariaDB is not installed")

        if self.app.pargs.redis:
            if WOAptGet.is_installed(self, 'redis-server'):
                apt_packages = apt_packages + WOVariables.wo_redis
            else:
                Log.info(self, "Redis is not installed")

        if self.app.pargs.wpcli:
            if os.path.isfile('/usr/local/bin/wp'):
                packages = packages + [["https://github.com/wp-cli/wp-cli/"
                                        "releases/download/v{0}/"
                                        "wp-cli-{0}.phar"
                                        "".format(WOVariables.wo_wp_cli),
                                        "/usr/local/bin/wp",
                                        "WP-CLI"]]
            else:
                Log.info(self, "WPCLI is not installed with WordOps")

        if len(packages) or len(apt_packages):

            Log.info(self, "During package update process non nginx-cached"
                     " parts of your site may remain down")
            # Check prompt
            if (not self.app.pargs.no_prompt):
                start_upgrade = input("Do you want to continue:[y/N]")
                if start_upgrade != "Y" and start_upgrade != "y":
                    Log.error(self, "Not starting package update")

            Log.info(self, "Updating packages, please wait...")
            if len(apt_packages):
                # apt-get update
                WOAptGet.update(self)
                # Update packages
                WOAptGet.install(self, apt_packages)

                # Post Actions after package updates
                if (set(WOVariables.wo_nginx).issubset(set(apt_packages))):
                    WOService.restart_service(self, 'nginx')
                if set(WOVariables.wo_php).issubset(set(apt_packages)):
                    WOService.restart_service(self, 'php7.2-fpm')
                if set(WOVariables.wo_hhvm).issubset(set(apt_packages)):
                    WOService.restart_service(self, 'hhvm')
                if set(WOVariables.wo_mysql).issubset(set(apt_packages)):
                    WOService.restart_service(self, 'mysql')
                if set(WOVariables.wo_redis).issubset(set(apt_packages)):
                    WOService.restart_service(self, 'redis-server')

            if len(packages):
                if self.app.pargs.wpcli:
                    WOFileUtils.remove(self, ['/usr/local/bin/wp'])

                Log.debug(self, "Downloading following: {0}".format(packages))
                WODownload.download(self, packages)

                if self.app.pargs.wpcli:
                    WOFileUtils.chmod(self, "/usr/local/bin/wp", 0o775)

            Log.info(self, "Successfully updated packages")
        else:
            self.app.args.print_help()
Пример #28
0
    def reload(self):
        """Reload service"""
        services = []
        if not (self.app.pargs.nginx or self.app.pargs.php
                or self.app.pargs.php7 or self.app.pargs.mysql
                or self.app.pargs.hhvm or self.app.pargs.memcache
                or self.app.pargs.redis):
            self.app.pargs.nginx = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True

        if self.app.pargs.nginx:
            if WOAptGet.is_installed(self,
                                     'nginx-custom') or WOAptGet.is_installed(
                                         self, 'nginx-mainline'):
                services = services + ['nginx']
            else:
                Log.info(self, "Nginx is not installed")

        if self.app.pargs.php:
            if (WOVariables.wo_platform_distro == 'debian'
                    or WOVariables.wo_platform_codename == 'precise'):
                if WOAptGet.is_installed(self, 'php5-fpm'):
                    services = services + ['php5-fpm']
                else:
                    Log.info(self, "PHP5-FPM is not installed")
            else:
                if WOAptGet.is_installed(self, 'php5.6-fpm'):
                    services = services + ['php5.6-fpm']
                else:
                    Log.info(self, "PHP5.6-FPM is not installed")

                if WOAptGet.is_installed(self, 'php7.0-fpm'):
                    services = services + ['php7.0-fpm']
                else:
                    Log.info(self, "PHP7.0-FPM is not installed")

        if self.app.pargs.php7:
            if (WOVariables.wo_platform_codename == 'trusty'
                    or WOVariables.wo_platform_codename == 'xenial'
                    or WOVariables.wo_platform_codename == 'bionic'):
                if WOAptGet.is_installed(self, 'php7.0-fpm'):
                    services = services + ['php7.0-fpm']
                else:
                    Log.info(self, "PHP7.0-FPM is not installed")
            else:
                Log.info(self, "Your platform does not support PHP 7")

        if self.app.pargs.mysql:
            if ((WOVariables.wo_mysql_host is "localhost")
                    or (WOVariables.wo_mysql_host is "127.0.0.1")):
                if (WOAptGet.is_installed(self, 'mysql-server')
                        or WOAptGet.is_installed(self,
                                                 'percona-server-server-5.6')
                        or WOAptGet.is_installed(self, 'mariadb-server')):
                    services = services + ['mysql']
                else:
                    Log.info(self, "MySQL is not installed")
            else:
                Log.warn(
                    self, "Remote MySQL found, "
                    "Unable to check MySQL service status")

        if self.app.pargs.hhvm:
            Log.info(self, "HHVM does not support to reload")

        if self.app.pargs.memcache:
            if WOAptGet.is_installed(self, 'memcached'):
                services = services + ['memcached']
            else:
                Log.info(self, "Memcache is not installed")

        if self.app.pargs.redis:
            if WOAptGet.is_installed(self, 'redis-server'):
                services = services + ['redis-server']
            else:
                Log.info(self, "Redis server is not installed")

        for service in services:
            Log.debug(self, "Reloading service: {0}".format(service))
            WOService.reload_service(self, service)