Example #1
0
def site_package_check(self, stype):
    apt_packages = []
    packages = []
    stack = EEStackController()
    stack.app = self.app
    if stype in ['html', 'php', 'mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
        Log.debug(self, "Setting apt_packages variable for Nginx")
        if not EEAptGet.is_installed(self, 'nginx-common'):
            apt_packages = apt_packages + EEVariables.ee_nginx

    if stype in ['php', 'mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
        Log.debug(self, "Setting apt_packages variable for PHP")
        if not EEAptGet.is_installed(self, 'php5-fpm'):
            apt_packages = apt_packages + EEVariables.ee_php

    if stype in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
        Log.debug(self, "Setting apt_packages variable for MySQL")
        if not EEShellExec.cmd_exec(self, "mysqladmin ping"):
            apt_packages = apt_packages + EEVariables.ee_mysql

    if stype in ['php', 'mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
        Log.debug(self, "Setting apt_packages variable for Postfix")
        if not EEAptGet.is_installed(self, 'postfix'):
            apt_packages = apt_packages + EEVariables.ee_postfix

    if stype in ['wp', 'wpsubdir', 'wpsubdomain']:
        Log.debug(self, "Setting packages variable for WP-CLI")
        if not EEShellExec.cmd_exec(self, "which wp"):
            packages = packages + [["https://github.com/wp-cli/wp-cli/"
                                    "releases/download/v{0}/"
                                    "wp-cli-{0}.phar"
                                    .format(EEVariables.ee_wp_cli),
                                    "/usr/bin/wp", "WP-CLI"]]
    return(stack.install(apt_packages=apt_packages, packages=packages,
                         disp_msg=False))
Example #2
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):
            self.app.pargs.nginx = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True

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

        if self.app.pargs.php:
            if EEAptGet.is_installed(self, 'php5-fpm'):
                self.info_php()
            else:
                Log.error(self, "PHP5 is not installed")

        if self.app.pargs.mysql:
            if EEShellExec.cmd_exec(self, "mysqladmin ping"):
                self.info_mysql()
            else:
                Log.error(self, "MySQL is not installed")
Example #3
0
    def add(self):
        """Swap addition with EasyEngine"""
        if EEVariables.ee_ram < 512:
            if EEVariables.ee_swap < 1000:
                Log.info(self, "Adding SWAP")

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

                # Modify Swap configuration
                if os.path.isfile("/etc/dphys-swapfile"):
                    EEFileUtils.searchreplace(self, "/etc/dphys-swapfile",
                                              "#CONF_SWAPFILE=/var/swap",
                                              "CONF_SWAPFILE=/ee-swapfile")
                    EEFileUtils.searchreplace(self,  "/etc/dphys-swapfile",
                                              "#CONF_MAXSWAP=2048",
                                              "CONF_MAXSWAP=1024")
                    EEFileUtils.searchreplace(self,  "/etc/dphys-swapfile",
                                              "#CONF_SWAPSIZE=",
                                              "CONF_SWAPSIZE=1024")
                else:
                    with open("/etc/dphys-swapfile", 'w') as conffile:
                        conffile.write("CONF_SWAPFILE=/ee-swapfile\n"
                                       "CONF_SWAPSIZE=1024\n"
                                       "CONF_MAXSWAP=1024\n")
                # Create swap file
                EEShellExec.cmd_exec(self, "service dphys-swapfile start")
Example #4
0
 def secure_port(self):
     """This function Secures port"""
     if self.app.pargs.user_input:
         while not self.app.pargs.user_input.isdigit():
             Log.info(self, "Please Enter valid port number ")
             self.app.pargs.user_input = input("EasyEngine "
                                               "admin port [22222]:")
     if not self.app.pargs.user_input:
         port = input("EasyEngine admin port [22222]:")
         if port == "":
             self.app.pargs.user_input = 22222
         while not port.isdigit() and port != "":
             Log.info(self, "Please Enter valid port number :")
             port = input("EasyEngine admin port [22222]:")
         self.app.pargs.user_input = port
     if EEVariables.ee_platform_distro == 'ubuntu':
         EEShellExec.cmd_exec(self, "sed -i \"s/listen.*/listen "
                              "{port} default_server ssl {http2};/\" "
                              "/etc/nginx/sites-available/22222"
                              .format(port=self.app.pargs.user_input,http2=("http2" if
                                                        EEAptGet.is_installed(self,'nginx-mainline') else "spdy")))
     if EEVariables.ee_platform_distro == 'debian':
         EEShellExec.cmd_exec(self, "sed -i \"s/listen.*/listen "
                              "{port} default_server ssl {http2};/\" "
                              "/etc/nginx/sites-available/22222"
                              .format(port=self.app.pargs.user_input,http2=("http2" if
                                                        EEAptGet.is_installed(self,'nginx-mainline') else "spdy")))
     EEGit.add(self, ["/etc/nginx"],
               msg="Adding changed secure port into Git")
     if not EEService.reload_service(self, 'nginx'):
         Log.error(self, "service nginx reload failed. "
                   "check issues with `nginx -t` command")
     Log.info(self, "Successfully port changed {port}"
              .format(port=self.app.pargs.user_input))
Example #5
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):
            self.app.pargs.nginx = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True

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

        if self.app.pargs.php:
            if EEAptGet.is_installed(self, 'php5-fpm'):
                self.info_php()
            else:
                Log.error(self, "PHP5 is not installed")

        if self.app.pargs.mysql:
            if EEShellExec.cmd_exec(self, "mysqladmin ping"):
                self.info_mysql()
            else:
                Log.error(self, "MySQL is not installed")
Example #6
0
    def add(self):
        """Swap addition with EasyEngine"""
        if EEVariables.ee_ram < 512:
            if EEVariables.ee_swap < 1000:
                Log.info(self, "Adding SWAP file, please wait...")

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

                # Modify Swap configuration
                if os.path.isfile("/etc/dphys-swapfile"):
                    EEFileUtils.searchreplace(self, "/etc/dphys-swapfile",
                                              "#CONF_SWAPFILE=/var/swap",
                                              "CONF_SWAPFILE=/ee-swapfile")
                    EEFileUtils.searchreplace(self,  "/etc/dphys-swapfile",
                                              "#CONF_MAXSWAP=2048",
                                              "CONF_MAXSWAP=1024")
                    EEFileUtils.searchreplace(self,  "/etc/dphys-swapfile",
                                              "#CONF_SWAPSIZE=",
                                              "CONF_SWAPSIZE=1024")
                else:
                    with open("/etc/dphys-swapfile", 'w') as conffile:
                        conffile.write("CONF_SWAPFILE=/ee-swapfile\n"
                                       "CONF_SWAPSIZE=1024\n"
                                       "CONF_MAXSWAP=1024\n")
                # Create swap file
                EEShellExec.cmd_exec(self, "service dphys-swapfile start")
Example #7
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.php7:
            self.app.pargs.php7 = 'off'
            self.debug_php7()
        if self.app.pargs.fpm:
            self.app.pargs.fpm = 'off'
            self.debug_fpm()
        if self.app.pargs.fpm7:
            self.app.pargs.fpm7 = 'off'
            self.debug_fpm7()
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if EEVariables.ee_mysql_host is "localhost":
                self.app.pargs.mysql = 'off'
                self.debug_mysql()
            else:
                Log.warn(
                    self, "Remote MySQL found, EasyEngine will not "
                    "enable remote debug")
        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:
            EEService.reload_service(self, 'nginx')

        # Reload PHP
        if self.trigger_php:
            if EEVariables.ee_platform_codename == 'trusty' or EEVariables.ee_platform_codename == 'bionic':
                if EEAptGet.is_installed(self, 'php5.6-fpm'):
                    EEService.reload_service(self, 'php5.6-fpm')
                if EEAptGet.is_installed(self, 'php7.2-fpm'):
                    EEService.reload_service(self, 'php7.2-fpm')
            else:
                EEService.reload_service(self, 'php5-fpm')
        self.app.close(0)
    def default(self):
        if ((not self.app.pargs.mariadb)):
            self.app.args.print_help()
        if self.app.pargs.mariadb:
            if EEVariables.ee_mysql_host is not "localhost":
                Log.error(
                    self, "Remote MySQL found, EasyEngine will not "
                    "install MariaDB")

            if EEShellExec.cmd_exec(self, "mysqladmin ping") and (
                    not EEAptGet.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")
Example #9
0
 def clean_redis(self):
     """This function clears Redis cache"""
     if (EEAptGet.is_installed(self, "redis-server")):
         Log.info(self, "Cleaning Redis cache")
         EEShellExec.cmd_exec(self, "redis-cli flushall")
     else:
         Log.info(self, "Redis is not installed")
Example #10
0
 def clean_redis(self):
     """This function clears Redis cache"""
     if(EEAptGet.is_installed(self, "redis-server")):
         Log.info(self, "Cleaning Redis cache")
         EEShellExec.cmd_exec(self, "redis-cli flushall")
     else:
         Log.info(self, "Redis is not installed")
Example #11
0
    def migrate_mariadb(self):
        # Backup all database
        EEMysql.backupAll(self)

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

        mysql_pref = ("Package: *\nPin: origin mirror.aarnet.edu.au"
                      "\nPin-Priority: 1000\n")
        with open('/etc/apt/preferences.d/'
                  'MariaDB.pref', 'w') as mysql_pref_file:
            mysql_pref_file.write(mysql_pref)

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

        config = configparser.ConfigParser()
        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")
        EEShellExec.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")
        EEShellExec.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 = EEVariables.ee_mysql + ["php5-mysql"]
        Log.info(self, "Updating apt-cache, please wait ...")
        EEAptGet.update(self)
        Log.info(self, "Installing MariaDB, please wait ...")
        EEAptGet.remove(self, ["mysql-common", "libmysqlclient18"])
        EEAptGet.auto_remove(self)
        EEAptGet.install(self, apt_packages)
Example #12
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.php7:
            self.app.pargs.php7 = 'off'
            self.debug_php7()
        if self.app.pargs.fpm:
            self.app.pargs.fpm = 'off'
            self.debug_fpm()
        if self.app.pargs.fpm7:
            self.app.pargs.fpm7 = 'off'
            self.debug_fpm7()
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if EEVariables.ee_mysql_host is "localhost":
                self.app.pargs.mysql = 'off'
                self.debug_mysql()
            else:
                Log.warn(self, "Remote MySQL found, EasyEngine will not "
                         "enable remote debug")
        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:
            EEService.reload_service(self, 'nginx')

        # Reload PHP
        if self.trigger_php:
            if EEVariables.ee_platform_codename == 'trusty' or EEVariables.ee_platform_codename == 'xenial':
                if EEAptGet.is_installed(self,'php5.6-fpm'):
                    EEService.reload_service(self, 'php5.6-fpm')
                if EEAptGet.is_installed(self,'php7.0-fpm'):
                    EEService.reload_service(self, 'php7.0-fpm')
            else:
                EEService.reload_service(self, 'php5-fpm')
        self.app.close(0)
    def upgrade_php56(self):
        if EEVariables.ee_platform_distro == "ubuntu":
            if os.path.isfile("/etc/apt/sources.list.d/ondrej-php5-5_6-{0}."
                              "list".format(EEVariables.ee_platform_codename)):
                Log.error(self, "Unable to find PHP 5.5")
        else:
            if not (os.path.isfile(EEVariables.ee_repo_file_path)
                    and EEFileUtils.grep(self, EEVariables.ee_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 EEVariables.ee_platform_distro == "ubuntu":
            EERepo.remove(self, ppa="ppa:ondrej/php5")
            EERepo.add(self, ppa=EEVariables.ee_php_repo)
        else:
            EEAptGet.remove(self, ["php5-xdebug"])
            EEFileUtils.searchreplace(self, EEVariables.ee_repo_file_path,
                                      "php55", "php56")

        Log.info(self, "Updating apt-cache, please wait...")
        EEAptGet.update(self)
        Log.info(self, "Installing packages, please wait ...")
        if (EEVariables.ee_platform_codename == 'trusty'
                or EEVariables.ee_platform_codename == 'xenial'
                or EEVariables.ee_platform_codename == 'bionic'):
            EEAptGet.install(self,
                             EEVariables.ee_php5_6 + EEVariables.ee_php_extra)
        else:
            EEAptGet.install(self, EEVariables.ee_php)

        if EEVariables.ee_platform_distro == "debian":
            EEShellExec.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")

            EEFileUtils.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")
Example #14
0
 def clean_memcache(self):
     """This function Clears memcache """
     try:
         if(EEAptGet.is_installed(self, "memcached")):
             EEService.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)
Example #15
0
 def clean_memcache(self):
     """This function Clears memcache """
     try:
         if (EEAptGet.is_installed(self, "memcached")):
             EEService.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)
Example #16
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 EEAptGet.is_installed(self, 'php7.0-fpm'):
                self.app.pargs.php = True

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

        if self.app.pargs.php:
            if EEVariables.ee_platform_codename != 'trusty':
                if EEAptGet.is_installed(self, 'php5-fpm'):
                    self.info_php()
                else:
                    Log.error(self, "PHP5 is not installed")
            else:
                if EEAptGet.is_installed(self, 'php5.6-fpm'):
                    self.info_php()
                else:
                    Log.error(self, "PHP5.6 is not installed")

        if self.app.pargs.php7:
            if EEAptGet.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 EEShellExec.cmd_exec(self, "mysqladmin ping"):
                self.info_mysql()
            else:
                Log.error(self, "MySQL is not installed")
Example #17
0
    def upgrade_php56(self):
        if EEVariables.ee_platform_distro == "ubuntu":
            if os.path.isfile("/etc/apt/sources.list.d/ondrej-php5-5_6-{0}."
                              "list".format(EEVariables.ee_platform_codename)):
                Log.error(self, "Unable to find PHP 5.5")
        else:
            if not(os.path.isfile(EEVariables.ee_repo_file_path) and
                   EEFileUtils.grep(self, EEVariables.ee_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 EEVariables.ee_platform_distro == "ubuntu":
            EERepo.remove(self, ppa="ppa:ondrej/php5")
            EERepo.add(self, ppa=EEVariables.ee_php_repo)
        else:
            EEAptGet.remove(self, ["php5-xdebug"])
            EEFileUtils.searchreplace(self, EEVariables.ee_repo_file_path,
                                      "php55", "php56")

        Log.info(self, "Updating apt-cache, please wait...")
        EEAptGet.update(self)
        Log.info(self, "Installing packages, please wait ...")
        if (EEVariables.ee_platform_codename == 'trusty' or EEVariables.ee_platform_codename == 'xenial'):
            EEAptGet.install(self, EEVariables.ee_php5_6 + EEVariables.ee_php_extra)
        else:
            EEAptGet.install(self, EEVariables.ee_php)

        if EEVariables.ee_platform_distro == "debian":
            EEShellExec.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")

            EEFileUtils.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")
Example #18
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 EEAptGet.is_installed(self, 'php7.0-fpm'):
                    self.app.pargs.php = True

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

        if self.app.pargs.php:
            if EEVariables.ee_platform_codename != 'trusty':
                if EEAptGet.is_installed(self, 'php5-fpm'):
                    self.info_php()
                else:
                    Log.error(self, "PHP5 is not installed")
            else:
                if EEAptGet.is_installed(self, 'php5.6-fpm'):
                    self.info_php()
                else:
                    Log.error(self, "PHP5.6 is not installed")

        if self.app.pargs.php7:
            if EEAptGet.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 EEShellExec.cmd_exec(self, "mysqladmin ping"):
                self.info_mysql()
            else:
                Log.error(self, "MySQL is not installed")
Example #19
0
def site_package_check(self, stype):
    apt_packages = []
    packages = []
    stack = EEStackController()
    stack.app = self.app
    if stype in ['html', 'php', 'mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
        Log.debug(self, "Setting apt_packages variable for Nginx")
        if not EEAptGet.is_installed(self, 'nginx-common'):
            apt_packages = apt_packages + EEVariables.ee_nginx

    if stype in ['php', 'mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
        Log.debug(self, "Setting apt_packages variable for PHP")
        if not EEAptGet.is_installed(self, 'php5-fpm'):
            apt_packages = apt_packages + EEVariables.ee_php

    if stype in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
        Log.debug(self, "Setting apt_packages variable for MySQL")
        if not EEShellExec.cmd_exec(self, "mysqladmin ping"):
            apt_packages = apt_packages + EEVariables.ee_mysql

    if stype in ['php', 'mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
        Log.debug(self, "Setting apt_packages variable for Postfix")
        if not EEAptGet.is_installed(self, 'postfix'):
            apt_packages = apt_packages + EEVariables.ee_postfix

    if stype in ['wp', 'wpsubdir', 'wpsubdomain']:
        Log.debug(self, "Setting packages variable for WP-CLI")
        if not EEShellExec.cmd_exec(self, "which wp"):
            packages = packages + [[
                "https://github.com/wp-cli/wp-cli/"
                "releases/download/v{0}/"
                "wp-cli-{0}.phar".format(EEVariables.ee_wp_cli), "/usr/bin/wp",
                "WP-CLI"
            ]]
    return (stack.install(apt_packages=apt_packages,
                          packages=packages,
                          disp_msg=False))
Example #20
0
    def default(self):
        if ((not self.app.pargs.mariadb)):
            self.app.args.print_help()
        if self.app.pargs.mariadb:
            if EEVariables.ee_mysql_host is not "localhost":
                Log.error(self, "Remote MySQL found, EasyEngine will not "
                          "install MariaDB")

            if EEShellExec.cmd_exec(self, "mysqladmin ping") and (not
               EEAptGet.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")
Example #21
0
def site_package_check(self, stype):
    apt_packages = []
    packages = []
    stack = EEStackController()
    stack.app = self.app
    if stype in ['html', 'proxy', 'php', 'mysql', 'wp', 'wpsubdir',
                 'wpsubdomain']:
        Log.debug(self, "Setting apt_packages variable for Nginx")

        if EEVariables.ee_platform_distro == 'debian':
            check_nginx = 'nginx-extras'
        else:
            check_nginx = 'nginx-custom'

        if not EEAptGet.is_installed(self, check_nginx):
            apt_packages = apt_packages + EEVariables.ee_nginx
        else:
            # Fix for Nginx white screen death
            if not EEFileUtils.grep(self, '/etc/nginx/fastcgi_params',
                                    'SCRIPT_FILENAME'):
                with open('/etc/nginx/fastcgi_params', encoding='utf-8',
                          mode='a') as ee_nginx:
                    ee_nginx.write('fastcgi_param \tSCRIPT_FILENAME '
                                   '\t$request_filename;\n')

    if stype in ['php', 'mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
        Log.debug(self, "Setting apt_packages variable for PHP")
        if not EEAptGet.is_installed(self, 'php5-fpm'):
            apt_packages = apt_packages + EEVariables.ee_php

    if stype in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
        Log.debug(self, "Setting apt_packages variable for MySQL")
        if not EEShellExec.cmd_exec(self, "mysqladmin ping"):
            apt_packages = apt_packages + EEVariables.ee_mysql
            packages = packages + [["https://raw.githubusercontent.com/"
                                    "major/MySQLTuner-perl/master/"
                                    "mysqltuner.pl", "/usr/bin/mysqltuner",
                                    "MySQLTuner"]]

    if stype in ['php', 'mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
        Log.debug(self, "Setting apt_packages variable for Postfix")
        if not EEAptGet.is_installed(self, 'postfix'):
            apt_packages = apt_packages + EEVariables.ee_postfix

    if stype in ['wp', 'wpsubdir', 'wpsubdomain']:
        Log.debug(self, "Setting packages variable for WP-CLI")
        if not EEShellExec.cmd_exec(self, "which wp"):
            packages = packages + [["https://github.com/wp-cli/wp-cli/"
                                    "releases/download/v{0}/"
                                    "wp-cli-{0}.phar"
                                    .format(EEVariables.ee_wp_cli),
                                    "/usr/bin/wp", "WP-CLI"]]

    if self.app.pargs.hhvm:
        Log.debug(self, "Setting apt_packages variable for HHVM")
        if not EEAptGet.is_installed(self, 'hhvm'):
            apt_packages = apt_packages + EEVariables.ee_hhvm

        if os.path.isdir("/etc/nginx/common") and (not
           os.path.isfile("/etc/nginx/common/php-hhvm.conf")):
            data = dict()
            Log.debug(self, 'Writting the nginx configuration to '
                      'file /etc/nginx/common/php-hhvm.conf')
            ee_nginx = open('/etc/nginx/common/php-hhvm.conf',
                            encoding='utf-8', mode='w')
            self.app.render((data), 'php-hhvm.mustache',
                            out=ee_nginx)
            ee_nginx.close()

            Log.debug(self, 'Writting the nginx configuration to '
                      'file /etc/nginx/common/w3tc-hhvm.conf')
            ee_nginx = open('/etc/nginx/common/w3tc-hhvm.conf',
                            encoding='utf-8', mode='w')
            self.app.render((data), 'w3tc-hhvm.mustache', out=ee_nginx)
            ee_nginx.close()

            Log.debug(self, 'Writting the nginx configuration to '
                      'file /etc/nginx/common/wpfc-hhvm.conf')
            ee_nginx = open('/etc/nginx/common/wpfc-hhvm.conf',
                            encoding='utf-8', mode='w')
            self.app.render((data), 'wpfc-hhvm.mustache',
                            out=ee_nginx)
            ee_nginx.close()

            Log.debug(self, 'Writting the nginx configuration to '
                      'file /etc/nginx/common/wpsc-hhvm.conf')
            ee_nginx = open('/etc/nginx/common/wpsc-hhvm.conf',
                            encoding='utf-8', mode='w')
            self.app.render((data), 'wpsc-hhvm.mustache',
                            out=ee_nginx)
            ee_nginx.close()

        if os.path.isfile("/etc/nginx/conf.d/upstream.conf"):
            if not EEFileUtils.grep(self, "/etc/nginx/conf.d/upstream.conf",
                                          "hhvm"):
                with open("/etc/nginx/conf.d/upstream.conf", "a") as hhvm_file:
                    hhvm_file.write("upstream hhvm {\nserver 127.0.0.1:8000;\n"
                                    "server 127.0.0.1:9000 backup;\n}\n")

    # Check if Nginx is allready installed and Pagespeed config there or not
    # If not then copy pagespeed config
    if self.app.pargs.pagespeed:
        if (os.path.isfile('/etc/nginx/nginx.conf') and
           (not os.path.isfile('/etc/nginx/conf.d/pagespeed.conf'))):
            # Pagespeed configuration
            data = dict()
            Log.debug(self, 'Writting the Pagespeed Global '
                      'configuration to file /etc/nginx/conf.d/'
                      'pagespeed.conf')
            ee_nginx = open('/etc/nginx/conf.d/pagespeed.conf',
                            encoding='utf-8', mode='w')
            self.app.render((data), 'pagespeed-global.mustache',
                            out=ee_nginx)
            ee_nginx.close()

    return(stack.install(apt_packages=apt_packages, packages=packages,
                         disp_msg=False))
    def migrate_mariadb(self):
        # Backup all database
        EEMysql.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)

        EERepo.add(self, repo_url=EEVariables.ee_mysql_repo)
        Log.debug(self, 'Adding key for {0}'.format(EEVariables.ee_mysql_repo))
        EERepo.add_key(self,
                       '0xF1656F24C74CD1D8',
                       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")
        EEShellExec.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")
        EEShellExec.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 = EEVariables.ee_mysql

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

        # If mail server is installed then install dovecot-sql and postfix-sql
        if EEAptGet.is_installed(self, "dovecot-core"):
            apt_packages = apt_packages + [
                "dovecot-mysql", "postfix-mysql", "libclass-dbi-mysql-perl"
            ]

        Log.info(self, "Updating apt-cache, please wait...")
        EEAptGet.update(self)
        Log.info(self, "Installing MariaDB, please wait...")
        EEAptGet.remove(self, ["mysql-common", "libmysqlclient18"])
        EEAptGet.auto_remove(self)
        EEAptGet.install(self, apt_packages)

        # Restart  dovecot and postfix if installed
        if EEAptGet.is_installed(self, "dovecot-core"):
            EEService.restart_service(self, 'dovecot')
            EEService.restart_service(self, 'postfix')
Example #23
0
    def migrate_mariadb(self):
        # Backup all database
        EEMysql.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)

        EERepo.add(self, repo_url=EEVariables.ee_mysql_repo)
        Log.debug(self, 'Adding key for {0}'
                  .format(EEVariables.ee_mysql_repo))
        EERepo.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")
        EEShellExec.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")
        EEShellExec.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 = EEVariables.ee_mysql

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

        # If mail server is installed then install dovecot-sql and postfix-sql
        if EEAptGet.is_installed(self, "dovecot-core"):
            apt_packages = apt_packages + ["dovecot-mysql", "postfix-mysql",
                                           "libclass-dbi-mysql-perl"]

        Log.info(self, "Updating apt-cache, please wait...")
        EEAptGet.update(self)
        Log.info(self, "Installing MariaDB, please wait...")
        EEAptGet.remove(self, ["mysql-common", "libmysqlclient18"])
        EEAptGet.auto_remove(self)
        EEAptGet.install(self, apt_packages)

        # Restart  dovecot and postfix if installed
        if EEAptGet.is_installed(self, "dovecot-core"):
            EEService.restart_service(self, 'dovecot')
            EEService.restart_service(self, 'postfix')
Example #24
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.php7)
           and (not self.app.pargs.fpm) and (not self.app.pargs.fpm7) 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 ee3.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:
                cron_time = 5

            try:
                if not EEShellExec.cmd_exec(self, "crontab -l | grep "
                                            "'ee debug --import-slow-log'"):
                    if not cron_time == 0:
                        Log.info(self, "setting up crontab entry,"
                                 " please wait...")
                        EEShellExec.cmd_exec(self, "/bin/bash -c \"crontab -l "
                                             "2> /dev/null | {{ cat; echo -e"
                                             " \\\"#EasyEngine start MySQL "
                                             "slow log \\n*/{0} * * * * "
                                             "/usr/local/bin/ee debug"
                                             " --import-slow-log\\n"
                                             "#EasyEngine end MySQL slow log"
                                             "\\\"; }} | crontab -\""
                                             .format(cron_time))
                else:
                    if not cron_time == 0:
                        Log.info(self, "updating crontab entry,"
                                 " please wait...")
                        if not EEShellExec.cmd_exec(self, "/bin/bash -c "
                                                    "\"crontab "
                                                    "-l | sed '/EasyEngine "
                                                    "start MySQL slow "
                                                    "log/!b;n;c\*\/{0} "
                                                    "\* \* \* "
                                                    "\* \/usr"
                                                    "\/local\/bin\/ee 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 EEShellExec.cmd_exec(self, "/bin/bash -c "
                                                    "\"crontab "
                                                    "-l | sed '/EasyEngine "
                                                    "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 (EEVariables.ee_platform_codename == 'trusty' or EEVariables.ee_platform_codename == 'xenial') and EEAptGet.is_installed(self,'php7.0-fpm'):
                self.app.pargs.php7 = 'on'
                self.app.pargs.fpm7 = '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 (EEVariables.ee_platform_codename == 'trusty' or EEVariables.ee_platform_codename == 'xenial') and EEAptGet.is_installed(self,'php7.0-fpm'):
                self.app.pargs.php7 = 'off'
                self.app.pargs.fpm7 = '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.php7)
           and (not self.app.pargs.fpm) and (not self.app.pargs.fpm7) 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.php7:
            self.debug_php7()
        if self.app.pargs.fpm7:
            self.debug_fpm7()
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if EEVariables.ee_mysql_host is "localhost":
                self.debug_mysql()
            else:
                Log.warn(self, "Remote MySQL found, EasyEngine will not "
                         "enable remote debug")
        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:
            EEService.reload_service(self, 'nginx')
        # Reload PHP
        if self.trigger_php:
            if (EEVariables.ee_platform_codename == 'trusty' or EEVariables.ee_platform_codename == 'xenial'):
                if EEAptGet.is_installed(self,'php5.6-fpm'):
                    EEService.restart_service(self, 'php5.6-fpm')
                if EEAptGet.is_installed(self,'php7.0-fpm'):
                    EEService.restart_service(self, 'php7.0-fpm')
            else:
                EEService.restart_service(self, 'php5-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)
Example #25
0
    def status(self):
        """Status of services"""
        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.postfix or self.app.pargs.hhvm
                or self.app.pargs.memcache or self.app.pargs.dovecot
                or self.app.pargs.redis):
            self.app.pargs.nginx = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True
            self.app.pargs.postfix = True
            self.app.pargs.hhvm = True

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

        if self.app.pargs.php:
            if EEVariables.ee_platform_codename != 'trusty':
                if EEAptGet.is_installed(self, 'php5-fpm'):
                    services = services + ['php5-fpm']
                else:
                    Log.info(self, "PHP5-FPM is not installed")
            else:
                if EEAptGet.is_installed(self, 'php5.6-fpm'):
                    services = services + ['php5.6-fpm']
                else:
                    Log.info(self, "PHP5.6-FPM is not installed")

                if EEAptGet.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 EEVariables.ee_platform_codename == 'trusty':
                if EEAptGet.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 ((EEVariables.ee_mysql_host is "localhost")
                    or (EEVariables.ee_mysql_host is "127.0.0.1")):
                if (EEAptGet.is_installed(self, 'mysql-server')
                        or EEAptGet.is_installed(self,
                                                 'percona-server-server-5.6')
                        or EEAptGet.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.postfix:
            if EEAptGet.is_installed(self, 'postfix'):
                services = services + ['postfix']
            else:
                Log.info(self, "Postfix is not installed")

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

        if self.app.pargs.dovecot:
            if EEAptGet.is_installed(self, 'dovecot-core'):
                services = services + ['dovecot']
            else:
                Log.info(self, "Mail server is not installed")

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

        for service in services:
            if EEService.get_service_status(self, service):
                Log.info(self, "{0:10}:  {1}".format(service, "Running"))
Example #26
0
    def default(self):
        # All package update
        if ((not self.app.pargs.php56)):

            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.postfix)
                    and (not self.app.pargs.hhvm)
                    and (not self.app.pargs.mailscanner)
                    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
                self.app.pargs.mail = True

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

            if self.app.pargs.mail:
                self.app.pargs.nginx = True
                self.app.pargs.php = True
                self.app.pargs.mysql = True
                self.app.pargs.wpcli = True
                self.app.pargs.postfix = True

                if EEAptGet.is_installed(self, 'dovecot-core'):
                    apt_packages = apt_packages + EEVariables.ee_mail
                    self.app.pargs.mailscanner = True
                else:
                    Log.info(self, "Mail server is not installed")

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

            if self.app.pargs.nginxmainline:
                if EEAptGet.is_installed(self, 'nginx-mainline'):
                    apt_packages = apt_packages + EEVariables.ee_nginx_dev
                else:
                    Log.info(self, "Nginx Mainline is not already installed")

            if self.app.pargs.php:
                if EEVariables.ee_platform_codename != 'trusty':
                    if EEAptGet.is_installed(self, 'php5-fpm'):
                        apt_packages = apt_packages + EEVariables.ee_php
                    else:
                        Log.info(self, "PHP is not installed")
                else:
                    if EEAptGet.is_installed(self, 'php5.6-fpm'):
                        apt_packages = apt_packages + EEVariables.ee_php5_6 + EEVariables.ee_php_extra
                    else:
                        Log.info(self, "PHP 5.6 is not installed")

                    if EEAptGet.is_installed(self, 'php7.0-fpm'):
                        apt_packages = apt_packages + EEVariables.ee_php7_0 + EEVariables.ee_php_extra
                    else:
                        Log.info(self, "PHP 7.0 is not installed")

            if self.app.pargs.hhvm:
                if EEAptGet.is_installed(self, 'hhvm'):
                    apt_packages = apt_packages + EEVariables.ee_hhvm
                else:
                    Log.info(self, "HHVM is not installed")

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

            if self.app.pargs.postfix:
                if EEAptGet.is_installed(self, 'postfix'):
                    apt_packages = apt_packages + EEVariables.ee_postfix
                else:
                    Log.info(self, "Postfix is not installed")

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

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

            if self.app.pargs.mailscanner:
                if EEAptGet.is_installed(self, 'amavisd-new'):
                    apt_packages = (apt_packages + EEVariables.ee_mailscanner)
                else:
                    Log.info(self, "MailScanner is not 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
                    EEAptGet.update(self)
                    # Update packages
                    EEAptGet.install(self, apt_packages)

                    # Post Actions after package updates
                    if (set(EEVariables.ee_nginx).issubset(set(apt_packages))
                            or set(EEVariables.ee_nginx_dev).issubset(
                                set(apt_packages))):
                        EEService.restart_service(self, 'nginx')
                    if EEVariables.ee_platform_codename != 'trusty':
                        if set(EEVariables.ee_php).issubset(set(apt_packages)):
                            EEService.restart_service(self, 'php5-fpm')
                    else:
                        if set(EEVariables.ee_php5_6).issubset(
                                set(apt_packages)):
                            EEService.restart_service(self, 'php5.6-fpm')
                        if set(EEVariables.ee_php7_0).issubset(
                                set(apt_packages)):
                            EEService.restart_service(self, 'php7.0-fpm')
                    if set(EEVariables.ee_hhvm).issubset(set(apt_packages)):
                        EEService.restart_service(self, 'hhvm')
                    if set(EEVariables.ee_postfix).issubset(set(apt_packages)):
                        EEService.restart_service(self, 'postfix')
                    if set(EEVariables.ee_mysql).issubset(set(apt_packages)):
                        EEService.restart_service(self, 'mysql')
                    if set(EEVariables.ee_mail).issubset(set(apt_packages)):
                        EEService.restart_service(self, 'dovecot')
                    if set(EEVariables.ee_redis).issubset(set(apt_packages)):
                        EEService.restart_service(self, 'redis-server')

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

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

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

                Log.info(self, "Successfully updated packages")

        # PHP 5.6 to 5.6
        elif (self.app.pargs.php56):
            self.upgrade_php56()
        else:
            self.app.args.print_help()
Example #27
0
    def default(self):
        # All package update
        if ((not self.app.pargs.php56)):

            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.postfix) and (not self.app.pargs.hhvm) and
               (not self.app.pargs.mailscanner) 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
                self.app.pargs.mail = True

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

            if self.app.pargs.mail:
                self.app.pargs.nginx = True
                self.app.pargs.php = True
                self.app.pargs.mysql = True
                self.app.pargs.wpcli = True
                self.app.pargs.postfix = True

                if EEAptGet.is_installed(self, 'dovecot-core'):
                    apt_packages = apt_packages + EEVariables.ee_mail
                    self.app.pargs.mailscanner = True
                else:
                    Log.info(self, "Mail server is not installed")

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

#            if self.app.pargs.nginxmainline:
#                if EEAptGet.is_installed(self, 'nginx-mainline'):
#                    apt_packages = apt_packages + EEVariables.ee_nginx_dev
#                else:
#                    Log.info(self, "Nginx Mainline is not already installed")

            if self.app.pargs.php:
                if (EEVariables.ee_platform_distro == 'debian' or EEVariables.ee_platform_codename == 'precise'):
                    if EEAptGet.is_installed(self, 'php5-fpm'):
                        apt_packages = apt_packages + EEVariables.ee_php
                    else:
                        Log.info(self, "PHP is not installed")
                else:
                    if EEAptGet.is_installed(self, 'php5.6-fpm'):
                        apt_packages = apt_packages + EEVariables.ee_php5_6 + EEVariables.ee_php_extra
                    else:
                        Log.info(self, "PHP 5.6 is not installed")

                    if EEAptGet.is_installed(self, 'php7.0-fpm'):
                        apt_packages = apt_packages + EEVariables.ee_php7_0 + EEVariables.ee_php_extra
                    else:
                        Log.info(self, "PHP 7.0 is not installed")

            if self.app.pargs.hhvm:
                if EEAptGet.is_installed(self, 'hhvm'):
                    apt_packages = apt_packages + EEVariables.ee_hhvm
                else:
                    Log.info(self, "HHVM is not installed")

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

            if self.app.pargs.postfix:
                if EEAptGet.is_installed(self, 'postfix'):
                    apt_packages = apt_packages + EEVariables.ee_postfix
                else:
                    Log.info(self, "Postfix is not installed")

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

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

            if self.app.pargs.mailscanner:
                if EEAptGet.is_installed(self, 'amavisd-new'):
                    apt_packages = (apt_packages + EEVariables.ee_mailscanner)
                else:
                    Log.info(self, "MailScanner is not 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
                    EEAptGet.update(self)
                    # Update packages
                    EEAptGet.install(self, apt_packages)

                    # Post Actions after package updates
                    if (set(EEVariables.ee_nginx).issubset(set(apt_packages))):
                        EEService.restart_service(self, 'nginx')
                    if (EEVariables.ee_platform_distro == 'debian' or EEVariables.ee_platform_codename == 'precise'):
                        if set(EEVariables.ee_php).issubset(set(apt_packages)):
                            EEService.restart_service(self, 'php5-fpm')
                    else:
                        if set(EEVariables.ee_php5_6).issubset(set(apt_packages)):
                            EEService.restart_service(self, 'php5.6-fpm')
                        if set(EEVariables.ee_php7_0).issubset(set(apt_packages)):
                            EEService.restart_service(self, 'php7.0-fpm')
                    if set(EEVariables.ee_hhvm).issubset(set(apt_packages)):
                        EEService.restart_service(self, 'hhvm')
                    if set(EEVariables.ee_postfix).issubset(set(apt_packages)):
                        EEService.restart_service(self, 'postfix')
                    if set(EEVariables.ee_mysql).issubset(set(apt_packages)):
                        EEService.restart_service(self, 'mysql')
                    if set(EEVariables.ee_mail).issubset(set(apt_packages)):
                        EEService.restart_service(self, 'dovecot')
                    if set(EEVariables.ee_redis).issubset(set(apt_packages)):
                        EEService.restart_service(self, 'redis-server')

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

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

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

                Log.info(self, "Successfully updated packages")

        # PHP 5.6 to 5.6
        elif (self.app.pargs.php56):
            self.upgrade_php56()
        else:
            self.app.args.print_help()
    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.postfix
                or self.app.pargs.hhvm or self.app.pargs.memcache
                or self.app.pargs.dovecot or self.app.pargs.redis):
            self.app.pargs.nginx = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True
            self.app.pargs.postfix = True

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

        if self.app.pargs.php:
            if EEVariables.ee_platform_codename != 'trusty':
                if EEAptGet.is_installed(self, 'php5-fpm'):
                    services = services + ['php5-fpm']
                else:
                    Log.info(self, "PHP5-FPM is not installed")
            else:
                if EEAptGet.is_installed(self, 'php5.6-fpm'):
                    services = services + ['php5.6-fpm']
                else:
                    Log.info(self, "PHP5.6-FPM is not installed")

                if EEAptGet.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 EEVariables.ee_platform_codename == 'trusty':
                if EEAptGet.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 ((EEVariables.ee_mysql_host is "localhost") or
               (EEVariables.ee_mysql_host is "127.0.0.1")):
                if (EEAptGet.is_installed(self, 'mysql-server') or
                   EEAptGet.is_installed(self, 'percona-server-server-5.6') or
                   EEAptGet.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.postfix:
            if EEAptGet.is_installed(self, 'postfix'):
                services = services + ['postfix']
            else:
                Log.info(self, "Postfix is not installed")

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

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

        if self.app.pargs.dovecot:
            if EEAptGet.is_installed(self, 'dovecot-core'):
                services = services + ['dovecot']
            else:
                Log.info(self, "Mail server is not installed")

        if self.app.pargs.redis:
            if EEAptGet.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))
            EEService.reload_service(self, service)
Example #29
0
def site_package_check(self, stype):
    apt_packages = []
    packages = []
    stack = EEStackController()
    stack.app = self.app
    if stype in ['html', 'proxy', 'php', 'mysql', 'wp', 'wpsubdir',
                 'wpsubdomain']:
        Log.debug(self, "Setting apt_packages variable for Nginx")

        if not EEAptGet.is_installed(self, 'nginx-custom'):
            apt_packages = apt_packages + EEVariables.ee_nginx
        else:
            # Fix for Nginx white screen death
            if not EEFileUtils.grep(self, '/etc/nginx/fastcgi_params',
                                    'SCRIPT_FILENAME'):
                with open('/etc/nginx/fastcgi_params', encoding='utf-8',
                          mode='a') as ee_nginx:
                    ee_nginx.write('fastcgi_param \tSCRIPT_FILENAME '
                                   '\t$request_filename;\n')

    if stype in ['php', 'mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
        Log.debug(self, "Setting apt_packages variable for PHP")
        if not EEAptGet.is_installed(self, 'php5-fpm'):
            apt_packages = apt_packages + EEVariables.ee_php

    if stype in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
        Log.debug(self, "Setting apt_packages variable for MySQL")
        if not EEShellExec.cmd_exec(self, "mysqladmin ping"):
            apt_packages = apt_packages + EEVariables.ee_mysql
            packages = packages + [["https://raw.githubusercontent.com/"
                                    "major/MySQLTuner-perl/master/"
                                    "mysqltuner.pl", "/usr/bin/mysqltuner",
                                    "MySQLTuner"]]

    if stype in ['php', 'mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
        Log.debug(self, "Setting apt_packages variable for Postfix")
        if not EEAptGet.is_installed(self, 'postfix'):
            apt_packages = apt_packages + EEVariables.ee_postfix

    if stype in ['wp', 'wpsubdir', 'wpsubdomain']:
        Log.debug(self, "Setting packages variable for WP-CLI")
        if not EEShellExec.cmd_exec(self, "which wp"):
            packages = packages + [["https://github.com/wp-cli/wp-cli/"
                                    "releases/download/v{0}/"
                                    "wp-cli-{0}.phar"
                                    .format(EEVariables.ee_wp_cli),
                                    "/usr/bin/wp", "WP-CLI"]]
    if self.app.pargs.wpredis:
        Log.debug(self, "Setting apt_packages variable for redis")
        if not EEAptGet.is_installed(self, 'redis-server'):
            apt_packages = apt_packages + EEVariables.ee_redis

        if os.path.isfile("/etc/nginx/nginx.conf") and (not
           os.path.isfile("/etc/nginx/common/redis.conf")):

            data = dict()
            Log.debug(self, 'Writting the nginx configuration to '
                      'file /etc/nginx/common/redis.conf')
            ee_nginx = open('/etc/nginx/common/redis.conf',
                            encoding='utf-8', mode='w')
            self.app.render((data), 'redis.mustache',
                            out=ee_nginx)
            ee_nginx.close()

        if os.path.isfile("/etc/nginx/nginx.conf") and (not
           os.path.isfile("/etc/nginx/common/redis-hhvm.conf")):

            data = dict()
            Log.debug(self, 'Writting the nginx configuration to '
                      'file /etc/nginx/common/redis-hhvm.conf')
            ee_nginx = open('/etc/nginx/common/redis-hhvm.conf',
                            encoding='utf-8', mode='w')
            self.app.render((data), 'redis-hhvm.mustache',
                            out=ee_nginx)
            ee_nginx.close()

        if os.path.isfile("/etc/nginx/conf.d/upstream.conf"):
            if not EEFileUtils.grep(self, "/etc/nginx/conf.d/"
                                    "upstream.conf",
                                    "redis"):
                with open("/etc/nginx/conf.d/upstream.conf",
                          "a") as redis_file:
                    redis_file.write("upstream redis {\n"
                                     "    server 127.0.0.1:6379;\n"
                                     "    keepalive 10;\n}")

        if os.path.isfile("/etc/nginx/nginx.conf") and (not
           os.path.isfile("/etc/nginx/conf.d/redis.conf")):
            with open("/etc/nginx/conf.d/redis.conf", "a") as redis_file:
                redis_file.write("# Log format Settings\n"
                                 "log_format rt_cache_redis '$remote_addr $upstream_response_time $srcache_fetch_status [$time_local] '\n"
                                 "'$http_host \"$request\" $status $body_bytes_sent '\n"
                                 "'\"$http_referer\" \"$http_user_agent\"';\n")

    if self.app.pargs.hhvm:
        if platform.architecture()[0] is '32bit':
            Log.error(self, "HHVM is not supported by 32bit system")
        Log.debug(self, "Setting apt_packages variable for HHVM")
        if not EEAptGet.is_installed(self, 'hhvm'):
            apt_packages = apt_packages + EEVariables.ee_hhvm

        if os.path.isdir("/etc/nginx/common") and (not
           os.path.isfile("/etc/nginx/common/php-hhvm.conf")):
            data = dict()
            Log.debug(self, 'Writting the nginx configuration to '
                      'file /etc/nginx/common/php-hhvm.conf')
            ee_nginx = open('/etc/nginx/common/php-hhvm.conf',
                            encoding='utf-8', mode='w')
            self.app.render((data), 'php-hhvm.mustache',
                            out=ee_nginx)
            ee_nginx.close()

            Log.debug(self, 'Writting the nginx configuration to '
                      'file /etc/nginx/common/w3tc-hhvm.conf')
            ee_nginx = open('/etc/nginx/common/w3tc-hhvm.conf',
                            encoding='utf-8', mode='w')
            self.app.render((data), 'w3tc-hhvm.mustache', out=ee_nginx)
            ee_nginx.close()

            Log.debug(self, 'Writting the nginx configuration to '
                      'file /etc/nginx/common/wpfc-hhvm.conf')
            ee_nginx = open('/etc/nginx/common/wpfc-hhvm.conf',
                            encoding='utf-8', mode='w')
            self.app.render((data), 'wpfc-hhvm.mustache',
                            out=ee_nginx)
            ee_nginx.close()

            Log.debug(self, 'Writting the nginx configuration to '
                      'file /etc/nginx/common/wpsc-hhvm.conf')
            ee_nginx = open('/etc/nginx/common/wpsc-hhvm.conf',
                            encoding='utf-8', mode='w')
            self.app.render((data), 'wpsc-hhvm.mustache',
                            out=ee_nginx)
            ee_nginx.close()

        if os.path.isfile("/etc/nginx/conf.d/upstream.conf"):
            if not EEFileUtils.grep(self, "/etc/nginx/conf.d/upstream.conf",
                                          "hhvm"):
                with open("/etc/nginx/conf.d/upstream.conf", "a") as hhvm_file:
                    hhvm_file.write("upstream hhvm {\nserver 127.0.0.1:8000;\n"
                                    "server 127.0.0.1:9000 backup;\n}\n")

    # Check if Nginx is allready installed and Pagespeed config there or not
    # If not then copy pagespeed config
    if self.app.pargs.pagespeed:
        if (os.path.isfile('/etc/nginx/nginx.conf') and
           (not os.path.isfile('/etc/nginx/conf.d/pagespeed.conf'))):
            # Pagespeed configuration
            data = dict()
            Log.debug(self, 'Writting the Pagespeed Global '
                      'configuration to file /etc/nginx/conf.d/'
                      'pagespeed.conf')
            ee_nginx = open('/etc/nginx/conf.d/pagespeed.conf',
                            encoding='utf-8', mode='w')
            self.app.render((data), 'pagespeed-global.mustache',
                            out=ee_nginx)
            ee_nginx.close()

    return(stack.install(apt_packages=apt_packages, packages=packages,
                         disp_msg=False))
    def status(self):
        """Status of services"""
        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.postfix
                or self.app.pargs.hhvm or self.app.pargs.memcache
                or self.app.pargs.dovecot or self.app.pargs.redis):
            self.app.pargs.nginx = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True
            self.app.pargs.postfix = True
            self.app.pargs.hhvm = True

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

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

                if EEAptGet.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 (EEVariables.ee_platform_codename == 'trusty' or EEVariables.ee_platform_codename == 'xenial'):
                if EEAptGet.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 ((EEVariables.ee_mysql_host is "localhost") or
               (EEVariables.ee_mysql_host is "127.0.0.1")):
                if (EEAptGet.is_installed(self, 'mysql-server') or
                   EEAptGet.is_installed(self, 'percona-server-server-5.6') or
                   EEAptGet.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.postfix:
            if EEAptGet.is_installed(self, 'postfix'):
                services = services + ['postfix']
            else:
                Log.info(self, "Postfix is not installed")

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

        if self.app.pargs.dovecot:
            if EEAptGet.is_installed(self, 'dovecot-core'):
                services = services + ['dovecot']
            else:
                Log.info(self, "Mail server is not installed")

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

        for service in services:
            if EEService.get_service_status(self, service):
                Log.info(self, "{0:10}:  {1}".format(service, "Running"))
Example #31
0
def site_package_check(self, stype):
    apt_packages = []
    packages = []
    stack = EEStackController()
    stack.app = self.app
    if stype in ['html', 'proxy', 'php', 'mysql', 'wp', 'wpsubdir',
                 'wpsubdomain']:
        Log.debug(self, "Setting apt_packages variable for Nginx")

        if not EEAptGet.is_installed(self, 'nginx-custom'):
            apt_packages = apt_packages + EEVariables.ee_nginx
        else:
            # Fix for Nginx white screen death
            if not EEFileUtils.grep(self, '/etc/nginx/fastcgi_params',
                                    'SCRIPT_FILENAME'):
                with open('/etc/nginx/fastcgi_params', encoding='utf-8',
                          mode='a') as ee_nginx:
                    ee_nginx.write('fastcgi_param \tSCRIPT_FILENAME '
                                   '\t$request_filename;\n')

    if stype in ['php', 'mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
        Log.debug(self, "Setting apt_packages variable for PHP")
        if not EEAptGet.is_installed(self, 'php5-fpm'):
            apt_packages = apt_packages + EEVariables.ee_php

    if stype in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
        Log.debug(self, "Setting apt_packages variable for MySQL")
        if not EEShellExec.cmd_exec(self, "mysqladmin ping"):
            apt_packages = apt_packages + EEVariables.ee_mysql
            packages = packages + [["https://raw.githubusercontent.com/"
                                    "major/MySQLTuner-perl/master/"
                                    "mysqltuner.pl", "/usr/bin/mysqltuner",
                                    "MySQLTuner"]]

    if stype in ['php', 'mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
        Log.debug(self, "Setting apt_packages variable for Postfix")
        if not EEAptGet.is_installed(self, 'postfix'):
            apt_packages = apt_packages + EEVariables.ee_postfix

    if stype in ['wp', 'wpsubdir', 'wpsubdomain']:
        Log.debug(self, "Setting packages variable for WP-CLI")
        if not EEShellExec.cmd_exec(self, "which wp"):
            packages = packages + [["https://github.com/wp-cli/wp-cli/"
                                    "releases/download/v{0}/"
                                    "wp-cli-{0}.phar"
                                    .format(EEVariables.ee_wp_cli),
                                    "/usr/bin/wp", "WP-CLI"]]
    if self.app.pargs.wpredis:
        Log.debug(self, "Setting apt_packages variable for redis")
        if not EEAptGet.is_installed(self, 'redis-server'):
            apt_packages = apt_packages + EEVariables.ee_redis

        if os.path.isfile("/etc/nginx/nginx.conf") and (not
           os.path.isfile("/etc/nginx/common/redis.conf")):

            data = dict()
            Log.debug(self, 'Writting the nginx configuration to '
                      'file /etc/nginx/common/redis.conf')
            ee_nginx = open('/etc/nginx/common/redis.conf',
                            encoding='utf-8', mode='w')
            self.app.render((data), 'redis.mustache',
                            out=ee_nginx)
            ee_nginx.close()

        if os.path.isfile("/etc/nginx/nginx.conf") and (not
           os.path.isfile("/etc/nginx/common/redis-hhvm.conf")):

            data = dict()
            Log.debug(self, 'Writting the nginx configuration to '
                      'file /etc/nginx/common/redis-hhvm.conf')
            ee_nginx = open('/etc/nginx/common/redis-hhvm.conf',
                            encoding='utf-8', mode='w')
            self.app.render((data), 'redis-hhvm.mustache',
                            out=ee_nginx)
            ee_nginx.close()

        if os.path.isfile("/etc/nginx/conf.d/upstream.conf"):
            if not EEFileUtils.grep(self, "/etc/nginx/conf.d/"
                                    "upstream.conf",
                                    "redis"):
                with open("/etc/nginx/conf.d/upstream.conf",
                          "a") as redis_file:
                    redis_file.write("upstream redis {\n"
                                     "    server 127.0.0.1:6379;\n"
                                     "    keepalive 10;\n}")

        if os.path.isfile("/etc/nginx/nginx.conf") and (not
           os.path.isfile("/etc/nginx/conf.d/redis.conf")):
            with open("/etc/nginx/conf.d/redis.conf", "a") as redis_file:
                redis_file.write("# Log format Settings\n"
                                 "log_format rt_cache_redis '$remote_addr $upstream_response_time $srcache_fetch_status [$time_local] '\n"
                                 "'$http_host \"$request\" $status $body_bytes_sent '\n"
                                 "'\"$http_referer\" \"$http_user_agent\"';\n")

    if self.app.pargs.hhvm:
        if platform.architecture()[0] is '32bit':
            Log.error(self, "HHVM is not supported by 32bit system")
        Log.debug(self, "Setting apt_packages variable for HHVM")
        if not EEAptGet.is_installed(self, 'hhvm'):
            apt_packages = apt_packages + EEVariables.ee_hhvm

        if os.path.isdir("/etc/nginx/common") and (not
           os.path.isfile("/etc/nginx/common/php-hhvm.conf")):
            data = dict()
            Log.debug(self, 'Writting the nginx configuration to '
                      'file /etc/nginx/common/php-hhvm.conf')
            ee_nginx = open('/etc/nginx/common/php-hhvm.conf',
                            encoding='utf-8', mode='w')
            self.app.render((data), 'php-hhvm.mustache',
                            out=ee_nginx)
            ee_nginx.close()

            Log.debug(self, 'Writting the nginx configuration to '
                      'file /etc/nginx/common/w3tc-hhvm.conf')
            ee_nginx = open('/etc/nginx/common/w3tc-hhvm.conf',
                            encoding='utf-8', mode='w')
            self.app.render((data), 'w3tc-hhvm.mustache', out=ee_nginx)
            ee_nginx.close()

            Log.debug(self, 'Writting the nginx configuration to '
                      'file /etc/nginx/common/wpfc-hhvm.conf')
            ee_nginx = open('/etc/nginx/common/wpfc-hhvm.conf',
                            encoding='utf-8', mode='w')
            self.app.render((data), 'wpfc-hhvm.mustache',
                            out=ee_nginx)
            ee_nginx.close()

            Log.debug(self, 'Writting the nginx configuration to '
                      'file /etc/nginx/common/wpsc-hhvm.conf')
            ee_nginx = open('/etc/nginx/common/wpsc-hhvm.conf',
                            encoding='utf-8', mode='w')
            self.app.render((data), 'wpsc-hhvm.mustache',
                            out=ee_nginx)
            ee_nginx.close()

        if os.path.isfile("/etc/nginx/conf.d/upstream.conf"):
            if not EEFileUtils.grep(self, "/etc/nginx/conf.d/upstream.conf",
                                          "hhvm"):
                with open("/etc/nginx/conf.d/upstream.conf", "a") as hhvm_file:
                    hhvm_file.write("upstream hhvm {\nserver 127.0.0.1:8000;\n"
                                    "server 127.0.0.1:9000 backup;\n}\n")

    # Check if Nginx is allready installed and Pagespeed config there or not
    # If not then copy pagespeed config
    if self.app.pargs.pagespeed:
        if (os.path.isfile('/etc/nginx/nginx.conf') and
           (not os.path.isfile('/etc/nginx/conf.d/pagespeed.conf'))):
            # Pagespeed configuration
            data = dict()
            Log.debug(self, 'Writting the Pagespeed Global '
                      'configuration to file /etc/nginx/conf.d/'
                      'pagespeed.conf')
            ee_nginx = open('/etc/nginx/conf.d/pagespeed.conf',
                            encoding='utf-8', mode='w')
            self.app.render((data), 'pagespeed-global.mustache',
                            out=ee_nginx)
            ee_nginx.close()

    return(stack.install(apt_packages=apt_packages, packages=packages,
                         disp_msg=False))
Example #32
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.php7) and (not self.app.pargs.fpm)
                and (not self.app.pargs.fpm7) 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 ee3.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:
                cron_time = 5

            try:
                if not EEShellExec.cmd_exec(
                        self, "crontab -l | grep "
                        "'ee debug --import-slow-log'"):
                    if not cron_time == 0:
                        Log.info(self, "setting up crontab entry,"
                                 " please wait...")
                        EEShellExec.cmd_exec(
                            self, "/bin/bash -c \"crontab -l "
                            "2> /dev/null | {{ cat; echo -e"
                            " \\\"#EasyEngine start MySQL "
                            "slow log \\n*/{0} * * * * "
                            "/usr/local/bin/ee debug"
                            " --import-slow-log\\n"
                            "#EasyEngine end MySQL slow log"
                            "\\\"; }} | crontab -\"".format(cron_time))
                else:
                    if not cron_time == 0:
                        Log.info(self, "updating crontab entry,"
                                 " please wait...")
                        if not EEShellExec.cmd_exec(
                                self, "/bin/bash -c "
                                "\"crontab "
                                "-l | sed '/EasyEngine "
                                "start MySQL slow "
                                "log/!b;n;c\*\/{0} "
                                "\* \* \* "
                                "\* \/usr"
                                "\/local\/bin\/ee 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 EEShellExec.cmd_exec(
                                self, "/bin/bash -c "
                                "\"crontab "
                                "-l | sed '/EasyEngine "
                                "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 (EEVariables.ee_platform_codename == 'trusty'
                    or EEVariables.ee_platform_codename
                    == 'bionic') and EEAptGet.is_installed(self, 'php7.2-fpm'):
                self.app.pargs.php7 = 'on'
                self.app.pargs.fpm7 = '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 (EEVariables.ee_platform_codename == 'trusty'
                    or EEVariables.ee_platform_codename
                    == 'bionic') and EEAptGet.is_installed(self, 'php7.2-fpm'):
                self.app.pargs.php7 = 'off'
                self.app.pargs.fpm7 = '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.php7) and (not self.app.pargs.fpm)
                and (not self.app.pargs.fpm7) 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.php7:
            self.debug_php7()
        if self.app.pargs.fpm7:
            self.debug_fpm7()
        if self.app.pargs.mysql:
            # MySQL debug will not work for remote MySQL
            if EEVariables.ee_mysql_host is "localhost":
                self.debug_mysql()
            else:
                Log.warn(
                    self, "Remote MySQL found, EasyEngine will not "
                    "enable remote debug")
        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:
            EEService.reload_service(self, 'nginx')
        # Reload PHP
        if self.trigger_php:
            if (EEVariables.ee_platform_codename == 'trusty'
                    or EEVariables.ee_platform_codename == 'bionic'):
                if EEAptGet.is_installed(self, 'php5.6-fpm'):
                    EEService.restart_service(self, 'php5.6-fpm')
                if EEAptGet.is_installed(self, 'php7.2-fpm'):
                    EEService.restart_service(self, 'php7.2-fpm')
            else:
                EEService.restart_service(self, 'php5-fpm')
                if EEVariables.ee_platform_codename == 'jessie':
                    EEService.restart_service(self, 'php7.2-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)
Example #33
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.postfix or self.app.pargs.hhvm
                or self.app.pargs.memcache or self.app.pargs.dovecot
                or self.app.pargs.redis):
            self.app.pargs.nginx = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True
            self.app.pargs.postfix = True

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

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

                if EEAptGet.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 (EEVariables.ee_platform_codename == 'trusty'
                    or EEVariables.ee_platform_codename == 'xenial'
                    or EEVariables.ee_platform_codename == 'bionic'):
                if EEAptGet.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 ((EEVariables.ee_mysql_host is "localhost")
                    or (EEVariables.ee_mysql_host is "127.0.0.1")):
                if (EEAptGet.is_installed(self, 'mysql-server')
                        or EEAptGet.is_installed(self,
                                                 'percona-server-server-5.6')
                        or EEAptGet.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.postfix:
            if EEAptGet.is_installed(self, 'postfix'):
                services = services + ['postfix']
            else:
                Log.info(self, "Postfix is not installed")

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

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

        if self.app.pargs.dovecot:
            if EEAptGet.is_installed(self, 'dovecot-core'):
                services = services + ['dovecot']
            else:
                Log.info(self, "Mail server is not installed")

        if self.app.pargs.redis:
            if EEAptGet.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))
            EEService.reload_service(self, service)
Example #34
0
    def stop(self):
        """Stop services"""
        services = []
        if not (self.app.pargs.nginx or self.app.pargs.php
                or self.app.pargs.mysql or self.app.pargs.postfix
                or self.app.pargs.hhvm or self.app.pargs.memcache
                or self.app.pargs.dovecot or self.app.pargs.redis):
            self.app.pargs.nginx = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True
            self.app.pargs.postfix = True

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

        if self.app.pargs.php:
            if EEAptGet.is_installed(self, 'php5-fpm'):
                services = services + ['php5-fpm']
            else:
                Log.info(self, "PHP5-FPM is not installed")

        if self.app.pargs.mysql:
            if ((EEVariables.ee_mysql_host is "localhost")
                    or (EEVariables.ee_mysql_host is "127.0.0.1")):
                if (EEAptGet.is_installed(self, 'mysql-server')
                        or EEAptGet.is_installed(self,
                                                 'percona-server-server-5.6')
                        or EEAptGet.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.postfix:
            if EEAptGet.is_installed(self, 'postfix'):
                services = services + ['postfix']
            else:
                Log.info(self, "Postfix is not installed")

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

        if self.app.pargs.dovecot:
            if EEAptGet.is_installed(self, 'dovecot-core'):
                services = services + ['dovecot']
            else:
                Log.info(self, "Mail server is not installed")

        if self.app.pargs.redis:
            if EEAptGet.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))
            EEService.stop_service(self, service)
def site_package_check(self, stype):
    apt_packages = []
    packages = []
    stack = EEStackController()
    stack.app = self.app
    if stype in ["html", "proxy", "php", "mysql", "wp", "wpsubdir", "wpsubdomain"]:
        Log.debug(self, "Setting apt_packages variable for Nginx")

        # Check if server has nginx-custom package
        if not EEAptGet.is_installed(self, "nginx-custom"):
            # check if Server has nginx-plus installed
            if EEAptGet.is_installed(self, "nginx-plus"):
                # do something
                # do post nginx installation configuration
                Log.info(self, "NGINX PLUS Detected ...")
                apt = ["nginx-plus"] + EEVariables.ee_nginx
                # apt_packages = apt_packages + EEVariables.ee_nginx
                stack.post_pref(apt, packages)

            else:
                apt_packages = apt_packages + EEVariables.ee_nginx
        else:
            # Fix for Nginx white screen death
            if not EEFileUtils.grep(self, "/etc/nginx/fastcgi_params", "SCRIPT_FILENAME"):
                with open("/etc/nginx/fastcgi_params", encoding="utf-8", mode="a") as ee_nginx:
                    ee_nginx.write("fastcgi_param \tSCRIPT_FILENAME " "\t$request_filename;\n")

    if stype in ["php", "mysql", "wp", "wpsubdir", "wpsubdomain"]:
        Log.debug(self, "Setting apt_packages variable for PHP")
        if not EEAptGet.is_installed(self, "php5-fpm"):
            apt_packages = apt_packages + EEVariables.ee_php

    if stype in ["mysql", "wp", "wpsubdir", "wpsubdomain"]:
        Log.debug(self, "Setting apt_packages variable for MySQL")
        if not EEShellExec.cmd_exec(self, "mysqladmin ping"):
            apt_packages = apt_packages + EEVariables.ee_mysql
            packages = packages + [
                [
                    "https://raw.githubusercontent.com/" "major/MySQLTuner-perl/master/" "mysqltuner.pl",
                    "/usr/bin/mysqltuner",
                    "MySQLTuner",
                ]
            ]

    if stype in ["php", "mysql", "wp", "wpsubdir", "wpsubdomain"]:
        Log.debug(self, "Setting apt_packages variable for Postfix")
        if not EEAptGet.is_installed(self, "postfix"):
            apt_packages = apt_packages + EEVariables.ee_postfix

    if stype in ["wp", "wpsubdir", "wpsubdomain"]:
        Log.debug(self, "Setting packages variable for WP-CLI")
        if not EEShellExec.cmd_exec(self, "which wp"):
            packages = packages + [
                [
                    "https://github.com/wp-cli/wp-cli/"
                    "releases/download/v{0}/"
                    "wp-cli-{0}.phar".format(EEVariables.ee_wp_cli),
                    "/usr/bin/wp",
                    "WP-CLI",
                ]
            ]
    if self.app.pargs.wpredis:
        Log.debug(self, "Setting apt_packages variable for redis")
        if not EEAptGet.is_installed(self, "redis-server"):
            apt_packages = apt_packages + EEVariables.ee_redis

        if os.path.isfile("/etc/nginx/nginx.conf") and (not os.path.isfile("/etc/nginx/common/redis.conf")):

            data = dict()
            Log.debug(self, "Writting the nginx configuration to " "file /etc/nginx/common/redis.conf")
            ee_nginx = open("/etc/nginx/common/redis.conf", encoding="utf-8", mode="w")
            self.app.render((data), "redis.mustache", out=ee_nginx)
            ee_nginx.close()

        if os.path.isfile("/etc/nginx/nginx.conf") and (not os.path.isfile("/etc/nginx/common/redis-hhvm.conf")):

            data = dict()
            Log.debug(self, "Writting the nginx configuration to " "file /etc/nginx/common/redis-hhvm.conf")
            ee_nginx = open("/etc/nginx/common/redis-hhvm.conf", encoding="utf-8", mode="w")
            self.app.render((data), "redis-hhvm.mustache", out=ee_nginx)
            ee_nginx.close()

        if os.path.isfile("/etc/nginx/conf.d/upstream.conf"):
            if not EEFileUtils.grep(self, "/etc/nginx/conf.d/" "upstream.conf", "redis"):
                with open("/etc/nginx/conf.d/upstream.conf", "a") as redis_file:
                    redis_file.write("upstream redis {\n" "    server 127.0.0.1:6379;\n" "    keepalive 10;\n}")

        if os.path.isfile("/etc/nginx/nginx.conf") and (not os.path.isfile("/etc/nginx/conf.d/redis.conf")):
            with open("/etc/nginx/conf.d/redis.conf", "a") as redis_file:
                redis_file.write(
                    "# Log format Settings\n"
                    "log_format rt_cache_redis '$remote_addr $upstream_response_time $srcache_fetch_status [$time_local] '\n"
                    "'$http_host \"$request\" $status $body_bytes_sent '\n"
                    '\'"$http_referer" "$http_user_agent"\';\n'
                )

    if self.app.pargs.hhvm:
        if platform.architecture()[0] is "32bit":
            Log.error(self, "HHVM is not supported by 32bit system")
        Log.debug(self, "Setting apt_packages variable for HHVM")
        if not EEAptGet.is_installed(self, "hhvm"):
            apt_packages = apt_packages + EEVariables.ee_hhvm

        if os.path.isdir("/etc/nginx/common") and (not os.path.isfile("/etc/nginx/common/php-hhvm.conf")):
            data = dict()
            Log.debug(self, "Writting the nginx configuration to " "file /etc/nginx/common/php-hhvm.conf")
            ee_nginx = open("/etc/nginx/common/php-hhvm.conf", encoding="utf-8", mode="w")
            self.app.render((data), "php-hhvm.mustache", out=ee_nginx)
            ee_nginx.close()

            Log.debug(self, "Writting the nginx configuration to " "file /etc/nginx/common/w3tc-hhvm.conf")
            ee_nginx = open("/etc/nginx/common/w3tc-hhvm.conf", encoding="utf-8", mode="w")
            self.app.render((data), "w3tc-hhvm.mustache", out=ee_nginx)
            ee_nginx.close()

            Log.debug(self, "Writting the nginx configuration to " "file /etc/nginx/common/wpfc-hhvm.conf")
            ee_nginx = open("/etc/nginx/common/wpfc-hhvm.conf", encoding="utf-8", mode="w")
            self.app.render((data), "wpfc-hhvm.mustache", out=ee_nginx)
            ee_nginx.close()

            Log.debug(self, "Writting the nginx configuration to " "file /etc/nginx/common/wpsc-hhvm.conf")
            ee_nginx = open("/etc/nginx/common/wpsc-hhvm.conf", encoding="utf-8", mode="w")
            self.app.render((data), "wpsc-hhvm.mustache", out=ee_nginx)
            ee_nginx.close()

        if os.path.isfile("/etc/nginx/conf.d/upstream.conf"):
            if not EEFileUtils.grep(self, "/etc/nginx/conf.d/upstream.conf", "hhvm"):
                with open("/etc/nginx/conf.d/upstream.conf", "a") as hhvm_file:
                    hhvm_file.write("upstream hhvm {\nserver 127.0.0.1:8000;\n" "server 127.0.0.1:9000 backup;\n}\n")

    # Check if Nginx is allready installed and Pagespeed config there or not
    # If not then copy pagespeed config
    if self.app.pargs.pagespeed:
        if os.path.isfile("/etc/nginx/nginx.conf") and (not os.path.isfile("/etc/nginx/conf.d/pagespeed.conf")):
            # Pagespeed configuration
            data = dict()
            Log.debug(
                self, "Writting the Pagespeed Global " "configuration to file /etc/nginx/conf.d/" "pagespeed.conf"
            )
            ee_nginx = open("/etc/nginx/conf.d/pagespeed.conf", encoding="utf-8", mode="w")
            self.app.render((data), "pagespeed-global.mustache", out=ee_nginx)
            ee_nginx.close()

    return stack.install(apt_packages=apt_packages, packages=packages, disp_msg=False)
Example #36
0
    def default(self):
        # All package update
        if ((not self.app.pargs.php56)):

            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")

            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.postfix) and (not self.app.pargs.hhvm) and
               (not self.app.pargs.mailscanner) and (not self.app.pargs.all)):
                self.app.pargs.web = True

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

            if self.app.pargs.web:
                self.app.pargs.nginx = True
                self.app.pargs.php = True
                self.app.pargs.mysql = True
                self.app.pargs.postfix = True
                self.app.pargs.hhvm = True

            if self.app.pargs.mail:
                self.app.pargs.nginx = True
                self.app.pargs.php = True
                self.app.pargs.mysql = True
                self.app.pargs.postfix = True

                if EEAptGet.is_installed(self, 'dovecot-core'):
                    apt_packages = apt_packages + EEVariables.ee_mail
                    self.app.pargs.mailscanner = True
                else:
                    Log.info(self, "Mail server is not installed")

            if self.app.pargs.nginx:
                if EEAptGet.is_installed(self, 'nginx-custom'):
                    apt_packages = apt_packages + EEVariables.ee_nginx
                else:
                    Log.info(self, "Nginx is not already installed")

            if self.app.pargs.php:
                if EEAptGet.is_installed(self, 'php5-fpm'):
                    apt_packages = apt_packages + EEVariables.ee_php
                else:
                    Log.info(self, "PHP is not installed")

            if self.app.pargs.hhvm:
                if EEAptGet.is_installed(self, 'hhvm'):
                    apt_packages = apt_packages + EEVariables.ee_hhvm
                else:
                    Log.info(self, "HHVM is not installed")

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

            if self.app.pargs.postfix:
                if EEAptGet.is_installed(self, 'postfix'):
                    apt_packages = apt_packages + EEVariables.ee_postfix
                else:
                    Log.info(self, "Postfix is not installed")

            if self.app.pargs.mailscanner:
                if EEAptGet.is_installed(self, 'amavisd-new'):
                    apt_packages = (apt_packages + EEVariables.ee_mailscanner)
                else:
                    Log.info(self, "MailScanner is not installed")

            if len(apt_packages):
                # apt-get update
                EEAptGet.update(self)

                # Update packages
                Log.info(self, "Updating packages, please wait...")
                EEAptGet.install(self, apt_packages)
                Log.info(self, "Successfully updated packages")

            # Post Actions after package updates
            if set(EEVariables.ee_nginx).issubset(set(apt_packages)):
                EEService.restart_service(self, 'nginx')
            if set(EEVariables.ee_php).issubset(set(apt_packages)):
                EEService.restart_service(self, 'php5-fpm')
            if set(EEVariables.ee_hhvm).issubset(set(apt_packages)):
                EEService.restart_service(self, 'hhvm')
            if set(EEVariables.ee_postfix).issubset(set(apt_packages)):
                EEService.restart_service(self, 'postfix')
            if set(EEVariables.ee_mysql).issubset(set(apt_packages)):
                EEService.restart_service(self, 'hhvm')
            if set(EEVariables.ee_mail).issubset(set(apt_packages)):
                EEService.restart_service(self, 'dovecot')

        # PHP 5.6 to 5.6
        elif (self.app.pargs.php56):
            self.upgrade_php56()
        else:
            self.app.args.print_help()
Example #37
0
def site_package_check(self, stype):
    apt_packages = []
    packages = []
    stack = EEStackController()
    stack.app = self.app
    if stype in ['html', 'proxy', 'php', 'mysql', 'wp', 'wpsubdir',
                 'wpsubdomain']:
        Log.debug(self, "Setting apt_packages variable for Nginx")

        if EEVariables.ee_platform_distro == 'debian':
            check_nginx = 'nginx-extras'
        else:
            check_nginx = 'nginx-custom'

        if not EEAptGet.is_installed(self, check_nginx):
            apt_packages = apt_packages + EEVariables.ee_nginx

    if stype in ['php', 'mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
        Log.debug(self, "Setting apt_packages variable for PHP")
        if not EEAptGet.is_installed(self, 'php5-fpm'):
            apt_packages = apt_packages + EEVariables.ee_php

    if stype in ['mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
        Log.debug(self, "Setting apt_packages variable for MySQL")
        if not EEShellExec.cmd_exec(self, "mysqladmin ping"):
            apt_packages = apt_packages + EEVariables.ee_mysql

    if stype in ['php', 'mysql', 'wp', 'wpsubdir', 'wpsubdomain']:
        Log.debug(self, "Setting apt_packages variable for Postfix")
        if not EEAptGet.is_installed(self, 'postfix'):
            apt_packages = apt_packages + EEVariables.ee_postfix

    if stype in ['wp', 'wpsubdir', 'wpsubdomain']:
        Log.debug(self, "Setting packages variable for WP-CLI")
        if not EEShellExec.cmd_exec(self, "which wp"):
            packages = packages + [["https://github.com/wp-cli/wp-cli/"
                                    "releases/download/v{0}/"
                                    "wp-cli-{0}.phar"
                                    .format(EEVariables.ee_wp_cli),
                                    "/usr/bin/wp", "WP-CLI"]]

    if self.app.pargs.hhvm:
        Log.debug(self, "Setting apt_packages variable for HHVM")
        if not EEAptGet.is_installed(self, 'hhvm'):
            apt_packages = apt_packages + EEVariables.ee_hhvm

        if os.path.isdir("/etc/nginx/common") and (not
           os.path.isfile("/etc/nginx/common/php-hhvm.conf")):
            data = dict()
            Log.debug(self, 'Writting the nginx configuration to '
                      'file /etc/nginx/common/php-hhvm.conf')
            ee_nginx = open('/etc/nginx/common/php-hhvm.conf',
                            encoding='utf-8', mode='w')
            self.app.render((data), 'php-hhvm.mustache',
                            out=ee_nginx)
            ee_nginx.close()

            Log.debug(self, 'Writting the nginx configuration to '
                      'file /etc/nginx/common/w3tc-hhvm.conf')
            ee_nginx = open('/etc/nginx/common/w3tc-hhvm.conf',
                            encoding='utf-8', mode='w')
            self.app.render((data), 'w3tc-hhvm.mustache', out=ee_nginx)
            ee_nginx.close()

            Log.debug(self, 'Writting the nginx configuration to '
                      'file /etc/nginx/common/wpfc-hhvm.conf')
            ee_nginx = open('/etc/nginx/common/wpfc-hhvm.conf',
                            encoding='utf-8', mode='w')
            self.app.render((data), 'wpfc-hhvm.mustache',
                            out=ee_nginx)
            ee_nginx.close()

            Log.debug(self, 'Writting the nginx configuration to '
                      'file /etc/nginx/common/wpsc-hhvm.conf')
            ee_nginx = open('/etc/nginx/common/wpsc-hhvm.conf',
                            encoding='utf-8', mode='w')
            self.app.render((data), 'wpsc-hhvm.mustache',
                            out=ee_nginx)
            ee_nginx.close()

    # Check if Nginx is allready installed and Pagespeed config there or not
    # If not then copy pagespeed config
    if self.app.pargs.pagespeed:
        if (os.path.isfile('/etc/nginx/nginx.conf') and
           (not os.path.isfile('/etc/nginx/conf.d/pagespeed.conf'))):
            # Pagespeed configuration
            data = dict()
            Log.debug(self, 'Writting the Pagespeed Global '
                      'configuration to file /etc/nginx/conf.d/'
                      'pagespeed.conf')
            ee_nginx = open('/etc/nginx/conf.d/pagespeed.conf',
                            encoding='utf-8', mode='w')
            self.app.render((data), 'pagespeed-global.mustache',
                            out=ee_nginx)
            ee_nginx.close()

    return(stack.install(apt_packages=apt_packages, packages=packages,
                         disp_msg=False))
Example #38
0
    def stop(self):
        """Stop services"""
        services = []
        if not (self.app.pargs.nginx or self.app.pargs.php
                or self.app.pargs.mysql or self.app.pargs.postfix
                or self.app.pargs.hhvm or self.app.pargs.memcache
                or self.app.pargs.dovecot or self.app.pargs.redis):
            self.app.pargs.nginx = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True
            self.app.pargs.postfix = True

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

        if self.app.pargs.php:
            if EEAptGet.is_installed(self, 'php5-fpm'):
                services = services + ['php5-fpm']
            else:
                Log.info(self, "PHP5-FPM is not installed")

        if self.app.pargs.mysql:
            if ((EEVariables.ee_mysql_host is "localhost") or
               (EEVariables.ee_mysql_host is "127.0.0.1")):
                if (EEAptGet.is_installed(self, 'mysql-server') or
                   EEAptGet.is_installed(self, 'percona-server-server-5.6') or
                   EEAptGet.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.postfix:
            if EEAptGet.is_installed(self, 'postfix'):
                services = services + ['postfix']
            else:
                Log.info(self, "Postfix is not installed")

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

        if self.app.pargs.dovecot:
            if EEAptGet.is_installed(self, 'dovecot-core'):
                services = services + ['dovecot']
            else:
                Log.info(self, "Mail server is not installed")

        if self.app.pargs.redis:
            if EEAptGet.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))
            EEService.stop_service(self, service)