shield important tasks properly
This commit is contained in:
@@ -133,7 +133,7 @@ class DaemonInstance:
|
|||||||
future.exception()
|
future.exception()
|
||||||
|
|
||||||
if not tasks_done:
|
if not tasks_done:
|
||||||
self._log.warning(f"terminate remaining task(s)")
|
self._log.warning("terminate remaining task(s)")
|
||||||
for task in pending:
|
for task in pending:
|
||||||
task.cancel()
|
task.cancel()
|
||||||
|
|
||||||
@@ -242,7 +242,11 @@ def main():
|
|||||||
pyinotifyd = get_pyinotifyd_from_config(myname, args.config)
|
pyinotifyd = get_pyinotifyd_from_config(myname, args.config)
|
||||||
daemon = DaemonInstance(pyinotifyd)
|
daemon = DaemonInstance(pyinotifyd)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception(f"config file '{args.config}': {e}")
|
if args.debug:
|
||||||
|
logging.exception(f"config file: {e}")
|
||||||
|
else:
|
||||||
|
logging.error(f"config file: {e}")
|
||||||
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if args.configtest:
|
if args.configtest:
|
||||||
|
|||||||
@@ -162,8 +162,8 @@ class ShellScheduler(TaskScheduler):
|
|||||||
"{src_pathname}", shell_quote(src_pathname))
|
"{src_pathname}", shell_quote(src_pathname))
|
||||||
|
|
||||||
self._log.info(f"{task_id}: execute shell command: {cmd}")
|
self._log.info(f"{task_id}: execute shell command: {cmd}")
|
||||||
proc = await asyncio.create_subprocess_shell(cmd)
|
proc = await asyncio.shield(asyncio.create_subprocess_shell(cmd))
|
||||||
await proc.communicate()
|
await asyncio.shield(proc.communicate())
|
||||||
|
|
||||||
|
|
||||||
class FileManagerRule:
|
class FileManagerRule:
|
||||||
@@ -246,24 +246,33 @@ class FileManagerScheduler(TaskScheduler):
|
|||||||
else:
|
else:
|
||||||
chown = (rule.user, rule.group)
|
chown = (rule.user, rule.group)
|
||||||
|
|
||||||
|
if os.path.isidr(path):
|
||||||
|
mode = rule.dirmode
|
||||||
|
else:
|
||||||
|
mode = rule.filemode
|
||||||
|
|
||||||
|
await asyncio.shield(
|
||||||
|
self._chmod_and_chown(path, mode, chown, task_id))
|
||||||
|
|
||||||
|
if not os.path.isdir(path):
|
||||||
|
return
|
||||||
|
|
||||||
work_on_dirs = not (rule.dirmode is chown is None)
|
work_on_dirs = not (rule.dirmode is chown is None)
|
||||||
work_on_files = not (rule.filemode is chown is None)
|
work_on_files = not (rule.filemode is chown is None)
|
||||||
|
|
||||||
if os.path.isdir(path):
|
|
||||||
await self._chmod_and_chown(path, rule.dirmode, chown, task_id)
|
|
||||||
if work_on_dirs or work_on_files:
|
if work_on_dirs or work_on_files:
|
||||||
for root, dirs, files in os.walk(path):
|
for root, dirs, files in os.walk(path):
|
||||||
if work_on_dirs:
|
if work_on_dirs:
|
||||||
for p in [os.path.join(root, d) for d in dirs]:
|
for p in [os.path.join(root, d) for d in dirs]:
|
||||||
await self._chmod_and_chown(
|
await asyncio.shield(
|
||||||
p, rule.dirmode, chown, task_id)
|
self._chmod_and_chown(
|
||||||
|
p, rule.dirmode, chown, task_id))
|
||||||
|
|
||||||
if work_on_files:
|
if work_on_files:
|
||||||
for p in [os.path.join(root, f) for f in files]:
|
for p in [os.path.join(root, f) for f in files]:
|
||||||
await self._chmod_and_chown(
|
await asyncio.shield(
|
||||||
p, rule.filemode, chown, task_id)
|
self._chmod_and_chown(
|
||||||
else:
|
p, rule.filemode, chown, task_id))
|
||||||
await self._chmod_and_chown(path, rule.filemode, chown, task_id)
|
|
||||||
|
|
||||||
def _get_rule_by_event(self, event):
|
def _get_rule_by_event(self, event):
|
||||||
rule = None
|
rule = None
|
||||||
@@ -313,7 +322,8 @@ class FileManagerScheduler(TaskScheduler):
|
|||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
os.makedirs(dst_dir)
|
os.makedirs(dst_dir)
|
||||||
await self._set_mode_and_owner(first_subdir, rule, task_id)
|
await asyncio.shield(
|
||||||
|
self._set_mode_and_owner(first_subdir, rule, task_id))
|
||||||
|
|
||||||
self._log.info(
|
self._log.info(
|
||||||
f"{task_id}: {rule.action} '{path}' to '{dst}'")
|
f"{task_id}: {rule.action} '{path}' to '{dst}'")
|
||||||
@@ -326,7 +336,8 @@ class FileManagerScheduler(TaskScheduler):
|
|||||||
else:
|
else:
|
||||||
os.rename(path, dst)
|
os.rename(path, dst)
|
||||||
|
|
||||||
await self._set_mode_and_owner(dst, rule, task_id)
|
await asyncio.shield(
|
||||||
|
self._set_mode_and_owner(dst, rule, task_id))
|
||||||
|
|
||||||
elif rule.action == "delete":
|
elif rule.action == "delete":
|
||||||
self._log.info(
|
self._log.info(
|
||||||
|
|||||||
Reference in New Issue
Block a user