From d93a7ff83d3d29fc6c254dd56af235dbe7abacb3 Mon Sep 17 00:00:00 2001 From: Yaroslav Brustinov Date: Fri, 17 Jun 2016 18:47:56 +0300 Subject: master_daemon: show better status of executed command --- .../trex_control_plane/server/singleton_daemon.py | 2 +- scripts/master_daemon.py | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'scripts') diff --git a/scripts/automation/trex_control_plane/server/singleton_daemon.py b/scripts/automation/trex_control_plane/server/singleton_daemon.py index 79deace1..1784cc42 100755 --- a/scripts/automation/trex_control_plane/server/singleton_daemon.py +++ b/scripts/automation/trex_control_plane/server/singleton_daemon.py @@ -86,7 +86,7 @@ class SingletonDaemon(object): def kill(self, timeout = 15): pid = self.get_pid() if not pid: - return False + raise Exception('%s is not running' % self.name) # try Ctrl+C, usual kill, kill -9 for signal_name in [signal.SIGINT, signal.SIGTERM, signal.SIGKILL]: if self.kill_by_signal(pid, signal_name, timeout): diff --git a/scripts/master_daemon.py b/scripts/master_daemon.py index e50d49ee..aa49f207 100755 --- a/scripts/master_daemon.py +++ b/scripts/master_daemon.py @@ -83,8 +83,7 @@ def start_master_daemon(): proc.start() for i in range(50): if master_daemon.is_running(): - print(termstyle.green('Master daemon is started.')) - os._exit(0) + return True sleep(0.1) fail(termstyle.red('Master daemon failed to run. Please look in log: %s' % logging_file)) @@ -226,9 +225,13 @@ if args.action != 'show': print(termstyle.red(e)) sys.exit(1) -# prints running status -if daemon.is_running(): - print(termstyle.green('%s is running' % daemon.name)) +passive = {'start': 'started', 'restart': 'restarted', 'stop': 'stopped', 'show': 'running'} + +if args.action in ('show', 'start', 'restart') and daemon.is_running() or \ + args.action == 'stop' and not daemon.is_running(): + print(termstyle.green('%s is %s' % (daemon.name, passive[args.action]))) + os._exit(0) else: - print(termstyle.red('%s is NOT running' % daemon.name)) + print(termstyle.red('%s is NOT %s' % (daemon.name, passive[args.action]))) + os._exit(-1) -- cgit 1.2.3-korg