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")