#!/usr/bin/env python3 # -*- coding: utf-8 -*- """作业 7 · 步骤 1:启动自愈 API。""" from __future__ import annotations import sys from pathlib import Path import _bootstrap # noqa: F401 import _config as C from dify_api import Dify LOCAL_SH = ( Path(__file__).resolve().parents[2] / "scripts_bash_cursor" / "作业7_故障自愈工作流" / "作业7_启动_self_heal.sh" ) def main() -> int: d = Dify(C.DIFY_EMAIL, C.DIFY_PASSWORD) try: d.login() d.sftp.put(str(LOCAL_SH), "/tmp/作业7_启动_self_heal.sh") out, err = d.sh("FORCE_RESTART=1 bash /tmp/作业7_启动_self_heal.sh") print(out or err) out2, _ = d.sh("curl -sf '%s/health'" % C.SELF_HEAL_BASE) if "ok" not in (out2 or ""): print("[FAIL] API 未启动") return 1 print("[OK] 自愈 API %s" % C.SELF_HEAL_BASE) return 0 finally: d.close() if __name__ == "__main__": sys.exit(main())