Пример #1
0
    def default(self):
        """default function for info"""
        if (not self.app.pargs.apache2 and not self.app.pargs.php
                and not self.app.pargs.mysql):
            self.app.pargs.apache2 = False
            self.app.pargs.php = True
            self.app.pargs.mysql = True

        if self.app.pargs.apache2:
            if SSSAptGet.is_installed(self, 'apache2'):
                self.info_apache2()
            else:
                Log.error(self, "Apache is not installed")

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

        if self.app.pargs.mysql:
            if SSSShellExec.cmd_exec(self, "mysqladmin ping"):
                self.info_mysql()
            else:
                Log.error(self, "MySQL is not installed")
    def add(self):
        """Swap addition with SimpleSetupServer"""
        if SSSVariables.sss_ram < 512:
            if SSSVariables.sss_swap < 1000:
                Log.info(self, "Adding SWAP file, please wait...")

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

                # Modify Swap configuration
                if os.path.isfile("/etc/dphys-swapfile"):
                    SSSFileUtils.searchreplace(self, "/etc/dphys-swapfile",
                                               "#CONF_SWAPFILE=/var/swap",
                                               "CONF_SWAPFILE=/sss-swapfile")
                    SSSFileUtils.searchreplace(self, "/etc/dphys-swapfile",
                                               "#CONF_MAXSWAP=2048",
                                               "CONF_MAXSWAP=1024")
                    SSSFileUtils.searchreplace(self, "/etc/dphys-swapfile",
                                               "#CONF_SWAPSIZE=",
                                               "CONF_SWAPSIZE=1024")
                else:
                    with open("/etc/dphys-swapfile", 'w') as conffile:
                        conffile.write("CONF_SWAPFILE=/sss-swapfile\n"
                                       "CONF_SWAPSIZE=1024\n"
                                       "CONF_MAXSWAP=1024\n")
                # Create swap file
                SSSShellExec.cmd_exec(self, "service dphys-swapfile start")
    def default(self):
        """default function for info"""
        if (not self.app.pargs.apache2 and not self.app.pargs.php
           and not self.app.pargs.mysql):
            self.app.pargs.apache2 = False
            self.app.pargs.php = True
            self.app.pargs.mysql = True

        if self.app.pargs.apache2:
            if SSSAptGet.is_installed(self, 'apache2'):
                self.info_apache2()
            else:
                Log.error(self, "Apache is not installed")

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

        if self.app.pargs.mysql:
            if SSSShellExec.cmd_exec(self, "mysqladmin ping"):
                self.info_mysql()
            else:
                Log.error(self, "MySQL is not installed")
Пример #4
0
def site_package_check(self, stype):
    apt_packages = []
    packages = []
    stack = SSSStackController()
    stack.app = self.app
    if stype in ["html", "php", "mysql"]:
        Log.debug(self, "Setting apt_packages variables for Apache")

        # check if server has apache
        if not SSSAptGet.is_installed(self, "apache2"):
            apt_packages = apt_packages + SSSVariables.sss_apache

    if stype in ["php", "mysql"]:
        Log.debug(self, "Setting apt_packages variables for PHP")

        # check if server has php
        if not SSSAptGet.is_installed(self, "php7.0-fpm"):
            apt_packages = apt_packages + SSSVariables.sss_php

    if stype in ["mysql"]:
        Log.debug(self, "Setting apt_packages variable for MySQL")
        if not SSSShellExec.cmd_exec(self, "mysqladmin ping"):
            apt_packages = apt_packages + SSSVariables.sss_mysql
            packages = packages + [
                [
                    "https://raw." "githubusercontent.com" "/serversetup/tuning-primer/" "master/tuning-primer.sh",
                    "/usr/bin/tuning-primer",
                    "Tuning-Primer",
                ]
            ]

    return stack.install(apt_packages=apt_packages, packages=packages, disp_msg=False)
    def add(self):
        """Swap addition with SimpleSetupServer"""
        if SSSVariables.sss_ram < 512:
            if SSSVariables.sss_swap < 1000:
                Log.info(self, "Adding SWAP file, please wait...")

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

                # Modify Swap configuration
                if os.path.isfile("/etc/dphys-swapfile"):
                    SSSFileUtils.searchreplace(self, "/etc/dphys-swapfile",
                                              "#CONF_SWAPFILE=/var/swap",
                                              "CONF_SWAPFILE=/sss-swapfile")
                    SSSFileUtils.searchreplace(self,  "/etc/dphys-swapfile",
                                              "#CONF_MAXSWAP=2048",
                                              "CONF_MAXSWAP=1024")
                    SSSFileUtils.searchreplace(self,  "/etc/dphys-swapfile",
                                              "#CONF_SWAPSIZE=",
                                              "CONF_SWAPSIZE=1024")
                else:
                    with open("/etc/dphys-swapfile", 'w') as conffile:
                        conffile.write("CONF_SWAPFILE=/sss-swapfile\n"
                                       "CONF_SWAPSIZE=1024\n"
                                       "CONF_MAXSWAP=1024\n")
                # Create swap file
                SSSShellExec.cmd_exec(self, "service dphys-swapfile start")
    def default(self):
        if ((not self.app.pargs.mariadb)):
            self.app.args.print_help()
        if self.app.pargs.mariadb:
            if SSSVariables.sss_mysql_host is not "localhost":
                Log.error(
                    self, "Remote MySQL found, EasyEngine will not "
                    "install MariaDB")

            if SSSShellExec.cmd_exec(self, "mysqladmin ping") and (
                    not SSSAptGet.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 Apache 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")
def site_package_check(self, stype):
    apt_packages = []
    packages = []
    stack = SSSStackController()
    stack.app = self.app
    if stype in ['html', 'php', 'mysql']:
        Log.debug(self, "Setting apt_packages variables for Apache")

        # check if server has apache
        if not SSSAptGet.is_installed(self, 'apache2'):
            apt_packages = apt_packages + SSSVariables.sss_apache

    if stype in ['php', 'mysql']:
        Log.debug(self, "Setting apt_packages variables for PHP")

        # check if server has php
        if not SSSAptGet.is_installed(self, 'php7.0-fpm'):
            apt_packages = apt_packages + SSSVariables.sss_php

    if stype in ['phpmyadmin']:
        Log.debug(self, "Setting apt_packages varible for phpMyAdmin")

        if not SSSAptGet.is_installed(self, 'phpmyadmin'):
            apt_packages = apt_packages + SSSVariables.sss_pma

    if stype in ['mysql']:
        Log.debug(self, "Setting apt_packages variable for MySQL")
        if not SSSShellExec.cmd_exec(self, "mysqladmin ping"):
            apt_packages = apt_packages + SSSVariables.sss_mysql
            packages = packages + [[
                "https://raw."
                "githubusercontent.com"
                "/serversetup/tuning-primer/"
                "master/tuning-primer.sh", "/usr/bin/tuning-primer",
                "Tuning-Primer"
            ]]

    return (stack.install(apt_packages=apt_packages,
                          packages=packages,
                          disp_msg=False))
Пример #8
0
    def remove(self):
        """Start removal of packages"""
        apt_packages = []
        packages = []

        # Default action for stack remove
        if ((not self.app.pargs.web) and (not self.app.pargs.apache2)
                and (not self.app.pargs.php) and (not self.app.pargs.mysql)):
            self.app.pargs.web = True
            self.app.pargs.apache2 = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True

        if self.app.pargs.all:
            self.app.pargs.web = True
            self.app.pargs.apache2 = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True

        if self.app.pargs.web:
            self.app.pargs.apache2 = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True
            #self.app.pargs.wpcli = True
            #self.app.pargs.postfix = True

        if self.app.pargs.apache2:
            Log.debug(self, "Removing apt_packages variable of Apache")
            apt_packages = apt_packages + SSSVariables.sss_apache
        if self.app.pargs.php:
            Log.debug(self, "Removing apt_packages variable of PHP")
            apt_packages = apt_packages + SSSVariables.sss_php
        if self.app.pargs.mysql:
            Log.debug(self, "Removing apt_packages variable of PHP")
            apt_packages = apt_packages + SSSVariables.sss_mysql
            packages = packages + ['/usr/bin/tuning-primer']

        if len(packages) or len(apt_packages):
            sss_prompt = input('Are you sure you to want to'
                               ' remove from server.'
                               '\nPackage configuration will remain'
                               ' on server after this operation.\n'
                               'Any answer other than '
                               '"yes" will be stop this'
                               ' operation :  ')

        if sss_prompt == 'YES' or sss_prompt == 'yes':
            if len(packages):
                SSSFileUtils.remove(self, packages)
                SSSAptGet.auto_remove(self)

            if len(apt_packages):
                Log.debug(self, "Removing apt_packages")
                Log.info(self, "Removing packages, please wait...")
                SSSAptGet.remove(self, apt_packages)
                SSSAptGet.auto_remove(self)

            Log.info(self, "Successfully removed packages")
    def remove(self):
        """Start removal of packages"""
        apt_packages = []
        packages = []

        # Default action for stack remove
        if ((not self.app.pargs.web) and (not self.app.pargs.apache2) and
            (not self.app.pargs.php) and (not self.app.pargs.mysql)):
                self.app.pargs.web = True
                self.app.pargs.apache2 = True
                self.app.pargs.php = True
                self.app.pargs.mysql = True

        if self.app.pargs.all:
            self.app.pargs.web = True
            self.app.pargs.apache2 = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True

        if self.app.pargs.web:
            self.app.pargs.apache2 = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True
            #self.app.pargs.wpcli = True
            #self.app.pargs.postfix = True

        if self.app.pargs.apache2:
            Log.debug(self,"Removing apt_packages variable of Apache")
            apt_packages = apt_packages + SSSVariables.sss_apache
        if self.app.pargs.php:
            Log.debug(self,"Removing apt_packages variable of PHP")
            apt_packages = apt_packages + SSSVariables.sss_php
        if self.app.pargs.mysql:
            Log.debug(self,"Removing apt_packages variable of PHP")
            apt_packages = apt_packages + SSSVariables.sss_mysql
            packages = packages + ['/usr/bin/tuning-primer']

        if len(packages) or len(apt_packages):
            sss_prompt = input('Are you sure you to want to'
                          ' remove from server.'
                          '\nPackage configuration will remain'
                          ' on server after this operation.\n'
                          'Any answer other than '
                          '"yes" will be stop this'
                          ' operation :  ')

        if sss_prompt == 'YES' or sss_prompt == 'yes':
            if len(packages):
                SSSFileUtils.remove(self, packages)
                SSSAptGet.auto_remove(self)

            if len(apt_packages):
                Log.debug(self, "Removing apt_packages")
                Log.info(self, "Removing packages, please wait...")
                SSSAptGet.remove(self, apt_packages)
                SSSAptGet.auto_remove(self)

            Log.info(self, "Successfully removed packages")
Пример #10
0
    def default(self):
        if not self.app.pargs.mariadb:
            self.app.args.print_help()
        if self.app.pargs.mariadb:
            if SSSVariables.sss_mysql_host is not "localhost":
                Log.error(self, "Remote MySQL found, EasyEngine will not " "install MariaDB")

            if SSSShellExec.cmd_exec(self, "mysqladmin ping") and (not SSSAptGet.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 Apache 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")
    def stop(self):
        """Stop services"""
        services = []
        if not (self.app.pargs.apache2 or self.app.pargs.php
                or self.app.pargs.mysql or self.app.pargs.memcache):
            self.app.pargs.apache2 = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True

        if self.app.pargs.apache2:
            if SSSAptGet.is_installed(self, 'apache2'):
                services = services + ['apache2']
            else:
                Log.info(self, 'Apache is not installed')

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

        if self.app.pargs.mysql:
            if ((SSSVariables.sss_mysql_host is "localhost")
                    or (SSSVariables.sss_mysql_host is "127.0.0.1")):
                if (SSSAptGet.is_installed(self, 'mysql-server')
                        or SSSAptGet.is_installed(self,
                                                  'percona-server-server-5.6')
                        or SSSAptGet.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.memcache:
            if SSSAptGet.is_installed(self, 'memcached'):
                services = services + ['memcached']
            else:
                Log.info(self, "Memcache is not installed")

        for service in services:
            Log.debug(self, "Stopping service: {0}".format(service))
            SSSService.stop_service(self, service)
    def stop(self):
        """Stop services"""
        services = []
        if not (self.app.pargs.apache2 or self.app.pargs.php
                or self.app.pargs.mysql or self.app.pargs.memcache):
            self.app.pargs.apache2 = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True

        if self.app.pargs.apache2:
            if SSSAptGet.is_installed(self,'apache2'):
                services = services + ['apache2']
            else:
                Log.info(self,'Apache is not installed')

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

        if self.app.pargs.mysql:
            if ((SSSVariables.sss_mysql_host is "localhost") or
               (SSSVariables.sss_mysql_host is "127.0.0.1")):
                if (SSSAptGet.is_installed(self, 'mysql-server') or
                   SSSAptGet.is_installed(self, 'percona-server-server-5.6') or
                   SSSAptGet.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.memcache:
            if SSSAptGet.is_installed(self, 'memcached'):
                services = services + ['memcached']
            else:
                Log.info(self, "Memcache is not installed")

        for service in services:
            Log.debug(self, "Stopping service: {0}".format(service))
            SSSService.stop_service(self, service)
Пример #13
0
    def migrate_mariadb(self):
        # Backup all database
        SSSMysql.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)

        SSSRepo.add(self, repo_url=SSSVariables.sss_mysql_repo)
        Log.debug(self, "Adding key for {0}".format(SSSVariables.sss_mysql_repo))
        SSSRepo.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"
        )
        SSSShellExec.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",
        )
        SSSShellExec.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 = SSSVariables.sss_mysql

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

        # If mail server is installed then install dovecot-sql and postfix-sql
        if SSSAptGet.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...")
        SSSAptGet.update(self)
        Log.info(self, "Installing MariaDB, please wait...")
        SSSAptGet.remove(self, ["mysql-common", "libmysqlclient18"])
        SSSAptGet.auto_remove(self)
        SSSAptGet.install(self, apt_packages)

        # Restart  dovecot and postfix if installed
        if SSSAptGet.is_installed(self, "dovecot-core"):
            SSSService.restart_service(self, "dovecot")
            SSSService.restart_service(self, "postfix")
    def migrate_mariadb(self):
        # Backup all database
        SSSMysql.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)

        SSSRepo.add(self, repo_url=SSSVariables.sss_mysql_repo)
        Log.debug(self,
                  'Adding key for {0}'.format(SSSVariables.sss_mysql_repo))
        SSSRepo.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")
        SSSShellExec.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")
        SSSShellExec.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 = SSSVariables.sss_mysql

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

        # If mail server is installed then install dovecot-sql and postfix-sql
        if SSSAptGet.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...")
        SSSAptGet.update(self)
        Log.info(self, "Installing MariaDB, please wait...")
        SSSAptGet.remove(self, ["mysql-common", "libmysqlclient18"])
        SSSAptGet.auto_remove(self)
        SSSAptGet.install(self, apt_packages)

        # Restart  dovecot and postfix if installed
        if SSSAptGet.is_installed(self, "dovecot-core"):
            SSSService.restart_service(self, 'dovecot')
            SSSService.restart_service(self, 'postfix')
Пример #15
0
    def default(self):
        # All package update
        apt_packages = []
        packages = []

        if ((not self.app.pargs.web) and (not self.app.pargs.apache2)
                and (not self.app.pargs.php) and (not self.app.pargs.mysql)
                and (not self.app.pargs.all)):
            self.app.pargs.web = True

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

        if self.app.pargs.web:
            self.app.pargs.apache2 = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True

        if self.app.pargs.apache2:
            if SSSAptGet.is_installed(self, 'apache2'):
                apt_packages = apt_packages + SSSVariables.sss_apache
            else:
                Log.info(self, "Apache is not already installed")

        if self.app.pargs.php:
            if SSSAptGet.is_installed(self, 'php7.0-fpm'):
                apt_packages = apt_packages + SSSVariables.sss_php
            else:
                Log.info(self, "PHP is not installed")

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

        if len(packages) or len(apt_packages):

            Log.info(
                self, "During package update process non Apache"
                " 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
                SSSAptGet.update(self)
                # Update packages
                SSSAptGet.install(self, apt_packages)

                # Post Actions after package updates
                if set(SSSVariables.sss_apache).issubset(set(apt_packages)):
                    SSSService.restart_service(self, 'apache2')
                if set(SSSVariables.sss_php).issubset(set(apt_packages)):
                    SSSService.restart_service(self, 'php7.0-fpm')
                if set(SSSVariables.sss_mysql).issubset(set(apt_packages)):
                    SSSService.restart_service(self, 'mysql')

            if len(packages):
                pass
            Log.info(self, "Successfully updated packages")
Пример #16
0
    def purge(self):
        """Start purging of packages"""
        apt_packages = []
        packages = []

        # Default action for stack remove
        if ((not self.app.pargs.web) and (not self.app.pargs.apache2) and
            (not self.app.pargs.php) and (not self.app.pargs.mysql) and
            (not self.app.pargs.phpmyadmin)):
                self.app.pargs.web = True
                self.app.pargs.apache2 = True
                self.app.pargs.php = True
                self.app.pargs.mysql = True

        if self.app.pargs.all:
            self.app.pargs.web = True
            self.app.pargs.apache2 = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True

        if self.app.pargs.web:
            self.app.pargs.apache2 = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True
            #self.app.pargs.wpcli = True
            #self.app.pargs.postfix = True

        if self.app.pargs.apache2:
            Log.debug(self, "Purge apt_packages variable of Apache")
            apt_packages = apt_packages + SSSVariables.sss_apache
        if self.app.pargs.php:
            Log.debug(self, "Purge apt_packages variable PHP")
            apt_packages = apt_packages + SSSVariables.sss_php
        if self.app.pargs.mysql:
            Log.debug(self,"Removing apt_packages variable of PHP")
            apt_packages = apt_packages + SSSVariables.sss_mysql
            packages = packages + ['/usr/bin/tuning-primer']
        if self.app.pargs.phpmyadmin:
            packages = packages + ['{0}22222/htdocs/db/pma'.
                                   format(SSSVariables.sss_webroot)]
            Log.debug(self, "Purge package variable phpMyAdmin")

        if len(packages) or len(apt_packages):
            sss_prompt = input('Are you sure you to want to purge '
                              'from server '
                              'along with their configuration'
                              ' packages,\nAny answer other than '
                              '"yes" will be stop this '
                              'operation :')

            if sss_prompt == 'YES' or sss_prompt == 'yes':
                if len(apt_packages):
                    Log.info(self, "Purging packages, please wait...")
                    SSSAptGet.remove(self, apt_packages, purge=True)
                    SSSAptGet.auto_remove(self)

                if len(packages):
                    SSSFileUtils.remove(self, packages)
                    SSSAptGet.auto_remove(self)

                Log.info(self, "Successfully purged packages")
Пример #17
0
    def install(self, packages=[], apt_packages=[], disp_msg=True):
        """Start installation of packages"""
        self.msg = []
        try:
            # Default action for stack installation
            if ((not self.app.pargs.web) and (not self.app.pargs.apache2) and
                (not self.app.pargs.php) and (not self.app.pargs.mysql) and 
                (not self.app.pargs.phpmyadmin)):
                self.app.pargs.web = True
                self.app.pargs.apache2 = True
                self.app.pargs.php = True
                self.app.pargs.mysql = True

            if self.app.pargs.all:
                self.app.pargs.web = True
                self.app.pargs.apache2 = True
                self.app.pargs.php = True
                #self.app.pargs.mysql = True

            if self.app.pargs.web:
                self.app.pargs.apache2 = True
                self.app.pargs.php = True
                #self.app.pargs.mysql = True
                #self.app.pargs.wpcli = True
                #self.app.pargs.postfix = True

            if self.app.pargs.apache2:
                Log.debug(self, "Setting apt_packages variable for Apache2")
                if not SSSAptGet.is_installed(self,'apache2'):
                    apt_packages = apt_packages + SSSVariables.sss_apache

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

            if self.app.pargs.php:
                Log.debug(self,"Setting apt_packages variable for PHP")
                if not SSSAptGet.is_installed(self,'php7.0-fpm'):
                    apt_packages = apt_packages + SSSVariables.sss_php
                else:
                    Log.debug(self, "PHP already installed")
                    Log.info(self, "PHP already installed")

            if self.app.pargs.mysql:
                Log.debug(self,"Setting apt_packages variable for MySQL")
                if not SSSShellExec.cmd_exec(self,"mysqladmin ping"):
                    apt_packages = apt_packages + SSSVariables.sss_mysql
                    packages = packages + [["https://raw."
                                            "githubusercontent.com"
                                            "/serversetup/tuning-primer/"
                                            "master/tuning-primer.sh",
                                            "/usr/bin/tuning-primer",
                                            "Tuning-Primer"]]
                else:
                    Log.debug(self, "MySQL connection is already alive")
                    Log.info(self, "MySQL connection is already alive")

            if self.app.pargs.phpmyadmin:
                Log.debug(self, "Setting packages varible for phpMyAdmin ")
                packages = packages + [["https://github.com/phpmyadmin/"
                                        "phpmyadmin/archive/STABLE.tar.gz",
                                        "/tmp/pma.tar.gz", "phpMyAdmin"]]


        except Exception as e:
            pass

        if len(apt_packages) or len(packages):
            Log.debug(self,"Calling pre_pref")
            self.pre_pref(apt_packages)
            if len(apt_packages):
                SSSSwap.add(self)
                Log.info(self, "Updating Apt-cache, please wait...")
                SSSAptGet.update(self)
                Log.info(self, "Installing packages, please wait...")
                SSSAptGet.install(self, apt_packages)
                SSSShellExec.cmd_exec(self, "a2enmod proxy_fcgi proxy proxy_http http2 ssl expires headers rewrite")
            if len(packages):
                Log.debug(self, "Downloading following: {0}".format(packages))
                SSSDownload.download(self, packages)
            Log.debug(self, "Calling post_pref")
            self.post_pref(apt_packages, packages)

            if disp_msg:
                if len(self.msg):
                    for msg in self.msg:
                        Log.info(self, Log.ENDC + msg)
                Log.info(self, "Successfully installed packages")
            else:
                return self.msg
    def default(self):
        # All package update
        apt_packages = []
        packages = []

        if ((not self.app.pargs.web) and (not self.app.pargs.apache2) and
           (not self.app.pargs.php) and (not self.app.pargs.mysql) and
            (not self.app.pargs.all)):
            self.app.pargs.web = True

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

        if self.app.pargs.web:
            self.app.pargs.apache2 = True
            self.app.pargs.php = True
            self.app.pargs.mysql = True

        if self.app.pargs.apache2:
            if SSSAptGet.is_installed(self, 'apache2'):
                apt_packages = apt_packages + SSSVariables.sss_apache
            else:
                Log.info(self, "Apache is not already installed")

        if self.app.pargs.php:
            if SSSAptGet.is_installed(self, 'php7.0-fpm'):
                apt_packages = apt_packages + SSSVariables.sss_php
            else:
                Log.info(self, "PHP is not installed")

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

        if len(packages) or len(apt_packages):

            Log.info(self, "During package update process non Apache"
                     " 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
                SSSAptGet.update(self)
                # Update packages
                SSSAptGet.install(self, apt_packages)

                # Post Actions after package updates
                if set(SSSVariables.sss_apache).issubset(set(apt_packages)):
                    SSSService.restart_service(self, 'apache2')
                if set(SSSVariables.sss_php).issubset(set(apt_packages)):
                    SSSService.restart_service(self, 'php7.0-fpm')
                if set(SSSVariables.sss_mysql).issubset(set(apt_packages)):
                    SSSService.restart_service(self, 'mysql')

            if len(packages):
                pass
            Log.info(self, "Successfully updated packages")
Пример #19
0
    def install(self, packages=[], apt_packages=[], disp_msg=True):
        """Start installation of packages"""
        self.msg = []
        try:
            # Default action for stack installation
            if ((not self.app.pargs.web) and (not self.app.pargs.apache2)
                    and (not self.app.pargs.php)
                    and (not self.app.pargs.mysql)):
                self.app.pargs.web = True
                self.app.pargs.apache2 = True
                self.app.pargs.php = True
                self.app.pargs.mysql = True
                self.app.pargs.phpmyadmin = True

            if self.app.pargs.all:
                self.app.pargs.web = True
                self.app.pargs.apache2 = True
                self.app.pargs.php = True
                self.app.pargs.mysql = True
                self.app.pargs.phpmyadmin = True

            if self.app.pargs.web:
                self.app.pargs.apache2 = True
                self.app.pargs.php = True
                self.app.pargs.mysql = True
                #self.app.pargs.wpcli = True
                #self.app.pargs.postfix = True

            if self.app.pargs.apache2:
                Log.debug(self, "Setting apt_packages variable for Apache2")
                if not SSSAptGet.is_installed(self, 'apache2'):
                    apt_packages = apt_packages + SSSVariables.sss_apache

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

            if self.app.pargs.php:
                Log.debug(self, "Setting apt_packages variable for PHP")
                if not SSSAptGet.is_installed(self, 'php7.0-fpm'):
                    apt_packages = apt_packages + SSSVariables.sss_php
                else:
                    Log.debug(self, "PHP already installed")
                    Log.info(self, "PHP already installed")

            if self.app.pargs.phpmyadmin:
                Log.debug(self, "Setting apt_packages variable for PhpMyadmin")
                if not SSSAptGet.is_installed(self, 'phpmyadmin'):
                    apt_packages = apt_packages + SSSVariables.sss_pma
                else:
                    Log.debug(self, "PhpMyadmin already installed")
                    Log.info(self, "PhpMyadmin already installed")

            if self.app.pargs.mysql:
                Log.debug(self, "Setting apt_packages variable for MySQL")
                if not SSSShellExec.cmd_exec(self, "mysqladmin ping"):
                    apt_packages = apt_packages + SSSVariables.sss_mysql
                    packages = packages + [[
                        "https://raw."
                        "githubusercontent.com"
                        "/serversetup/tuning-primer/"
                        "master/tuning-primer.sh", "/usr/bin/tuning-primer",
                        "Tuning-Primer"
                    ]]
                else:
                    Log.debug(self, "MySQL connection is already alive")
                    Log.info(self, "MySQL connection is already alive")

        except Exception as e:
            pass

        if len(apt_packages) or len(packages):
            Log.debug(self, "Calling pre_pref")
            self.pre_pref(apt_packages)
            if len(apt_packages):
                SSSSwap.add(self)
                Log.info(self, "Updating Apt-cache, please wait...")
                SSSAptGet.update(self)
                Log.info(self, "Installing packages, please wait...")
                SSSAptGet.install(self, apt_packages)
                SSSShellExec.cmd_exec(
                    self,
                    "a2enmod proxy_fcgi proxy proxy_http http2 ssl expires headers rewrite"
                )
            if len(packages):
                Log.debug(self, "Downloading following: {0}".format(packages))
                SSSDownload.download(self, packages)
            Log.debug(self, "Calling post_pref")
            self.post_pref(apt_packages, packages)

            if disp_msg:
                if len(self.msg):
                    for msg in self.msg:
                        Log.info(self, Log.ENDC + msg)
                Log.info(self, "Successfully installed packages")
            else:
                return self.msg