Example #1
0
 def export_env2php(self):
     os_env_str = ''
     tmpfile    = value_of("${PRJ_ROOT}/run/") + self.prefix + '.env'
     for k,v in environ_items():
         if k == "SHELL" or k == '_':
             continue
         os_env_str += ( 'env[%s] = "%s"\n' %(k,v))
     if os.access(value_of("${PRJ_ROOT}/run/"), os.W_OK) :
         with open(tmpfile, 'w') as f: f.write (os_env_str)
Example #2
0
 def export_env2php(self):
     os_env_str = ''
     tmpfile = value_of("${PRJ_ROOT}/run/") + self.prefix + '.env'
     for k, v in environ_items():
         if k == "SHELL" or k == '_':
             continue
         os_env_str += ('env[%s] = "%s"\n' % (k, v))
     if os.access(value_of("${PRJ_ROOT}/run/"), os.W_OK):
         with open(tmpfile, 'w') as f:
             f.write(os_env_str)
Example #3
0
 def _before(self,context):
     self.port       = value_of(self.port)
     self.admin_port = value_of(self.admin_port)
     self.admin_ip   = value_of(self.admin_ip)
     self.http_ip    = value_of(self.http_ip)
     self.mem        = value_of(self.mem)
     self.vcl        = value_of(self.vcl)
     self.extras          = value_of(self.extras)
     self.name       = value_of(self.name)
     self.pid        = value_of("${PRJ_ROOT}/varnishd_${PRJ_KEY}_" + self.port + ".pid")
Example #4
0
    def _before(self, context):
        utls.check.must_true(hasattr(context, "php_def"), "no !R.php_def")
        self.sudo = value_of(self.sudo)
        #FIXME
        #self.prefix     = value_of("rgapp-${USER}-${PRJ_KEY}-${_RG_SYS}" + self.sock_id)
        self.prefix = value_of("rgapp-${USER}-${PRJ_KEY}" + self.sock_id)
        self.php_ini = value_of(self.php_ini)
        self.fpm_conf = value_of(self.fpm_conf)
        cur_path = os.path.dirname(os.path.realpath(__file__))

        if os.path.isfile(self.fpm_conf):
            self.f_conf = self.fpm_conf
        elif self.fpm_conf == 'online':
            self.f_conf = value_of(
                "${PRJ_ROOT}") + '/' + self.prefix + '/fpm_svc.conf.online'
        else:
            self.f_conf = value_of(
                "${PRJ_ROOT}") + '/' + self.prefix + '/fpm_svc.conf.dev'

        cmdtpl = "${PATH}/fpm_ctrl.sh -b ${FPM_BIN} -c ${FPM_CONF} -f ${PHP_INI} -p ${PREFIX} -r ${PRJ_ROOT} -n ${RUN_PATH}"
        self.base_cmd = Template(cmdtpl).substitute(
            PATH=cur_path,
            FPM_BIN=context.php_def.fpm,
            FPM_CONF=self.f_conf,
            PHP_INI=self.php_ini,
            PREFIX=self.prefix,
            PRJ_ROOT=value_of('${PRJ_ROOT}'),
            #RUN_PATH=rg_run_path() FIXME
            RUN_PATH=value_of("${PRJ_ROOT}"))
Example #5
0
    def _before(self,context):
        utls.check.must_true(hasattr(context,"php_def"),"no !R.php_def")
        self.sudo       = value_of(self.sudo)
        #FIXME
        #self.prefix     = value_of("rgapp-${USER}-${PRJ_KEY}-${_RG_SYS}" + self.sock_id)
        self.prefix     = value_of("rgapp-${USER}-${PRJ_KEY}" + self.sock_id)
        self.php_ini    = value_of(self.php_ini)
        self.fpm_conf   = value_of(self.fpm_conf)
        cur_path        = os.path.dirname(os.path.realpath(__file__))

        if os.path.isfile(self.fpm_conf):
            self.f_conf = self.fpm_conf
        elif self.fpm_conf == 'online' :
            self.f_conf = value_of("${PRJ_ROOT}")  +  '/' + self.prefix + '/fpm_svc.conf.online'
        else :
            self.f_conf = value_of("${PRJ_ROOT}") +  '/' + self.prefix + '/fpm_svc.conf.dev'

        cmdtpl="${PATH}/fpm_ctrl.sh -b ${FPM_BIN} -c ${FPM_CONF} -f ${PHP_INI} -p ${PREFIX} -r ${PRJ_ROOT} -n ${RUN_PATH}"
        self.base_cmd = Template(cmdtpl).substitute(
            PATH        =   cur_path,
            FPM_BIN     =   context.php_def.fpm,
            FPM_CONF    =   self.f_conf,
            PHP_INI     =   self.php_ini,
            PREFIX      =   self.prefix,
            PRJ_ROOT    =   value_of('${PRJ_ROOT}'),
            #RUN_PATH=rg_run_path() FIXME
            RUN_PATH=value_of("${PRJ_ROOT}")
            )
Example #6
0
 def _before(self, context):
     self.port = value_of(self.port)
     self.admin_port = value_of(self.admin_port)
     self.admin_ip = value_of(self.admin_ip)
     self.http_ip = value_of(self.http_ip)
     self.mem = value_of(self.mem)
     self.vcl = value_of(self.vcl)
     self.extras = value_of(self.extras)
     self.name = value_of(self.name)
     self.pid = value_of("${PRJ_ROOT}/varnishd_${PRJ_KEY}_" + self.port +
                         ".pid")
Example #7
0
 def export_monitorconf(self, conf_path, files_to_check):
     cmd    = "cd %s; %s/rigger restart -x %s" %(value_of('${PRJ_ROOT}'), rg_home() , self.__class__.__name__)
     prefix = os.path.dirname(conf_path)
     if not os.path.isdir(prefix):
        shexec.execmd("mkdir -p '%s'" % prefix)
     conf   = 'FILES=\\"%s\\";' % files_to_check.replace(',', ' ') + 'CMD=\\"%s\\"' % cmd
     shexec.execmd('echo "%s" > "%s"' %(conf, conf_path))
Example #8
0
 def macro_data(self, arr):
     out = []
     for line in arr:
         line = value_of(line.strip())
         if len(line) > 0:
             out.append(line)
     return out
Example #9
0
 def export_monitorconf(self, conf_path, files_to_check):
     cmd = "cd %s; %s/rigger restart -x %s" % (
         value_of('${PRJ_ROOT}'), rg_home(), self.__class__.__name__)
     prefix = os.path.dirname(conf_path)
     if not os.path.isdir(prefix):
         shexec.execmd("mkdir -p '%s'" % prefix)
     conf = 'FILES=\\"%s\\";' % files_to_check.replace(
         ',', ' ') + 'CMD=\\"%s\\"' % cmd
     shexec.execmd('echo "%s" > "%s"' % (conf, conf_path))
Example #10
0
 def _config(self, context):
     prefix_dir = value_of("${PRJ_ROOT}") + '/' + self.prefix
     if not os.path.isdir(prefix_dir):
         shexec.execmd("mkdir -p '%s'" % prefix_dir)
     self.export_monitorconf(prefix_dir + '/config.fpm', 'fpm.pid,fpm.sock')
     self.export_env2php()
     self.export_fpmconf()
     cmd = self.base_cmd + " -d config"
     shexec.execmd(cmd)
Example #11
0
 def _config(self,context):
     prefix_dir = value_of("${PRJ_ROOT}") + '/' + self.prefix
     if not os.path.isdir(prefix_dir):
        shexec.execmd("mkdir -p '%s'" % prefix_dir)
     self.export_monitorconf(prefix_dir  + '/config.fpm', 'fpm.pid,fpm.sock')
     self.export_env2php()
     self.export_fpmconf()
     cmd = self.base_cmd + " -d config"
     shexec.execmd(cmd)
Example #12
0
    def test_save(self):
        from utls.rg_var import value_of
        save_file = value_of("${HOME}/devspace/rigger-ng/test/data/rigger.data")

        rargs          = run_args()
        rargs.prj.env  = "diy"
        rargs.prj.sys  = "api,test"
        rargs.prj.cmds = "conf,start"
        rargs.save(save_file)

        loaded  = run_args.load(save_file)
        self.assertEqual(loaded.prj.env  , rargs.prj.env)
        self.assertEqual(loaded.prj.sys  , rargs.prj.sys)
        self.assertEqual(loaded.prj.cmds , [])
Example #13
0
 def export_fpmconf(self):
     if not self.f_conf == self.fpm_conf:
         fpm_conf = 'online' if self.fpm_conf == 'online' else 'dev'
         run_user = env_exp.value("${USER}") if env_exp.value("${USER}") in [e.pw_name for e in pwd.getpwall()] else 'nobody'
         cnt_min = str(int(self.fpm_cnt) - 10)
         cnt_max = str(int(self.fpm_cnt) + 10)
         conf_override = env_exp.value("\n".join(self.conf_override).replace(';' + fpm_conf, ''))
         tplpath = rg_home() + '/extension/res_conf/fpm_svc.conf.' + fpm_conf
         with open(tplpath,'r') as ftpl :
             tpl = ftpl.read()
             tpl = Template(tpl).substitute(POOL_NAME=self.prefix,USER=run_user,FPM_CNT=self.fpm_cnt,FPM_CNT_MIN=cnt_min,FPM_CNT_MAX=cnt_max,CONF_OVERRIDE=conf_override)
             tmp_path = value_of("${PRJ_ROOT}/run/" + self.f_conf.replace('/', '_'))
             with open(tmp_path, 'w') as f: f.write (tpl)
             shexec.execmd("mv '%s' '%s'" % (tmp_path, self.f_conf))
Example #14
0
    def test_save(self):
        from utls.rg_var import value_of
        save_file = value_of(
            "${HOME}/devspace/rigger-ng/test/data/rigger.data")

        rargs = run_args()
        rargs.prj.env = "diy"
        rargs.prj.sys = "api,test"
        rargs.prj.cmds = "conf,start"
        rargs.save(save_file)

        loaded = run_args.load(save_file)
        self.assertEqual(loaded.prj.env, rargs.prj.env)
        self.assertEqual(loaded.prj.sys, rargs.prj.sys)
        self.assertEqual(loaded.prj.cmds, [])
Example #15
0
 def export_fpmconf(self):
     if not self.f_conf == self.fpm_conf:
         fpm_conf = 'online' if self.fpm_conf == 'online' else 'dev'
         run_user = env_exp.value("${USER}") if env_exp.value(
             "${USER}") in [e.pw_name for e in pwd.getpwall()] else 'nobody'
         cnt_min = str(int(self.fpm_cnt) - 10)
         cnt_max = str(int(self.fpm_cnt) + 10)
         conf_override = env_exp.value("\n".join(
             self.conf_override).replace(';' + fpm_conf, ''))
         tplpath = rg_home(
         ) + '/extension/res_conf/fpm_svc.conf.' + fpm_conf
         with open(tplpath, 'r') as ftpl:
             tpl = ftpl.read()
             tpl = Template(tpl).substitute(POOL_NAME=self.prefix,
                                            USER=run_user,
                                            FPM_CNT=self.fpm_cnt,
                                            FPM_CNT_MIN=cnt_min,
                                            FPM_CNT_MAX=cnt_max,
                                            CONF_OVERRIDE=conf_override)
             tmp_path = value_of("${PRJ_ROOT}/run/" +
                                 self.f_conf.replace('/', '_'))
             with open(tmp_path, 'w') as f:
                 f.write(tpl)
             shexec.execmd("mv '%s' '%s'" % (tmp_path, self.f_conf))
Example #16
0
 def _before(self, context):
     with res_context(self.__class__.__name__):
         self.svc_port = value_of(self.svc_port)
         self.admin_port = value_of(self.admin_port)
         self.admin_ip = value_of(self.admin_ip)
         self.svc_ip = value_of(self.svc_ip)
         self.mem = value_of(self.mem)
         self.vcl = value_of(self.vcl)
         self.extras = value_of(self.extras)
         self.name = value_of(self.name)
         self.pid = value_of("${RUN_PATH}/varnishd_" + self.svc_port +
                             ".pid")
         self.varnishd = value_of(self.varnishd)
         self.varnishadm = value_of(self.varnishadm)
Example #17
0
 def _before(self,context):
     with res_context(self.__class__.__name__) :
         self.svc_port   = value_of(self.svc_port)
         self.admin_port = value_of(self.admin_port)
         self.admin_ip   = value_of(self.admin_ip)
         self.svc_ip     = value_of(self.svc_ip)
         self.mem        = value_of(self.mem)
         self.vcl        = value_of(self.vcl)
         self.extras     = value_of(self.extras)
         self.name       = value_of(self.name)
         self.pid        = value_of("${RUN_PATH}/varnishd_" + self.svc_port + ".pid")
         self.varnishd   = value_of(self.varnishd)
         self.varnishadm = value_of(self.varnishadm)
Example #18
0
 def _check(self, context):
     cmdtpl = "cat " + value_of(
         "${PRJ_ROOT}"
     ) + '/' + self.prefix + "/fpm.pid 2>/dev/null | xargs ps | grep fpm"
     cnt_cmd = Template(cmdtpl).substitute(FPM_CONF=self.f_conf)
     check_proc("PHP-FPM", cnt_cmd, '1')
Example #19
0
 def _check(self,context):
     cmdtpl = "cat " +  value_of("${PRJ_ROOT}") +  '/'   + self.prefix + "/fpm.pid 2>/dev/null | xargs ps | grep fpm"
     cnt_cmd = Template(cmdtpl).substitute(FPM_CONF=self.f_conf)
     check_proc("PHP-FPM", cnt_cmd, '1')