feat: init
This commit is contained in:
25
backend/docker_utils.py
Normal file
25
backend/docker_utils.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import os
|
||||
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
NOMADNET_CONTAINER = os.environ.get("NOMADNET_CONTAINER", "nomadnet")
|
||||
|
||||
|
||||
@router.post("/restart")
|
||||
async def restart_nomadnet():
|
||||
try:
|
||||
import docker
|
||||
|
||||
client = docker.from_env()
|
||||
container = client.containers.get(NOMADNET_CONTAINER)
|
||||
container.restart()
|
||||
return {"status": "restarted", "container": NOMADNET_CONTAINER}
|
||||
except docker.errors.NotFound:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail=f"Container '{NOMADNET_CONTAINER}' not found",
|
||||
)
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
Reference in New Issue
Block a user