settings.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import tempfile
  2. from pathlib import Path
  3. from functools import cache
  4. from archivebox.config import CONSTANTS
  5. from archivebox.config.paths import get_collection_id
  6. DATA_DIR = CONSTANTS.DATA_DIR
  7. LOGS_DIR = CONSTANTS.LOGS_DIR
  8. TMP_DIR = CONSTANTS.TMP_DIR
  9. SUPERVISORD_CONFIG_FILE = TMP_DIR / "supervisord.conf"
  10. PID_FILE = TMP_DIR / "supervisord.pid"
  11. SOCK_FILE = TMP_DIR / "supervisord.sock"
  12. LOG_FILE = TMP_DIR / "supervisord.log"
  13. WORKERS_DIR = TMP_DIR / "workers"
  14. @cache
  15. def get_sock_file():
  16. """Get the path to the supervisord socket file, symlinking to a shorter path if needed due to unix path length limits"""
  17. TMP_DIR.mkdir(parents=True, exist_ok=True)
  18. if len(f'file://{SOCK_FILE.absolute().resolve()}') > 98:
  19. # socket absolute paths cannot be longer than 104 bytes on macos, and 108 bytes on linux
  20. # symlink it to a shorter path and use that instead
  21. # place the actual socket file in a shorter tmp dir
  22. # /var/folders/qy/6tpfrpx100j1t4l312nz683m0000gn/T/archivebox_supervisord_3d1e544e.sock
  23. shorter_sock_file = Path(tempfile.gettempdir()) / f"archivebox_supervisord_{get_collection_id()}.sock"
  24. # symlink ./data/tmp/<collection_id>/supervisord.sock -> /var/folders/qy/abc234235/T/archivebox_supervisord_3d1e544e.sock
  25. # for convenience/consistency
  26. symlink = SOCK_FILE
  27. symlink.unlink(missing_ok=True)
  28. symlink.symlink_to(shorter_sock_file)
  29. assert len(f'file://{shorter_sock_file}') <= 98, f'Failed to create supervisord SOCK_FILE, system tmp dir location is too long {shorter_sock_file} (unix only allows 108 characters for socket paths)'
  30. return shorter_sock_file
  31. return SOCK_FILE