From 1888691ee8ccdd8d7d9a600d6f5e5e63cfd46d57 Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Tue, 8 Oct 2024 17:10:56 -0700 Subject: [PATCH] try creating shared libs as 777 when running as root --- archivebox/config/paths.py | 18 +++++++++++++++--- archivebox/config/permissions.py | 2 +- archivebox/logging_util.py | 13 ++++++++----- pyproject.toml | 2 +- uv.lock | 2 +- 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/archivebox/config/paths.py b/archivebox/config/paths.py index 8c3d0fd3..b4aae940 100644 --- a/archivebox/config/paths.py +++ b/archivebox/config/paths.py @@ -95,7 +95,11 @@ def get_LIB_DIR(): if IS_ROOT: # make sure lib dir is owned by the archivebox user, not root with SudoPermission(uid=0): - os.system(f'chown {ARCHIVEBOX_USER}:{ARCHIVEBOX_GROUP} "{lib_dir}"') + if ARCHIVEBOX_USER == 0: + # print(f'[yellow]:warning: Waring: Creating SYSTEM_LIB_DIR {lib_dir} with mode 777 so that non-root archivebox users can share it.[/yellow] (caches shared libs used by archivebox for performance)', file=sys.stderr) + os.system(f'chmod -R 777 "{lib_dir}"') + else: + os.system(f'chown {ARCHIVEBOX_USER}:{ARCHIVEBOX_GROUP} "{lib_dir}"') else: raise PermissionError() except (PermissionError, AssertionError): @@ -129,7 +133,11 @@ def get_TMP_DIR(): if not dir_is_writable(run_dir): if IS_ROOT: with SudoPermission(uid=0, fallback=False): - os.system(f'chown {ARCHIVEBOX_USER}:{ARCHIVEBOX_GROUP} "{run_dir}"') + if ARCHIVEBOX_USER == 0: + # print(f'[yellow]:warning: Waring: Creating SYSTEM_TMP_DIR {run_dir} with mode 777 so that non-root archivebox users can access it.[/yellow]', file=sys.stderr) + os.system(f'chmod -R 777 "{run_dir}"') + else: + os.system(f'chown {ARCHIVEBOX_USER}:{ARCHIVEBOX_GROUP} "{run_dir}"') else: raise PermissionError() assert len(str(run_dir / 'supervisord.conf')) < 95, 'SYSTEM_TMP_DIR path is too long, please set SYSTEM_TMP_DIR env variable to a shorter path (unfortunately unix requires socket paths be < 108 chars)' @@ -148,7 +156,11 @@ def get_TMP_DIR(): if not dir_is_writable(run_dir): if IS_ROOT: with SudoPermission(uid=0): - os.system(f'chown {ARCHIVEBOX_USER}:{ARCHIVEBOX_GROUP} "{run_dir}"') + if ARCHIVEBOX_USER == 0: + # print(f'[yellow]:warning: Waring: Creating SYSTEM_TMP_DIR {run_dir} with mode 777 so that non-root archivebox users can access it.[/yellow]', file=sys.stderr) + os.system(f'chmod -R 777 "{run_dir}"') + else: + os.system(f'chown {ARCHIVEBOX_USER}:{ARCHIVEBOX_GROUP} "{run_dir}"') else: raise PermissionError() diff --git a/archivebox/config/permissions.py b/archivebox/config/permissions.py index 2f5c49ff..916298de 100644 --- a/archivebox/config/permissions.py +++ b/archivebox/config/permissions.py @@ -85,7 +85,7 @@ except Exception: ############################################################################################# def drop_privileges(): - """If running as root, drop privileges to the user that owns the data dir (or PUID, or default=911)""" + """If running as root, drop privileges to the user that owns the data dir (or PUID)""" # always run archivebox as the user that owns the data dir, never as root if os.getuid() == 0: diff --git a/archivebox/logging_util.py b/archivebox/logging_util.py index 7d727e23..f4503a1f 100644 --- a/archivebox/logging_util.py +++ b/archivebox/logging_util.py @@ -573,11 +573,14 @@ def printable_folder_status(name: str, folder: Dict) -> str: if folder['path']: if os.access(folder['path'], os.R_OK): - num_files = ( - f'{len(os.listdir(folder["path"]))} files' - if Path(folder['path']).is_dir() else - printable_filesize(Path(folder['path']).stat().st_size) - ) + try: + num_files = ( + f'{len(os.listdir(folder["path"]))} files' + if os.path.isdir(folder['path']) else + printable_filesize(Path(folder['path']).stat().st_size) + ) + except PermissionError: + num_files = 'error' else: num_files = 'missing' diff --git a/pyproject.toml b/pyproject.toml index 7d20ca03..61494a51 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "archivebox" -version = "0.8.5rc11" +version = "0.8.5rc12" requires-python = ">=3.10" description = "Self-hosted internet archiving solution." authors = [{name = "Nick Sweeting", email = "pyproject.toml@archivebox.io"}] diff --git a/uv.lock b/uv.lock index b6ea27ce..8bdba510 100644 --- a/uv.lock +++ b/uv.lock @@ -41,7 +41,7 @@ wheels = [ [[package]] name = "archivebox" -version = "0.8.5rc11" +version = "0.8.5rc12" source = { editable = "." } dependencies = [ { name = "atomicwrites" },