fix: update au lieu de fuse

This commit is contained in:
administrateur 2025-03-30 07:18:56 +02:00
parent 80796c20a0
commit 431d50267a

View File

@ -3,6 +3,7 @@ import os
import subprocess import subprocess
import redis import redis
from threading import Lock from threading import Lock
import shutil
app = Flask(__name__) app = Flask(__name__)
@ -53,21 +54,17 @@ encoding = Slash,BackSlash,Colon,Dot
return config_path return config_path
def mount_nextcloud(website, mount_path="/mnt"): def rclone_sync(website, local_path):
config_file = write_rclone_config() config_file = write_rclone_config()
remote_path = f"nextcloud:{NEXTCLOUD_PATH}/@{website}" remote_path = f"nextcloud:{NEXTCLOUD_PATH}/@{website}"
log_debug(f"Mounting {remote_path} to {mount_path}") if os.path.exists(local_path):
os.makedirs(mount_path, exist_ok=True) shutil.rmtree(local_path)
os.makedirs(local_path, exist_ok=True)
# Try to unmount first in case of stale mount cmd = f"rclone --config {config_file} sync {remote_path} {local_path} --verbose"
subprocess.run(f"fusermount -u {mount_path}", shell=True, stderr=subprocess.DEVNULL) log_debug(f"Syncing from {remote_path} to {local_path}")
return stream_command(cmd)
cmd = f"rclone --config {config_file} mount {remote_path} {mount_path} --vfs-cache-mode full --daemon"
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
if result.returncode != 0:
raise RuntimeError(f"Failed to mount: {result.stderr}")
def stream_command(cmd): def stream_command(cmd):
log_debug(f"Executing: {cmd}") log_debug(f"Executing: {cmd}")
@ -100,18 +97,18 @@ def build_mkdocs():
log_debug(f"Build already active for website: {website}") log_debug(f"Build already active for website: {website}")
return jsonify({"status": "busy", "message": f"Build already active: {website}"}), 429 return jsonify({"status": "busy", "message": f"Build already active: {website}"}), 429
mount_path = "/mnt" tmp_path = f"/tmp/{website}"
compile_path = f"/tmp/{website}#compile" compile_path = f"{tmp_path}#compile"
final_path = f"/srv/{website}" final_path = f"/srv/{website}"
src = os.path.join(mount_path, "mkdocs.yml") src = os.path.join(tmp_path, "mkdocs.yml")
try: try:
mount_nextcloud(website, mount_path) if rclone_sync(website, tmp_path) != 0:
return jsonify({"status": "error", "message": "rclone sync failed"}), 500
log_debug(f"Checking if mkdocs.yml exists at {src}")
if not os.path.exists(src): if not os.path.exists(src):
log_debug(f"{src} not found after mount") log_debug(f"{src} not found after rclone sync")
return jsonify({"error": f"{src} not found after mount"}), 404 return jsonify({"error": f"{src} not found after sync"}), 404
log_debug(f"Running MkDocs build: {src} -> {compile_path}") log_debug(f"Running MkDocs build: {src} -> {compile_path}")
mkdocs_cmd = f"mkdocs build --no-strict --config-file {src} --site-dir {compile_path}" mkdocs_cmd = f"mkdocs build --no-strict --config-file {src} --site-dir {compile_path}"
@ -128,8 +125,7 @@ def build_mkdocs():
finally: finally:
redis_client.delete(lock_key) redis_client.delete(lock_key)
subprocess.run(f"fusermount -u {mount_path}", shell=True, stderr=subprocess.DEVNULL) log_debug(f"Redis lock released for website: {website}")
log_debug(f"Redis lock released and mount cleaned for website: {website}")
if __name__ == "__main__": if __name__ == "__main__":
log_debug("Starting Flask server on 0.0.0.0:80") log_debug("Starting Flask server on 0.0.0.0:80")