#!/usr/bin/env bash set -euo pipefail certificate_domain="${SEA_FTP_CERTIFICATE_DOMAIN:-}" management_domain="${SEA_MANAGEMENT_DOMAIN:-}" if [[ ! "${certificate_domain}" =~ ^[A-Za-z0-9.-]+$ ]] || [[ "${certificate_domain}" == .* ]] || [[ "${certificate_domain}" == *..* ]]; then echo "SEA_FTP_CERTIFICATE_DOMAIN is invalid." >&2 exit 1 fi if [[ ! "${management_domain}" =~ ^[A-Za-z0-9.-]+$ ]] || [[ "${management_domain}" == .* ]] || [[ "${management_domain}" == *..* ]]; then echo "SEA_MANAGEMENT_DOMAIN is invalid." >&2 exit 1 fi SEA_FTP_CERTIFICATE_DOMAIN="${certificate_domain}" /www/server/panel/pyenv/bin/python3 - <<'PY' import json import os import stat import tempfile from pathlib import Path path = Path('/var/lib/sea-vhost/config.json') if not path.is_file() or path.is_symlink(): raise SystemExit('Sea vHost configuration is missing or unsafe') metadata = path.stat() payload = json.loads(path.read_text(encoding='utf-8')) payload['ftp_domain'] = os.environ['SEA_FTP_CERTIFICATE_DOMAIN'].strip().lower() handle, temporary_name = tempfile.mkstemp(prefix='.sea-vhost-config-', dir=str(path.parent), text=True) try: with os.fdopen(handle, 'w', encoding='utf-8') as output: json.dump(payload, output, ensure_ascii=False, indent=2) output.write('\n') output.flush() os.fsync(output.fileno()) os.chmod(temporary_name, stat.S_IMODE(metadata.st_mode)) os.chown(temporary_name, metadata.st_uid, metadata.st_gid) os.replace(temporary_name, path) finally: try: os.unlink(temporary_name) except FileNotFoundError: pass PY systemctl restart sea-vhost-agent sea-vhost-panel-broker sea-vhost-api healthy=false for _ in {1..30}; do health="$(curl --fail --silent --show-error --max-time 3 --header "Host: ${management_domain}" http://127.0.0.1:8080/healthz 2>/dev/null || true)" if [[ "${health}" == *'"status":"ok"'* ]]; then healthy=true break fi sleep 1 done if [[ "${healthy}" == "true" ]]; then echo "Sea vHost FTP host-reuse mode update: success" # Do not exit here: panel-run-task appends its completion marker after this # script, and an explicit exit would prevent the caller from observing it. true else echo "Sea vHost API did not become healthy after the FTP mode update." >&2 exit 1 fi