Add powerline-daemon --quiet

This commit is contained in:
ZyX 2014-08-02 22:20:06 +04:00
parent 44cca97566
commit ea7f3b6501
1 changed files with 18 additions and 11 deletions

View File

@ -300,7 +300,7 @@ def check_existing():
return sock return sock
def test_connect(): def kill_daemon():
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
try: try:
try: try:
@ -351,6 +351,7 @@ def lockpidfile():
def main(): def main():
p = ArgumentParser(description= p = ArgumentParser(description=
'Daemon to improve the performance of powerline') 'Daemon to improve the performance of powerline')
p.add_argument('--quiet', '-q', action='store_true', help='Without other options: do not complain about already running powerline-daemon instance. Will still exit with 1. With `--kill\' and `--replace\': do not show any messages. With `--foreground\': ignored. Does not silence exceptions in any case.')
a = p.add_mutually_exclusive_group().add_argument a = p.add_mutually_exclusive_group().add_argument
a('--kill', '-k', action='store_true', help='Kill an already running instance') a('--kill', '-k', action='store_true', help='Kill an already running instance')
a('--foreground', '-f', action='store_true', help='Run in the foreground (dont daemonize)') a('--foreground', '-f', action='store_true', help='Run in the foreground (dont daemonize)')
@ -358,14 +359,18 @@ def main():
args = p.parse_args() args = p.parse_args()
if args.kill: if args.kill:
if test_connect(): if kill_daemon():
if not args.quiet:
print ('Kill command sent to daemon, if it does not die in a couple of seconds use kill to kill it') print ('Kill command sent to daemon, if it does not die in a couple of seconds use kill to kill it')
raise SystemExit(0)
else: else:
if not args.quiet:
print ('No running daemon found') print ('No running daemon found')
return raise SystemExit(1)
if args.replace: if args.replace:
while test_connect(): while kill_daemon():
if not args.quiet:
print ('Kill command sent to daemon, waiting for daemon to exit, press Ctrl-C to terminate wait and exit') print ('Kill command sent to daemon, waiting for daemon to exit, press Ctrl-C to terminate wait and exit')
sleep(2) sleep(2)
@ -377,6 +382,7 @@ def main():
if use_filesystem: if use_filesystem:
# Create a locked pid file containing the daemon's PID # Create a locked pid file containing the daemon's PID
if lockpidfile() is None: if lockpidfile() is None:
if not args.quiet:
print ('The daemon is already running. Use %s -k to kill it.' % os.path.basename(sys.argv[0]), print ('The daemon is already running. Use %s -k to kill it.' % os.path.basename(sys.argv[0]),
file=sys.stderr) file=sys.stderr)
raise SystemExit(1) raise SystemExit(1)
@ -384,6 +390,7 @@ def main():
# Bind to address or bail if we cannot bind # Bind to address or bail if we cannot bind
sock = check_existing() sock = check_existing()
if sock is None: if sock is None:
if not args.quiet:
print ('The daemon is already running. Use %s -k to kill it.' % os.path.basename(sys.argv[0]), print ('The daemon is already running. Use %s -k to kill it.' % os.path.basename(sys.argv[0]),
file=sys.stderr) file=sys.stderr)
raise SystemExit(1) raise SystemExit(1)