feat: add cc-connect start/stop controls
Deploy Dashboard (Dev) / deploy-dev (push) Has been cancelled
Deploy Dashboard (Dev) / deploy-dev (push) Has been cancelled
Add backend start/stop endpoints and wire cc-connect UI controls to toggle container state with post-action health refresh and clear error handling. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -10,15 +10,96 @@ router = APIRouter()
|
||||
client = docker.DockerClient(base_url=DOCKER_HOST, timeout=5)
|
||||
|
||||
|
||||
def _get_cc_connect_container():
|
||||
matches = client.containers.list(all=True, filters={"name": "cc-connect"})
|
||||
return matches[0] if matches else None
|
||||
|
||||
|
||||
@router.post("/start")
|
||||
def start_cc_connect():
|
||||
try:
|
||||
container = _get_cc_connect_container()
|
||||
except Exception as exc:
|
||||
return {
|
||||
"ok": False,
|
||||
"status": "down",
|
||||
"container_status": None,
|
||||
"error": f"docker check failed: {exc}",
|
||||
}
|
||||
|
||||
if not container:
|
||||
return {
|
||||
"ok": False,
|
||||
"status": "down",
|
||||
"container_status": "not_found",
|
||||
"error": "cc-connect container not found",
|
||||
}
|
||||
|
||||
try:
|
||||
container.start()
|
||||
container.reload()
|
||||
container_status = container.status
|
||||
return {
|
||||
"ok": container_status == "running",
|
||||
"status": "up" if container_status == "running" else "down",
|
||||
"container_status": container_status,
|
||||
"error": None if container_status == "running" else "cc-connect failed to start",
|
||||
}
|
||||
except Exception as exc:
|
||||
return {
|
||||
"ok": False,
|
||||
"status": "down",
|
||||
"container_status": container.status,
|
||||
"error": f"docker start failed: {exc}",
|
||||
}
|
||||
|
||||
|
||||
@router.post("/stop")
|
||||
def stop_cc_connect():
|
||||
try:
|
||||
container = _get_cc_connect_container()
|
||||
except Exception as exc:
|
||||
return {
|
||||
"ok": False,
|
||||
"status": "down",
|
||||
"container_status": None,
|
||||
"error": f"docker check failed: {exc}",
|
||||
}
|
||||
|
||||
if not container:
|
||||
return {
|
||||
"ok": False,
|
||||
"status": "down",
|
||||
"container_status": "not_found",
|
||||
"error": "cc-connect container not found",
|
||||
}
|
||||
|
||||
try:
|
||||
container.stop()
|
||||
container.reload()
|
||||
container_status = container.status
|
||||
return {
|
||||
"ok": container_status != "running",
|
||||
"status": "down",
|
||||
"container_status": container_status,
|
||||
"error": None if container_status != "running" else "cc-connect failed to stop",
|
||||
}
|
||||
except Exception as exc:
|
||||
return {
|
||||
"ok": False,
|
||||
"status": "down",
|
||||
"container_status": container.status,
|
||||
"error": f"docker stop failed: {exc}",
|
||||
}
|
||||
|
||||
|
||||
@router.get("/health")
|
||||
async def cc_connect_health():
|
||||
url = (CC_CONNECT_URL or "").strip()
|
||||
|
||||
container = None
|
||||
try:
|
||||
matches = client.containers.list(all=True, filters={"name": "cc-connect"})
|
||||
if matches:
|
||||
container = matches[0]
|
||||
container = _get_cc_connect_container()
|
||||
except Exception as exc:
|
||||
return {
|
||||
"ok": False,
|
||||
|
||||
Reference in New Issue
Block a user