From 4d3050cbef431524d95ef8f4e642c5111ab5079e Mon Sep 17 00:00:00 2001 From: joschrew <91774427+joschrew@users.noreply.github.com> Date: Wed, 24 Apr 2024 09:29:23 +0200 Subject: [PATCH 1/3] Set permission for network logging files and dirs --- src/ocrd_network/logging_utils.py | 13 ++++++++++++- src/ocrd_utils/config.py | 14 ++++++++++++-- src/ocrd_utils/logging.py | 10 ++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/ocrd_network/logging_utils.py b/src/ocrd_network/logging_utils.py index c20136642..2b9bffa1d 100644 --- a/src/ocrd_network/logging_utils.py +++ b/src/ocrd_network/logging_utils.py @@ -9,11 +9,22 @@ def configure_file_handler_with_formatter(logger: Logger, log_file: Path, mode: file_handler = FileHandler(filename=log_file, mode=mode) file_handler.setFormatter(Formatter(LOG_FORMAT)) logger.addHandler(file_handler) + try: + log_file.chmod(0o666) + except PermissionError: + # if the file exists the permissions are supposed to already fit + pass def get_root_logging_dir(module_name: NetworkLoggingDirs) -> Path: module_log_dir = Path(config.OCRD_NETWORK_LOGS_ROOT_DIR, module_name.value) - module_log_dir.mkdir(parents=True, exist_ok=True) + try: + module_log_dir.mkdir(parents=True, exist_ok=True) + module_log_dir.chmod(0o777) + except PermissionError: + # if the folder exists the permissions are supposed to already fit + pass + return module_log_dir diff --git a/src/ocrd_utils/config.py b/src/ocrd_utils/config.py index d2a373f18..144c96859 100644 --- a/src/ocrd_utils/config.py +++ b/src/ocrd_utils/config.py @@ -162,13 +162,23 @@ def _ocrd_download_timeout_parser(val): description="The root directory where all mets server related socket files are created", parser=lambda val: Path(val), default=(True, Path(gettempdir(), "ocrd_network_sockets"))) -config.OCRD_NETWORK_SOCKETS_ROOT_DIR.mkdir(parents=True, exist_ok=True) +config.OCRD_NETWORK_SOCKETS_ROOT_DIR.mkdir(mode=0o777, parents=True, exist_ok=True) +try: + config.OCRD_NETWORK_SOCKETS_ROOT_DIR.chmod(0o777) +except PermissionError: + # if the folder exists the permissions are supposed to already fit + pass config.add(name="OCRD_NETWORK_LOGS_ROOT_DIR", description="The root directory where all ocrd_network related file logs are stored", parser=lambda val: Path(val), default=(True, Path(gettempdir(), "ocrd_network_logs"))) -config.OCRD_NETWORK_LOGS_ROOT_DIR.mkdir(parents=True, exist_ok=True) +config.OCRD_NETWORK_LOGS_ROOT_DIR.mkdir(mode=0o777, parents=True, exist_ok=True) +try: + config.OCRD_NETWORK_LOGS_ROOT_DIR.chmod(0o777) +except PermissionError: + # if the folder exists the permissions are supposed to already fit + pass config.add("HOME", description="Directory to look for `ocrd_logging.conf`, fallback for unset XDG variables.", diff --git a/src/ocrd_utils/logging.py b/src/ocrd_utils/logging.py index 6245f99b7..1f45ab72c 100644 --- a/src/ocrd_utils/logging.py +++ b/src/ocrd_utils/logging.py @@ -34,6 +34,7 @@ import logging.config from pathlib import Path import sys +from os import chmod from .constants import LOG_FORMAT, LOG_TIMEFMT from .config import config @@ -179,6 +180,15 @@ def initLogging(builtin_only=False, force_reinit=False, silent=not config.OCRD_L if not silent: print(f"[LOGGING] Picked up logging config at {config_file}", file=sys.stderr) logging.config.fileConfig(config_file) + # Set permission of processing-server logfile to 666 to prevent possible permission erros while logging + try: + network_logger = logging.getLogger("ocrd_network") + for handler in network_logger.handlers: + if isinstance(handler, logging.FileHandler): + chmod(handler.baseFilename, 0o666) + except PermissionError: + # if the file exists the permissions are supposed to already fit + pass else: if not silent: print("[LOGGING] Initializing logging with built-in defaults", file=sys.stderr) From 2c4a3fd1e127042d5c1fea8410aa8579e626c158 Mon Sep 17 00:00:00 2001 From: Mehmed Mustafa Date: Fri, 3 May 2024 17:33:48 +0200 Subject: [PATCH 2/3] change permisisons to 774 and 664 --- src/ocrd_network/logging_utils.py | 4 ++-- src/ocrd_utils/config.py | 8 ++++---- src/ocrd_utils/logging.py | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ocrd_network/logging_utils.py b/src/ocrd_network/logging_utils.py index 2b9bffa1d..4899e571b 100644 --- a/src/ocrd_network/logging_utils.py +++ b/src/ocrd_network/logging_utils.py @@ -10,7 +10,7 @@ def configure_file_handler_with_formatter(logger: Logger, log_file: Path, mode: file_handler.setFormatter(Formatter(LOG_FORMAT)) logger.addHandler(file_handler) try: - log_file.chmod(0o666) + log_file.chmod(0o664) except PermissionError: # if the file exists the permissions are supposed to already fit pass @@ -20,7 +20,7 @@ def get_root_logging_dir(module_name: NetworkLoggingDirs) -> Path: module_log_dir = Path(config.OCRD_NETWORK_LOGS_ROOT_DIR, module_name.value) try: module_log_dir.mkdir(parents=True, exist_ok=True) - module_log_dir.chmod(0o777) + module_log_dir.chmod(0o774) except PermissionError: # if the folder exists the permissions are supposed to already fit pass diff --git a/src/ocrd_utils/config.py b/src/ocrd_utils/config.py index 144c96859..d5390d655 100644 --- a/src/ocrd_utils/config.py +++ b/src/ocrd_utils/config.py @@ -162,9 +162,9 @@ def _ocrd_download_timeout_parser(val): description="The root directory where all mets server related socket files are created", parser=lambda val: Path(val), default=(True, Path(gettempdir(), "ocrd_network_sockets"))) -config.OCRD_NETWORK_SOCKETS_ROOT_DIR.mkdir(mode=0o777, parents=True, exist_ok=True) +config.OCRD_NETWORK_SOCKETS_ROOT_DIR.mkdir(mode=0o774, parents=True, exist_ok=True) try: - config.OCRD_NETWORK_SOCKETS_ROOT_DIR.chmod(0o777) + config.OCRD_NETWORK_SOCKETS_ROOT_DIR.chmod(0o774) except PermissionError: # if the folder exists the permissions are supposed to already fit pass @@ -173,9 +173,9 @@ def _ocrd_download_timeout_parser(val): description="The root directory where all ocrd_network related file logs are stored", parser=lambda val: Path(val), default=(True, Path(gettempdir(), "ocrd_network_logs"))) -config.OCRD_NETWORK_LOGS_ROOT_DIR.mkdir(mode=0o777, parents=True, exist_ok=True) +config.OCRD_NETWORK_LOGS_ROOT_DIR.mkdir(mode=0o774, parents=True, exist_ok=True) try: - config.OCRD_NETWORK_LOGS_ROOT_DIR.chmod(0o777) + config.OCRD_NETWORK_LOGS_ROOT_DIR.chmod(0o774) except PermissionError: # if the folder exists the permissions are supposed to already fit pass diff --git a/src/ocrd_utils/logging.py b/src/ocrd_utils/logging.py index 1f45ab72c..a8cd0967c 100644 --- a/src/ocrd_utils/logging.py +++ b/src/ocrd_utils/logging.py @@ -185,7 +185,7 @@ def initLogging(builtin_only=False, force_reinit=False, silent=not config.OCRD_L network_logger = logging.getLogger("ocrd_network") for handler in network_logger.handlers: if isinstance(handler, logging.FileHandler): - chmod(handler.baseFilename, 0o666) + chmod(handler.baseFilename, 0o664) except PermissionError: # if the file exists the permissions are supposed to already fit pass From 96a56003a1ea06879273ed6af086128fdc34ad45 Mon Sep 17 00:00:00 2001 From: kba Date: Thu, 6 Jun 2024 14:57:24 +0200 Subject: [PATCH 3/3] Revert "change permisisons to 774 and 664" This reverts commit 2c4a3fd1e127042d5c1fea8410aa8579e626c158. --- src/ocrd_network/logging_utils.py | 4 ++-- src/ocrd_utils/config.py | 8 ++++---- src/ocrd_utils/logging.py | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ocrd_network/logging_utils.py b/src/ocrd_network/logging_utils.py index 4899e571b..2b9bffa1d 100644 --- a/src/ocrd_network/logging_utils.py +++ b/src/ocrd_network/logging_utils.py @@ -10,7 +10,7 @@ def configure_file_handler_with_formatter(logger: Logger, log_file: Path, mode: file_handler.setFormatter(Formatter(LOG_FORMAT)) logger.addHandler(file_handler) try: - log_file.chmod(0o664) + log_file.chmod(0o666) except PermissionError: # if the file exists the permissions are supposed to already fit pass @@ -20,7 +20,7 @@ def get_root_logging_dir(module_name: NetworkLoggingDirs) -> Path: module_log_dir = Path(config.OCRD_NETWORK_LOGS_ROOT_DIR, module_name.value) try: module_log_dir.mkdir(parents=True, exist_ok=True) - module_log_dir.chmod(0o774) + module_log_dir.chmod(0o777) except PermissionError: # if the folder exists the permissions are supposed to already fit pass diff --git a/src/ocrd_utils/config.py b/src/ocrd_utils/config.py index d5390d655..144c96859 100644 --- a/src/ocrd_utils/config.py +++ b/src/ocrd_utils/config.py @@ -162,9 +162,9 @@ def _ocrd_download_timeout_parser(val): description="The root directory where all mets server related socket files are created", parser=lambda val: Path(val), default=(True, Path(gettempdir(), "ocrd_network_sockets"))) -config.OCRD_NETWORK_SOCKETS_ROOT_DIR.mkdir(mode=0o774, parents=True, exist_ok=True) +config.OCRD_NETWORK_SOCKETS_ROOT_DIR.mkdir(mode=0o777, parents=True, exist_ok=True) try: - config.OCRD_NETWORK_SOCKETS_ROOT_DIR.chmod(0o774) + config.OCRD_NETWORK_SOCKETS_ROOT_DIR.chmod(0o777) except PermissionError: # if the folder exists the permissions are supposed to already fit pass @@ -173,9 +173,9 @@ def _ocrd_download_timeout_parser(val): description="The root directory where all ocrd_network related file logs are stored", parser=lambda val: Path(val), default=(True, Path(gettempdir(), "ocrd_network_logs"))) -config.OCRD_NETWORK_LOGS_ROOT_DIR.mkdir(mode=0o774, parents=True, exist_ok=True) +config.OCRD_NETWORK_LOGS_ROOT_DIR.mkdir(mode=0o777, parents=True, exist_ok=True) try: - config.OCRD_NETWORK_LOGS_ROOT_DIR.chmod(0o774) + config.OCRD_NETWORK_LOGS_ROOT_DIR.chmod(0o777) except PermissionError: # if the folder exists the permissions are supposed to already fit pass diff --git a/src/ocrd_utils/logging.py b/src/ocrd_utils/logging.py index a8cd0967c..1f45ab72c 100644 --- a/src/ocrd_utils/logging.py +++ b/src/ocrd_utils/logging.py @@ -185,7 +185,7 @@ def initLogging(builtin_only=False, force_reinit=False, silent=not config.OCRD_L network_logger = logging.getLogger("ocrd_network") for handler in network_logger.handlers: if isinstance(handler, logging.FileHandler): - chmod(handler.baseFilename, 0o664) + chmod(handler.baseFilename, 0o666) except PermissionError: # if the file exists the permissions are supposed to already fit pass