Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stop -> kill #34

Merged
merged 3 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pwncore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async def app_lifespan(app: FastAPI):
for db_container in containers:
try:
container = await docker_client.containers.get(db_container["docker_id"])
await container.stop()
await container.kill()
await container.delete()
except (
Exception
Expand Down
4 changes: 2 additions & 2 deletions src/pwncore/routes/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

async def _del_cont(id: str):
container = await docker_client.containers.get(id)
await container.stop()
await container.kill()
await container.delete()


Expand Down Expand Up @@ -95,7 +95,7 @@ async def _create_container(prob: R2Problem, mteam: MetaTeam):
await R2Ports.bulk_create(ports)
except Exception as err:
try:
await container.stop()
await container.kill()
await container.delete()
except Exception:
pass
Expand Down
2 changes: 1 addition & 1 deletion src/pwncore/routes/ctf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async def flag_post(
return {"msg_code": config.msg_codes["db_error"]}

container = await docker_client.containers.get(team_container.docker_id)
await container.stop()
await container.kill()
await container.delete()
#

Expand Down
25 changes: 19 additions & 6 deletions src/pwncore/routes/ctf/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,25 @@ async def start_docker_container(ctf_id: int, response: Response, jwt: RequireJw
return {"msg_code": config.msg_codes["ctf_not_found"]}

team_id = jwt["team_id"] # From JWT
team_container = await Container.get_or_none(team=team_id, problem=ctf_id)
team_container = await Container.filter(team=team_id, problem=ctf_id)
if team_container:
db_ports = await team_container.ports.all().values(
a, b = team_container[0], team_container[1:]
db_ports = await a.ports.all().values(
"port"
) # Get ports from DB
ports = [db_port["port"] for db_port in db_ports] # Create a list out of it
ports = [db_port["port"]
for db_port in db_ports] # Create a list out of it

for db_container in b:
try:
await db_container.delete()
except Exception:
pass

container = await docker_client.containers.get(db_container.docker_id)
await container.kill()
await container.delete()

return {
"msg_code": config.msg_codes["container_already_running"],
"ports": ports,
Expand Down Expand Up @@ -96,7 +109,7 @@ async def start_docker_container(ctf_id: int, response: Response, jwt: RequireJw
await Ports.create(port=port, container=db_container)
except Exception as err:
# Stop the container if failed to make a DB record
await container.stop()
await container.kill()
await container.delete()
logger.exception("Error while starting", exc_info=err)

Expand Down Expand Up @@ -127,7 +140,7 @@ async def stopall_docker_container(response: Response, jwt: RequireJwt):

for db_container in containers:
container = await docker_client.containers.get(db_container["docker_id"])
await container.stop()
await container.kill()
await container.delete()

return {"msg_code": config.msg_codes["containers_team_stop"]}
Expand Down Expand Up @@ -157,7 +170,7 @@ async def stop_docker_container(ctf_id: int, response: Response, jwt: RequireJwt
return {"msg_code": config.msg_codes["db_error"]}

container = await docker_client.containers.get(team_container.docker_id)
await container.stop()
await container.kill()
await container.delete()

return {"msg_code": config.msg_codes["container_stop"]}
Loading