Exemplo n.º 1
0
    def call(self, cmd):
        if isinstance(cmd, basestring):
            raise DeprecationWarning('call() takes a mapping')

        call_id = uuid.uuid4().hex
        cmd['id'] = call_id
        host, port = self.endpoint.split(':')

        try:
            cmd = json.dumps(cmd)
            if not self.stream or self.stream.closed():
                self.stream = yield gen_timeout(
                    self.timeout, self.client.connect(host, port))

            yield gen_timeout(self.timeout, self.stream.write(cmd + MSG_END))
        except gen.TimeoutError:
            raise CallError('Timed out ({} seconds).'.format(self.timeout))
        except ValueError as e:
            raise CallError(str(e))

        while True:
            try:
                msg = yield gen_timeout(self.timeout,
                                        self.stream.read_until(MSG_END))
                msg = rstrip(msg, MSG_END)
                res = json.loads(msg)
                if 'id' in res and res['id'] not in (call_id, None):
                    # we got the wrong message
                    continue
                raise gen.Return(res)
            except gen.TimeoutError:
                raise CallError('Timed out ({} seconds).'.format(self.timeout))
            except ValueError as e:
                raise CallError(str(e))
Exemplo n.º 2
0
    def install(cls, *args):
        logger.info('Installing ant-upgrade service')

        returncode, output = _nssm_run('install', cls.name, UPGRADE_START)
        if returncode == 0 and 'Administrator access' in output:
            raise CallError(output)
        elif returncode == 5:
            raise AlreadyExist(cls.exist_msg)
        elif returncode != 0:
            raise CallError(output)

        logger.info('ant-upgrade installed')
Exemplo n.º 3
0
    def remove(cls):
        """If you want to remove the service, please make sure stop it first.
        Otherwise you will get error message: "Error deleting". """
        logger.info('Removing ant-upgrade service')

        returncode, output = _nssm_run('remove', cls.name, 'confirm')
        if returncode == 3:
            raise NotExistError(cls.not_exist_msg)
        elif returncode == 4:
            raise CallError(cls.remove_err_msg)
        elif returncode != 0:
            raise CallError(output)
        logger.info('ant-upgrade removed')
Exemplo n.º 4
0
    def install(cls, *args):
        logger.info('Installing ant-agent service')

        if not os.path.exists(CIRCLED_PATH):
            raise CallError('{} not exists.'.format(CIRCLED_PATH))

        returncode, output = _nssm_run('install', cls.name, BIN_START)
        if returncode == 0 and 'Administrator access' in output:
            raise CallError(output)
        elif returncode == 5:
            raise AlreadyExist(cls.exist_msg)
        elif returncode != 0:
            raise CallError(output)

        logger.info('ant-agent installed')
Exemplo n.º 5
0
    def config(cls, *args):
        logger.debug('Configuring ant-agent service parameters')

        returncode, output = _nssm_run('set', cls.name, 'AppDirectory',
                                       ROOT_DIR)
        if returncode != 0:
            if '\x07c\x9a' in output:
                raise CallError(cls.not_exist_msg)
            elif '\xd2b\xdd' in output:
                raise CallError(cls.access_err_msg)
            raise CallError(output)

        returncode, output = _nssm_run('set', cls.name, 'AppParameters',
                                       *([CIRCLED_PATH] + list(args)))
        if returncode != 0:
            raise CallError(output)
        logger.debug('ant-agent service parameters configured')
Exemplo n.º 6
0
    def stop(cls):
        logger.info('Stopping ant-agent service')

        returncode, output = _sc_run('stop', cls.name)
        if returncode != 0:
            raise CallError(output)
        _wait_util(cls, 'stopped')

        logger.info('ant-agent stopped')
Exemplo n.º 7
0
    def start(cls, *args):
        logger.info('Starting ant-agent service')

        # CircleWinService.config(*args)
        returncode, output = _sc_run('start', cls.name)
        if returncode != 0:
            raise CallError(output)
        _wait_util(cls, 'running')

        logger.info('ant-agent started')
Exemplo n.º 8
0
 def _handle_msg(self, client, msg):
     ret_msg = client.call(msg)
     if ret_msg.get('status') == 'error':
         reason = ret_msg.get('reason')
         if 'time out' in reason:
             raise TimeOutError(TIMEOUT_MSG)
         elif 'invalid' in reason:
             raise MessageError(reason)
         else:
             raise CallError(reason)
     return ret_msg
Exemplo n.º 9
0
 def status(cls):
     returncode, output = _nssm_run('status', cls.name)
     if returncode == 0:
         if 'SERVICE_STOPPED' in output:
             return 'stopped'
         elif 'SERVICE_RUNNING' in output:
             return 'running'
         elif 'SERVICE_PAUSED' in output:
             return 'paused'
         elif 'START_PENDING' in output:
             return 'starting'
         elif 'STOP_PENDING' in output:
             return 'stopping'
     elif returncode == 3:
         raise NotExistError(cls.not_exist_msg)
     else:
         raise CallError(output)