From 775f89be524518f4b2d305a8446313f848dfd3b2 Mon Sep 17 00:00:00 2001 From: Valentin Ochs Date: Tue, 21 May 2019 19:14:53 +0200 Subject: [PATCH] Fix startup, improve killing of old servers --- mailcap-server.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mailcap-server.py b/mailcap-server.py index c3f2603..24144e7 100644 --- a/mailcap-server.py +++ b/mailcap-server.py @@ -161,9 +161,10 @@ if __name__ == "__main__": parser.add_argument('--no-daemonize', '-n', action='store_true') parser.add_argument('--socket', '-s', default=os.path.join(os.environ['HOME'], '.mailcap.sock')) parser.add_argument('--dir', '-d', default=None) + parser.add_argument('--force', '-f', action='store_true') args = parser.parse_args() - if args.action == 'kill': + if args.action == 'kill' or args.force: if os.path.exists(args.socket): os.remove(args.socket) if os.path.exists(args.pid): @@ -171,11 +172,12 @@ if __name__ == "__main__": try: os.kill(pid, 3) except ProcessLookupError as e: - print("Failed to kill process with pid %d:" % (pid,), str(e)) + if args.action == 'kill': + print("Failed to kill process with pid %d:" % (pid,), str(e)) os.remove(args.pid) if os.path.exists(args.socket): os.remove(args.socket) - elif args.action == 'run': + if args.action == 'run': if os.path.exists(args.pid): print("Already running with pid %d" % (int(open(args.pid).read()),)) exit() @@ -186,4 +188,4 @@ if __name__ == "__main__": run_server(args) else: with daemon.DaemonContext(): - run_server() + run_server(args)