Add self-contained automated server upgrade package

This commit is contained in:
admin committed 2026-09-10 14:23:31 +02:00
1 parent 4d58fc7b66
commit 8e6c9a058f
14 files changed
+908 -26

No files matched your search

+31 -1
View File
@@ -13,6 +13,7 @@ from pathlib import Path, PurePosixPath
import re
import subprocess
import sys
import time
import tarfile
FORMAT = 2
@@ -201,9 +202,38 @@ def write_status(folder, operation, run_id, code):
os.replace(str(path) + ".tmp", path)
def wait_nextcloud(directory, timeout):
timeout = int(timeout)
if timeout < 1 or timeout > 3600:
raise ValueError("WRITER_DRAIN_TIMEOUT must be 1..3600 seconds")
expected = {os.path.realpath(directory + "/cron.php"), os.path.realpath(directory + "/occ")}
deadline = time.monotonic() + timeout
while True:
found = []
for process in Path("/proc").iterdir():
if not process.name.isdigit() or int(process.name) == os.getpid():
continue
try:
args = (process / "cmdline").read_bytes().split(b"\0")
cwd = os.readlink(process / "cwd")
# Exact script arguments only: do not match this helper's NC_DIR
# argument, unrelated files, or arbitrary shell command strings.
if any(arg and os.path.realpath(os.path.join(cwd, os.fsdecode(arg))) in expected for arg in args):
found.append(process.name)
except (FileNotFoundError, ProcessLookupError):
continue
if not found:
return
if time.monotonic() >= deadline:
raise ValueError("Nextcloud writers still active (PIDs: " + ", ".join(found) + ")")
time.sleep(1)
def main():
op, *args = sys.argv[1:]
if op == "status":
if op == "wait-nextcloud":
wait_nextcloud(*args)
elif op == "status":
write_status(*args)
elif op == "crypt":
crypt(*args)