コード例 #1
0
ファイル: __init__.py プロジェクト: lolizeppelin/gopdb
 def start(self, cfgfile, postrun=None, timeout=None, **kwargs):
     """stary database intance"""
     args = [SH, MYSQLSAFE, '--defaults-file=%s' % cfgfile]
     args.extend(self.base_opts)
     if not systemutils.POSIX:
         # just for test on windows
         LOG.info('will call %s', ' '.join(args))
         return
     pid = safe_fork()
     if pid == 0:
         # fork twice
         ppid = os.fork()
         if ppid == 0:
             os.closerange(3, systemutils.MAXFD)
             with open(BASELOG, 'ab') as f:
                 os.dup2(f.fileno(), 1)
                 os.dup2(f.fileno(), 2)
             try:
                 os.execv(SH, args)
             except OSError:
                 os._exit(1)
         else:
             os._exit(0)
     else:
         wait(pid)
         eventlet.sleep(1)
コード例 #2
0
 def syncwait(self, exitfunc=None, notify=None):
     try:
         try:
             if systemutils.POSIX:
                 from simpleutil.utils.systemutils import posix
                 posix.wait(self.pid)
             else:
                 systemutils.subwait(self.pid)
         except (ExitBySIG, UnExceptExit) as e:
             LOG.error('Websocket process wait catch error %s' % e.message)
             os.remove(self.tmp)
         finally:
             LOG.info('Websocket process with pid %d has been exit' %
                      self.pid)
             self.timer.cancel()
         if not os.path.exists(self.tmp):
             LOG.error('Upload file fail, %s not exist, has been delete' %
                       self.tmp)
             notify & eventlet.spawn_n(notify.fail)
             raise exceptions.PostWebSocketError(
                 'File not exit after upload')
         if os.path.getsize(self.tmp) != self.size:
             notify & eventlet.spawn_n(notify.fail)
             LOG.error('Size not match')
             os.remove(self.tmp)
             raise exceptions.PostWebSocketError(
                 'File size not match after upload')
         LOG.info('Upload file end, success')
         if os.path.exists(self.output):
             os.remove(self.output)
         os.rename(self.tmp, self.output)
         notify & eventlet.spawn_n(notify.success)
     finally:
         LOG.info('Call exit func')
         exitfunc & exitfunc()
コード例 #3
0
ファイル: base.py プロジェクト: frankiegu/Goperation
 def _wait():
     try:
         if systemutils.POSIX:
             from simpleutil.utils.systemutils import posix
             posix.wait(pid)
         else:
             subwait(sub)
     except Exception as e:
         LOG.error('Websocket reader wait catch error %s' % str(e))
     LOG.info('Websocket reader with pid %d has been exit' % pid)
     self.left_ports.add(port)
     self.websockets.pop(pid, None)
     _timer.cancel()
コード例 #4
0
ファイル: __init__.py プロジェクト: lolizeppelin/gopdb
 def install(self, cfgfile, postrun, timeout, **kwargs):
     """create database intance"""
     if not os.path.exists(cfgfile):
         raise ValueError('Config file not exist')
     args = [SH, MYSQLINSTALL, '--defaults-file=%s' % cfgfile]
     args.extend(self.base_opts)
     replication = kwargs.pop('replication', None)
     auth = kwargs.pop('auth')
     logfile = kwargs.get('logfile')
     if not systemutils.POSIX:
         # just for test on windows
         LOG.info('will call %s', ' '.join(args))
     else:
         with goperation.tlock('gopdb-install', 30):
             pid = safe_fork()
             if pid == 0:
                 os.closerange(3, systemutils.MAXFD)
                 logfile = logfile or os.devnull
                 with open(logfile, 'wb') as f:
                     os.dup2(f.fileno(), 1)
                     os.dup2(f.fileno(), 2)
                 try:
                     os.execv(SH, args)
                 except OSError:
                     os._exit(1)
             else:
                 try:
                     wait(pid, timeout)
                 except:
                     raise
                 finally:
                     LOG.info('%s has been exit' % MYSQLINSTALL)
     eventlet.sleep(0)
     self.start(cfgfile)
     eventlet.sleep(3)
     binlog = self._init_passwd(cfgfile, auth, replication)
     if postrun:
         postrun(binlog)
コード例 #5
0
ファイル: base.py プロジェクト: frankiegu/Goperation
    def rpc_upgrade_agent(self, ctxt, **kwargs):
        if not systemutils.LINUX:
            return AgentRpcResult(self.agent_id, ctxt, resultcode=manager_common.RESULT_ERROR,
                                  result='upgrade just on redhat system')
        from simpleutil.utils.systemutils import posix
        with self.work_lock.priority(0):
            if threadpool.threads or self.status < manager_common.SOFTBUSY:
                return AgentRpcResult(self.agent_id, ctxt,
                                      resultcode=manager_common.RESULT_ERROR,
                                      result='upgrade fail public thread pool not empty or status error')
            for endpont in self.endpoints:
                endpont.frozen = True
            last_status = self.status
            executable = systemutils.find_executable(YUM)
            # CALL yum --disablerepo=* --enablerepo=goputil clean metadata FIRST
            pid = safe_fork()
            args = [executable, '-y', '--disablerepo=*', '--enablerepo=goputil', 'clean', 'metadata']
            if pid == 0:
                os.closerange(3, systemutils.MAXFD)
                try:
                    os.execv(executable, args)
                except OSError:
                    os._exit(1)
            try:
                posix.wait(pid, 5)
            except (ExitBySIG, UnExceptExit):
                self.status = last_status
                return AgentRpcResult(self.agent_id, ctxt, resultcode=manager_common.RESULT_ERROR,
                                      result='upgrade call yum clean metadata fail')
            LOG.info('Call yum clean success')
            args = [executable, '-y', '--disablerepo=*', '--enablerepo=goputil', 'update']
            rpms = ['python-simpleutil-*', 'python-simpleservice-*',
                    'python-simpleflow-*', 'python-goperation-*']
            for cls in self.conf.endpoints:
                rpms.append('python-%s-*' % cls)
            args.extend(rpms)
            LOG.info('Rpm upgrade command %s' % ' '.join(args))

            pid = safe_fork()
            if pid == 0:
                os.closerange(3, systemutils.MAXFD)
                logpath = CONF.log_dir
                logfile = os.path.join(logpath, 'upgrade.%d.log' % int(time.time()))
                with open(logfile, 'ab') as f:
                    os.dup2(f.fileno(), sys.stdout.fileno())
                    os.dup2(f.fileno(), sys.stderr.fileno())
                    # exec后关闭日志文件描述符
                    systemutils.set_cloexec_flag(f.fileno())
                    try:
                        os.execv(executable, args)
                    except (OSError, IOError) as e:
                        sys.stderr.write('exec: ' + ' '.join(args) + '\n')
                        sys.stderr.write(str(e) + '\n')
                        os._exit(1)
            try:
                posix.wait(pid, 600)
            except (ExitBySIG, UnExceptExit) as e:
                self.status = last_status
                return AgentRpcResult(self.agent_id, ctxt, resultcode=manager_common.RESULT_ERROR,
                                      result='upgrade call yum update fail, %s' % e.message)
            executable = '/etc/init.d/gop-%s' % self.agent_type
            args = [executable, 'restart']
            pid = safe_fork()
            if pid == 0:
                os.closerange(3, systemutils.MAXFD)
                ppid = os.fork()
                if ppid == 0:
                    eventlet.sleep(5)
                    try:
                        os.execv(executable, args)
                    except OSError:
                        os._exit(1)
                os._exit(0)
            posix.wait(pid)
            LOG.warning('Agent restart command executeing, restart in 5 seconds')
            return AgentRpcResult(self.agent_id, ctxt, resultcode=manager_common.RESULT_SUCCESS,
                                  result='upgrade call yum update success')