Exemplo n.º 1
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")
Exemplo n.º 2
0
    def debug_php7(self):
        """Start/Stop PHP debug"""
        # PHP global debug start

        if (self.app.pargs.php7 == 'on' and not self.app.pargs.site_name):
            if (EEVariables.ee_platform_codename == 'wheezy' or EEVariables.ee_platform_codename == 'precise'):
                Log.error(self,"PHP 7.0 not supported.")
            if not (EEShellExec.cmd_exec(self, "sed -n \"/upstream php7"
                                               "{/,/}/p \" /etc/nginx/"
                                               "conf.d/upstream.conf "
                                               "| grep 9170")):

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

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

                # Enable xdebug
                if (EEVariables.ee_platform_codename != 'jessie'):
                    EEFileUtils.searchreplace(self, "/etc/php/7.0/mods-available/"
                                              "xdebug.ini",
                                              ";zend_extension",
                                              "zend_extension")
                else:
                    EEFileUtils.searchreplace(self, "/etc/php/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.0/fpm/pool.d/debug.conf')
                config['debug']['slowlog'] = '/var/log/php/7.0/slow.log'
                config['debug']['request_slowlog_timeout'] = '10s'
                with open('/etc/php/7.0/fpm/pool.d/debug.conf',
                          encoding='utf-8', mode='w') as confifile:
                    Log.debug(self, "Writting debug.conf configuration into "
                              "/etc/php/7.0/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.0/slow.log']

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

                # Change upstream.conf
                nc = NginxConfig()
                nc.loadf('/etc/nginx/conf.d/upstream.conf')
                nc.set([('upstream','php',), 'server'], '127.0.0.1:9070')
                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
                if (EEVariables.ee_platform_codename != 'jessie'):
                    EEFileUtils.searchreplace(self, "/etc/php/7.0/mods-available/"
                                          "xdebug.ini",
                                          "zend_extension",
                                          ";zend_extension")
                else:
                    EEFileUtils.searchreplace(self, "/etc/php/mods-available/"
                                          "xdebug.ini",
                                          "zend_extension",
                                          ";zend_extension")

                self.trigger_php = True
                self.trigger_nginx = True
            else:
                Log.info(self, "PHP 7.0 debug is already disabled")
Exemplo n.º 3
0
    def debug_php7(self):
        """Start/Stop PHP debug"""
        # PHP global debug start

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

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

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

                # Enable xdebug
                EEFileUtils.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 EEShellExec.cmd_exec(
                    self, " sed -n \"/upstream php7 {/,/}/p\" "
                    "/etc/nginx/conf.d/upstream.conf "
                    "| grep 9170"):
                Log.info(self, "Disabling PHP 7.2 debug")

                # Change upstream.conf
                nc = NginxConfig()
                nc.loadf('/etc/nginx/conf.d/upstream.conf')
                nc.set([(
                    'upstream',
                    'php7',
                ), 'server'], '127.0.0.1:9070')
                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
                EEFileUtils.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")
Exemplo n.º 4
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")
Exemplo n.º 5
0
def generate(inputf,
             outputf,
             PROJECT_PATH='/webapp/',
             DJANGO_SERVERS=["localhost:80", "localhost:81"],
             TWISTED_SERVERS=["localhost:8000", "localhost:8001"],
             SHINY_SERVERS=["localhost:80", "localhost:81"]):
    UWSGI_PARAM = PROJECT_PATH + 'uwsgi_params'
    DJANGO_ROOT = PROJECT_PATH + "energyinsight2.0/"
    nc = NginxConfig()
    nc.loadf(inputf)

    # Set twisted server upstream
    twisted_servers = [('server', x) for x in TWISTED_SERVERS]
    nc.set([('http', ), ('upstream', 'twisted')], twisted_servers)

    # Set django server upstream
    django_servers = [('server', x) for x in DJANGO_SERVERS]
    nc.set([('http', ), ('upstream', 'django')], django_servers)
    # Set shiny server upstream
    shiny_servers = [('server', x) for x in SHINY_SERVERS]
    nc.set([('http', ), ('upstream', 'shiny')], shiny_servers)

    # Set the uwsgi_parameters
    nc.set([('http', ), ('server', ),
            ('location', '~ ^\\/api\\/(put|get)series'), 'include'],
           UWSGI_PARAM)
    nc.set([('http', ), ('server', ), ('location', '/'), 'include'],
           UWSGI_PARAM)
    nc.set([('http', ), ('server', ), ('location', '/static')],
           [('root', DJANGO_ROOT + "/")])

    # set lua path
    nc.set([('http', ), 'lua_package_path'],
           "\"" + PROJECT_PATH + "jwt/?.lua;;\"")

    # http_block=nc.get(('http',))['value'];
    # for b in http_block:
    # 	if b['name']=='server':
    # 		for i,t in enumerate(b['value']):
    # 			if isinstance(t,tuple) and t[0]=='lua_package_path':
    # 				b['value'][i]=('lua_package_path',"\""+PROJECT_PATH+";;\"");

    nc.savef(outputf)


# setup twisted server configuration
#nc.append({'name':'upstrea','param':'twisted','value':[('server','localhost'),('server','app.equotaenergy.com')]},http_block,position=1);
# setup django server configuration
#nc.append({'name':'upstrea','param':'django','value':[('server','localhost'),('server','app.equotaenergy.com')]},http_block,position=1);

#print(nc.gen_config())