fuck it go back to nested lib and tmp dirs with supervisord sock workaround

This commit is contained in:
Nick Sweeting 2024-10-08 17:48:59 -07:00
parent df68f416fb
commit 4b34b729ab
No known key found for this signature in database
6 changed files with 52 additions and 21 deletions

View file

@ -1,14 +1,33 @@
import tempfile
from pathlib import Path
from archivebox.config import CONSTANTS
from archivebox.config.paths import get_collection_id
DATA_DIR = CONSTANTS.DATA_DIR
LOGS_DIR = CONSTANTS.LOGS_DIR
TMP_DIR = CONSTANTS.TMP_DIR
Path.mkdir(TMP_DIR, exist_ok=True)
SUPERVISORD_CONFIG_FILE = TMP_DIR / "supervisord.conf"
PID_FILE = TMP_DIR / "supervisord.pid"
SOCK_FILE = TMP_DIR / "supervisord.sock"
LOG_FILE = TMP_DIR / "supervisord.log"
WORKERS_DIR = TMP_DIR / "workers"
def get_sock_file():
TMP_DIR.mkdir(parents=True, exist_ok=True)
if len(str(SOCK_FILE)) > 100:
# socket absolute paths cannot be longer than 108 characters on some systems
# symlink it to a shorter path and use that instead
# use tmpfile to atomically overwrite any existing symlink
symlink = Path(tempfile.gettempdir()) / f"archivebox_supervisord_{get_collection_id()}.sock.tmp"
symlink.unlink(missing_ok=True)
symlink.symlink_to(SOCK_FILE)
symlink.rename(str(symlink).replace('.sock.tmp', '.sock'))
assert len(str(symlink)) <= 100, f'Failed to create supervisord SOCK_FILE, system tmp dir location is too long {symlink} (unix only allows 108 characters for socket paths)'
return symlink
return SOCK_FILE

View file

@ -1,6 +1,5 @@
__package__ = 'archivebox.queues'
import os
import time
import signal
import psutil
@ -15,7 +14,7 @@ from xmlrpc.client import ServerProxy
from archivebox.config.permissions import ARCHIVEBOX_USER
from .settings import SUPERVISORD_CONFIG_FILE, DATA_DIR, PID_FILE, SOCK_FILE, LOG_FILE, WORKERS_DIR, TMP_DIR, LOGS_DIR
from .settings import SUPERVISORD_CONFIG_FILE, DATA_DIR, PID_FILE, get_sock_file, LOG_FILE, WORKERS_DIR, TMP_DIR, LOGS_DIR
from typing import Iterator
@ -48,11 +47,11 @@ nocleanup = true
user = {ARCHIVEBOX_USER}
[unix_http_server]
file = {TMP_DIR}/{SOCK_FILE.name}
file = {get_sock_file()}
chmod = 0700
[supervisorctl]
serverurl = unix://{TMP_DIR}/{SOCK_FILE.name}
serverurl = unix://{get_sock_file()}
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
@ -81,12 +80,12 @@ def create_worker_config(daemon):
def get_existing_supervisord_process():
try:
transport = SupervisorTransport(None, None, f"unix://{SOCK_FILE}")
transport = SupervisorTransport(None, None, f"unix://{get_sock_file()}")
server = ServerProxy("http://localhost", transport=transport)
current_state = cast(Dict[str, int | str], server.supervisor.getState())
if current_state["statename"] == "RUNNING":
pid = server.supervisor.getPID()
print(f"[🦸‍♂️] Supervisord connected (pid={pid}) via unix://{str(SOCK_FILE).replace(str(TMP_DIR), 'tmp')}.")
print(f"[🦸‍♂️] Supervisord connected (pid={pid}) via unix://{str(get_sock_file()).replace(str(TMP_DIR), 'tmp')}.")
return server.supervisor
except FileNotFoundError:
return None