Beispiel #1
0
def hashbucket(self):
    # Check Nginx Hashbucket error
    sub = subprocess.Popen('nginx -t', stdout=subprocess.PIPE,
                           stderr=subprocess.PIPE, shell=True)
    output, error_output = sub.communicate()
    if 'server_names_hash_bucket_size' not in str(error_output):
        return True

    count = 0
    # Get the list of sites-availble
    sites_list = os.listdir("/etc/nginx/sites-enabled/")

    # Count the number of characters in site names
    for site in sites_list:
        count = sum([count, len(site)])

    # Calculate Nginx hash bucket size
    ngx_calc = math.trunc(sum([math.log(count, 2), 2]))
    ngx_hash = math.trunc(math.pow(2, ngx_calc))

    # Replace hashbucket in Nginx.conf file
    if WOFileUtils.grep(self, "/etc/nginx/nginx.conf",
                        "server_names_hash_bucket_size"):
        for line in fileinput.FileInput("/etc/nginx/nginx.conf", inplace=1):
            if "server_names_hash_bucket_size" in line:
                print("\tserver_names_hash_bucket_size {0};".format(ngx_hash))
            else:
                print(line, end='')

    else:
        WOFileUtils.searchreplace(self, '/etc/nginx/nginx.conf',
                                  "gzip_disable \"msie6\";",
                                  "gzip_disable \"msie6\";\n"
                                  "\tserver_names_hash_bucket_size {0};\n"
                                  .format(ngx_hash))
Beispiel #2
0
    def upgrade_php56(self):
        if WOVariables.wo_platform_distro == "ubuntu":
            if os.path.isfile("/etc/apt/sources.list.d/ondrej-php5-5_6-{0}."
                              "list".format(WOVariables.wo_platform_codename)):
                Log.error(self, "Unable to find PHP 5.5")
        else:
            if not(os.path.isfile(WOVariables.wo_repo_file_path) and
                   WOFileUtils.grep(self, WOVariables.wo_repo_file_path,
                                    "php55")):
                Log.error(self, "Unable to find PHP 5.5")

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

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

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

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

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

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

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

        Log.info(self, "Successfully upgraded from PHP 5.5 to PHP 5.6")
Beispiel #3
0
    def add(self):
        """Swap addition with WordOps"""
        # Get System RAM and SWAP details
        wo_ram = psutil.virtual_memory().total / (1024 * 1024)
        wo_swap = psutil.swap_memory().total / (1024 * 1024)
        if wo_ram < 512:
            if wo_swap < 1000:
                Log.info(self, "Adding SWAP file, please wait...")

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

                # Modify Swap configuration
                if os.path.isfile("/etc/dphys-swapfile"):
                    WOFileUtils.searchreplace(self, "/etc/dphys-swapfile",
                                              "#CONF_SWAPFILE=/var/swap",
                                              "CONF_SWAPFILE=/wo-swapfile")
                    WOFileUtils.searchreplace(self, "/etc/dphys-swapfile",
                                              "#CONF_MAXSWAP=2048",
                                              "CONF_MAXSWAP=1024")
                    WOFileUtils.searchreplace(self, "/etc/dphys-swapfile",
                                              "#CONF_SWAPSIZE=",
                                              "CONF_SWAPSIZE=1024")
                else:
                    with open("/etc/dphys-swapfile", 'w') as conffile:
                        conffile.write("CONF_SWAPFILE=/wo-swapfile\n"
                                       "CONF_SWAPSIZE=1024\n"
                                       "CONF_MAXSWAP=1024\n")
                # Create swap file
                WOShellExec.cmd_exec(self, "service dphys-swapfile start")
Beispiel #4
0
    def debug_php73(self):
        """Start/Stop PHP debug"""
        # PHP global debug start

        if (self.app.pargs.php73 == 'on' and not self.app.pargs.site_name):
            if not (WOShellExec.cmd_exec(
                    self, "sed -n \"/upstream php73"
                    "{/,/}/p \" /etc/nginx/"
                    "conf.d/upstream.conf "
                    "| grep 9173")):

                Log.info(self, "Enabling PHP 7.3 debug")

                # Change upstream.conf
                nc = NginxConfig()
                nc.loadf('/etc/nginx/conf.d/upstream.conf')
                nc.set([(
                    'upstream',
                    'php73',
                ), 'server'], '127.0.0.1:9173')
                nc.savef('/etc/nginx/conf.d/upstream.conf')

                # Enable xdebug
                WOFileUtils.searchreplace(
                    self, "/etc/php/7.3/mods-available/"
                    "xdebug.ini", ";zend_extension", "zend_extension")

                # Fix slow log is not enabled default in PHP5.6
                config = configparser.ConfigParser()
                config.read('/etc/php/7.3/fpm/pool.d/debug.conf')
                config['debug']['slowlog'] = '/var/log/php/7.3/slow.log'
                config['debug']['request_slowlog_timeout'] = '10s'
                with open('/etc/php/7.3/fpm/pool.d/debug.conf',
                          encoding='utf-8',
                          mode='w') as confifile:
                    Log.debug(
                        self, "Writting debug.conf configuration into "
                        "/etc/php/7.3/fpm/pool.d/debug.conf")
                    config.write(confifile)

                self.trigger_php = True
                self.trigger_nginx = True
            else:
                Log.info(self, "PHP debug is already enabled")

            self.msg = self.msg + ['/var/log/php/7.3/slow.log']

        # PHP global debug stop
        elif (self.app.pargs.php73 == 'off' and not self.app.pargs.site_name):
            if WOShellExec.cmd_exec(
                    self, " sed -n \"/upstream "
                    "php72 {/,/}/p\" "
                    "/etc/nginx/conf.d/upstream.conf "
                    "| grep 9172"):
                Log.info(self, "Disabling PHP 7.2 debug")

                # Change upstream.conf
                nc = NginxConfig()
                nc.loadf('/etc/nginx/conf.d/upstream.conf')
                nc.set([(
                    'upstream',
                    'php72',
                ), 'server'], 'unix:/var/run/php/php72-fpm.sock')
                nc.savef('/etc/nginx/conf.d/upstream.conf')

                # Disable xdebug
                WOFileUtils.searchreplace(
                    self, "/etc/php/7.2/mods-available/"
                    "xdebug.ini", "zend_extension", ";zend_extension")

                self.trigger_php = True
                self.trigger_nginx = True
            else:
                Log.info(self, "PHP 7.2 debug is already disabled")
Beispiel #5
0
    def debug_php(self):
        """Start/Stop PHP debug"""
        # PHP global debug start

        if (self.app.pargs.php == 'on' and not self.app.pargs.site_name):
            if not (WOShellExec.cmd_exec(
                    self, "sed -n \"/upstream php"
                    "{/,/}/p \" /etc/nginx/"
                    "conf.d/upstream.conf "
                    "| grep 9001")):

                Log.info(self, "Enabling PHP debug")

                # Change upstream.conf
                nc = NginxConfig()
                nc.loadf('/etc/nginx/conf.d/upstream.conf')
                nc.set([(
                    'upstream',
                    'php',
                ), 'server'], '127.0.0.1:9001')
                nc.savef('/etc/nginx/conf.d/upstream.conf')

                # Enable xdebug
                WOFileUtils.searchreplace(
                    self, "/etc/{0}/mods-available/".format("php/7.2" if (
                        WOVariables.wo_platform_distro == 'ubuntu'
                    ) else "php/7.2") + "xdebug.ini", ";zend_extension",
                    "zend_extension")

                # Fix slow log is not enabled default in PHP5.6
                config = configparser.ConfigParser()
                config.read(
                    '/etc/{0}/fpm/pool.d/debug.conf'.format("php/7.2" if (
                        WOVariables.wo_platform_distro == 'ubuntu'
                    ) else "php5"))
                config['debug']['slowlog'] = '/var/log/{0}/slow.log'.format(
                    "php/7.2" if (WOVariables.wo_platform_distro == 'ubuntu'
                                  ) else "php5")
                config['debug']['request_slowlog_timeout'] = '10s'
                with open(
                        '/etc/{0}/fpm/pool.d/debug.conf'.format("php/7.2" if (
                            WOVariables.wo_platform_distro == 'ubuntu'
                        ) else "php5"),
                        encoding='utf-8',
                        mode='w') as confifile:
                    Log.debug(
                        self, "Writting debug.conf configuration into "
                        "/etc/{0}/fpm/pool.d/debug.conf".format("php/7.2" if (
                            WOVariables.wo_platform_distro == 'ubuntu'
                        ) else "php5"))
                    config.write(confifile)

                self.trigger_php = True
                self.trigger_nginx = True
            else:
                Log.info(self, "PHP debug is already enabled")

            self.msg = self.msg + [
                '/var/log/{0}/slow.log'.format("php/7.2" if (
                    WOVariables.wo_platform_distro == 'ubuntu') else "php5")
            ]

        # PHP global debug stop
        elif (self.app.pargs.php == 'off' and not self.app.pargs.site_name):
            if WOShellExec.cmd_exec(
                    self, " sed -n \"/upstream php {/,/}/p\" "
                    "/etc/nginx/conf.d/upstream.conf "
                    "| grep 9001"):
                Log.info(self, "Disabling PHP debug")

                # Change upstream.conf
                nc = NginxConfig()
                nc.loadf('/etc/nginx/conf.d/upstream.conf')
                nc.set([(
                    'upstream',
                    'php',
                ), 'server'], '127.0.0.1:9000')
                nc.savef('/etc/nginx/conf.d/upstream.conf')

                # Disable xdebug
                WOFileUtils.searchreplace(
                    self, "/etc/{0}/mods-available/".format("php/7.2" if (
                        WOVariables.wo_platform_distro == 'ubuntu'
                    ) else "php5") + "xdebug.ini", "zend_extension",
                    ";zend_extension")

                self.trigger_php = True
                self.trigger_nginx = True
            else:
                Log.info(self, "PHP debug is already disabled")
Beispiel #6
0
    def debug_php72(self):
        """Start/Stop PHP debug"""
        # PHP global debug start

        if (self.app.pargs.php72 == 'on' and not self.app.pargs.site_name):
            if (WOVariables.wo_platform_codename == 'wheezy'
                    or WOVariables.wo_platform_codename == 'precise'):
                Log.error(self, "PHP 7.2 not supported.")
            if not (WOShellExec.cmd_exec(
                    self, "sed -n \"/upstream php7"
                    "{/,/}/p \" /etc/nginx/"
                    "conf.d/upstream.conf "
                    "| grep 9172")):

                Log.info(self, "Enabling PHP 7.2 debug")

                # Change upstream.conf
                nc = NginxConfig()
                nc.loadf('/etc/nginx/conf.d/upstream.conf')
                nc.set([(
                    'upstream',
                    'php72',
                ), 'server'], '127.0.0.1:9172')
                if os.path.isfile("/etc/nginx/common/wpfc-hhvm.conf"):
                    nc.set([(
                        'upstream',
                        'hhvm',
                    ), 'server'], '127.0.0.1:9172')
                nc.savef('/etc/nginx/conf.d/upstream.conf')

                # Enable xdebug
                WOFileUtils.searchreplace(
                    self, "/etc/php/7.2/mods-available/"
                    "xdebug.ini", ";zend_extension", "zend_extension")

                # Fix slow log is not enabled default in PHP5.6
                config = configparser.ConfigParser()
                config.read('/etc/php/7.2/fpm/pool.d/debug.conf')
                config['debug']['slowlog'] = '/var/log/php/7.2/slow.log'
                config['debug']['request_slowlog_timeout'] = '10s'
                with open('/etc/php/7.2/fpm/pool.d/debug.conf',
                          encoding='utf-8',
                          mode='w') as confifile:
                    Log.debug(
                        self, "Writting debug.conf configuration into "
                        "/etc/php/7.2/fpm/pool.d/debug.conf")
                    config.write(confifile)

                self.trigger_php = True
                self.trigger_nginx = True
            else:
                Log.info(self, "PHP debug is already enabled")

            self.msg = self.msg + ['/var/log/php/7.2/slow.log']

        # PHP global debug stop
        elif (self.app.pargs.php7 == 'off' and not self.app.pargs.site_name):
            if WOShellExec.cmd_exec(
                    self, " sed -n \"/upstream php72 {/,/}/p\" "
                    "/etc/nginx/conf.d/upstream.conf "
                    "| grep 9172"):
                Log.info(self, "Disabling PHP 7.2 debug")

                # Change upstream.conf
                nc = NginxConfig()
                nc.loadf('/etc/nginx/conf.d/upstream.conf')
                nc.set([(
                    'upstream',
                    'php72',
                ), 'server'], '127.0.0.1:9072')
                if os.path.isfile("/etc/nginx/common/wpfc-hhvm.conf"):
                    nc.set([(
                        'upstream',
                        'hhvm',
                    ), 'server'], '127.0.0.1:8000')
                nc.savef('/etc/nginx/conf.d/upstream.conf')

                # Disable xdebug
                WOFileUtils.searchreplace(
                    self, "/etc/php/7.2/mods-available/"
                    "xdebug.ini", "zend_extension", ";zend_extension")

                self.trigger_php = True
                self.trigger_nginx = True
            else:
                Log.info(self, "PHP 7.2 debug is already disabled")