def start_agent(): if IS_WINDOWS: if CircleWinService.status() != 'stopped': CircleWinService.stop() CircleWinService.start() else: check_call([BIN_START], shell=True)
def stop_agent(self): self.http_handler.log_ok('Stopping agent') if IS_WINDOWS: from circle.winservice import CircleWinService if CircleWinService.status() != 'stopped': CircleWinService.stop() else: p = Popen([self.bin_stop], stdout=PIPE, stderr=STDOUT, cwd=ROOT_DIR, shell=True) last_time = time.time() while p.poll() is None: time.sleep(TIME_TICK) self.http_handler.log_ok('Stopping agent') if time.time() - last_time > STOP_AGENT_TIMEOUT: err_msg = 'Stop agent time out' raise MessageError(err_msg) poll = p.poll() if p.poll() != 0: out = p.stdout.read() if 'circled' in out and 'closed' in out: self.http_handler.log_ok( 'circled not running, no need to stop') return elif out.strip() != 'ok': pre = 'Start agent timeout' if poll is None \ else 'Start agent error' msg = '{}. Exit code: {}\n{}'.format(pre, poll, out) raise MessageError(msg) self.http_handler.log_ok('Stop agent done')
def win_daemonize(): logger.info('Starting deamon mode. ' 'The AntCircled service will be started.') args = sys.argv[1:] if '--daemon' in args: args.remove('--daemon') try: if not CircleWinService.exists(): CircleWinService.install(*args) CircleWinService.start(*args) sys.exit(0) except (AlreadyExist, NotExistError, CallError) as e: logger.error(e) sys.exit(1)
def _dispatch_callback(self, msg, mid, cmd_name, resp=None): if resp is None: resp = ok() if not isinstance(resp, (dict, list)): msg = 'Message {!r} tried to send a non-dict: {}'\ .format(msg, str(resp)) logger.error(msg) return self.send_error(mid, msg, error('server error'), errno=errors.BAD_MSG_DATA_ERROR) if isinstance(resp, list): resp = {'results': resp} self.send_ok(mid, msg, resp) if cmd_name.lower() == 'quit': self.controller.arbiter.stop() if IS_WINDOWS and CircleWinService.status() == 'running': CircleWinService.stop()
def check_win_agent(): if CircleWinService.exists(): answer = raw_input('Ant agent has installed as windows service ' '("Agent") before. \n' 'Do you want to remove it?(yes/no)') if answer == 'yes': if CircleWinService.status() != 'stopped': CircleWinService.stop() CircleWinService.remove() else: logger.info('exit') return False if UpgradeWinService.exists(): if UpgradeWinService.status() != 'stopped': UpgradeWinService.stop() UpgradeWinService.remove() return True
def start_win(): from circle.winservice import CircleWinService if CircleWinService.status() != 'stopped': CircleWinService.stop() CircleWinService.start()