From 7eacfa14f857e3795973ecea1aeb09b4ad2a6483 Mon Sep 17 00:00:00 2001 From: Blallo Date: Wed, 20 Feb 2019 18:11:08 +0100 Subject: [PATCH] Daemonic check-in/out. --- bot_z/bot_z.py | 2 +- bot_z/zdaemon.py | 36 +++++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/bot_z/bot_z.py b/bot_z/bot_z.py index 6d2b3d9..9584a75 100644 --- a/bot_z/bot_z.py +++ b/bot_z/bot_z.py @@ -193,7 +193,7 @@ class Operator(wd.Firefox): user_form.send_keys(user) pass_form.send_keys(password) do_it = True - if self.debug and not force and self.opts.headless: + if self.debug and not force and not self.opts.headless: _do_it = input("Really do the login? [y/n] ").lower() do_it = True if _do_it == "y" else False if do_it: diff --git a/bot_z/zdaemon.py b/bot_z/zdaemon.py index d86ada2..b1a9368 100644 --- a/bot_z/zdaemon.py +++ b/bot_z/zdaemon.py @@ -112,7 +112,7 @@ def operator_login(op: Operator, username: str, password: str, force: bool) -> N """ Instructs the operator to perform login. """ - logger.debug("Performing login.") + logger.debug("Performing login...") op.login(username, password, force) logger.info("Login done.") @@ -121,7 +121,7 @@ def operator_logout(op: Operator, force: bool) -> None: """ Instructs the operator to perform logout. """ - logger.debug("Performing logout.") + logger.debug("Performing logout...") op.logout(force) logger.info("Logout done.") @@ -131,7 +131,7 @@ def operator_checkin(op: Operator, force: bool) -> None: Instructs the operator to perform the check in. """ logger.debug("Performing check in...") - op.checkin() + op.check_in(force) logger.info("Check in done.") @@ -140,7 +140,7 @@ def operator_checkout(op: Operator, force: bool) -> None: Instructs the operator to perform the check out. """ logger.debug("Performing check out...") - op.checkout() + op.check_out(force) logger.info("Check out done.") @@ -175,24 +175,34 @@ def daemon_process( debug=debug, ) - def stop_all() -> None: - pass + def _stop_all() -> None: + logger.debug("SIGTERM...stopping all the clients...") + clients = PLifo.All(lifo_path) + with Fifo(fifo_path) as fifo: + for client in clients: + fifo.write(cmd_marshal(name=client, cmd="stop")) - def reload_all() -> None: - pass + def _reload_all() -> None: + logger.debug("SIGUSR1 received here.") + clients = PLifo.All(lifo_path) + with Fifo(fifo_path) as fifo: + for client in clients: + fifo.write(cmd_marshal(name=client, cmd="reload")) - def list_all() -> None: - pass + def _list_all() -> None: + logger.debug("SIGUSR2 received here.") + clients = PLifo.All(lifo_path) + logger.info("Client list: %s", clients) context = daemon.DaemonContext( working_directory=working_dir, umask=umask, pidfile=pidfile ) logger.debug("context defined") context.signal_map = { - signal.SIGTERM: stop_all, + signal.SIGTERM: _stop_all, signal.SIGHUP: "terminate", - signal.SIGUSR1: reload_all, - signal.SIGUSR2: list_all, + signal.SIGUSR1: _reload_all, + signal.SIGUSR2: _list_all, } logger.debug("signal map defined") cmd_map = {