From 326ef108be614b87777363c46d67d665afcb8d93 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Thu, 29 Jan 2026 13:53:41 +0000 Subject: [PATCH] Initial upload: API Mock CLI v0.1.0 --- src/cli/commands/stop.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/cli/commands/stop.py diff --git a/src/cli/commands/stop.py b/src/cli/commands/stop.py new file mode 100644 index 0000000..b45250d --- /dev/null +++ b/src/cli/commands/stop.py @@ -0,0 +1,24 @@ +import os +import click + + +@click.command("stop") +def stop_command(): + pid_file = "api-mock.pid" + if os.path.exists(pid_file): + try: + with open(pid_file, "r") as f: + pid = int(f.read().strip()) + os.kill(pid, 15) + os.remove(pid_file) + click.echo(f"Server stopped (PID: {pid})") + except ProcessLookupError: + click.echo("Server process not found, cleaning up stale PID file") + os.remove(pid_file) + except PermissionError: + click.echo("Permission denied to stop server") + except Exception as e: + click.echo(f"Error stopping server: {e}") + else: + click.echo("No running server found (no PID file)") + click.echo("If a server is running, you may need to kill it manually")