-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from Never-Over/bridge-stop
bridge stop
- Loading branch information
Showing
4 changed files
with
60 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import os | ||
import signal | ||
from typing import cast | ||
|
||
import docker | ||
import psutil | ||
from docker.errors import NotFound | ||
from docker.models.containers import Container | ||
|
||
from bridge.console import log_task | ||
from bridge.utils.filesystem import resolve_dot_bridge | ||
|
||
|
||
def stop(): | ||
with log_task("Stopping bridge services...", "All bridge services stopped"): | ||
bridge_path = resolve_dot_bridge() | ||
# Docker - postgres, redis | ||
cid_path = bridge_path / "cid" | ||
if os.path.exists(cid_path): | ||
docker_client = docker.from_env() | ||
with open(cid_path) as f: | ||
for cid in f.readlines(): | ||
cid = cid.strip() | ||
try: | ||
container = docker_client.containers.get(cid) | ||
container = cast(Container, container) | ||
container.stop() | ||
except NotFound: | ||
pass | ||
os.remove(cid_path) | ||
# Processes - celery, flower | ||
for proc in psutil.process_iter(["pid", "name", "cmdline"]): | ||
try: | ||
# Check if the name fragment is in the command line; this field is a list | ||
proc_name = proc.info["cmdline"] | ||
if proc_name and "bridge.service.django_celery" in proc_name: | ||
proc.send_signal(signal.SIGTERM) | ||
except (psutil.NoSuchProcess, psutil.AccessDenied): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[project] | ||
name = "python-bridge" | ||
version = "0.0.24" | ||
version = "0.0.25" | ||
authors = [ | ||
{ name="Caelean Barnes", email="[email protected]" }, | ||
{ name="Evan Doyle", email="[email protected]" }, | ||
|
@@ -32,7 +32,8 @@ dependencies = [ | |
"rich==13.7.1", | ||
"pydantic==2.6.4", | ||
"pyyaml==6.0.1", | ||
"dj-database-url==2.1.0" | ||
"dj-database-url==2.1.0", | ||
"psutil==5.9.8", | ||
] | ||
|
||
[project.urls] | ||
|