diff options
author | Yaroslav Brustinov <ybrustin@cisco.com> | 2016-06-17 18:47:56 +0300 |
---|---|---|
committer | Yaroslav Brustinov <ybrustin@cisco.com> | 2016-06-17 18:47:56 +0300 |
commit | d93a7ff83d3d29fc6c254dd56af235dbe7abacb3 (patch) | |
tree | d4be7b58fb6712a71c34152aae7bf74ac72e43cd /scripts | |
parent | 3207f14a91cc01b44b28ba541e5968f58a7e5ec2 (diff) |
master_daemon: show better status of executed command
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/automation/trex_control_plane/server/singleton_daemon.py | 2 | ||||
-rwxr-xr-x | scripts/master_daemon.py | 15 |
2 files changed, 10 insertions, 7 deletions
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) |