feat: enhance service status check to return container count in logs
Some checks failed
Nix Format Check / check-format (push) Failing after 36s
Some checks failed
Nix Format Check / check-format (push) Failing after 36s
This commit is contained in:
@@ -73,10 +73,10 @@ def cmd_logs(args):
|
|||||||
return run_docker_compose(cmd, service_name=args.service)
|
return run_docker_compose(cmd, service_name=args.service)
|
||||||
|
|
||||||
def check_service_running(service_name):
|
def check_service_running(service_name):
|
||||||
"""Check if service has running containers"""
|
"""Check if service has running containers and return the count"""
|
||||||
compose_file = get_service_path(service_name)
|
compose_file = get_service_path(service_name)
|
||||||
if not compose_file:
|
if not compose_file:
|
||||||
return False
|
return 0
|
||||||
|
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
["docker", "compose", "-f", compose_file, "ps", "--quiet"],
|
["docker", "compose", "-f", compose_file, "ps", "--quiet"],
|
||||||
@@ -84,7 +84,9 @@ def check_service_running(service_name):
|
|||||||
text=True
|
text=True
|
||||||
)
|
)
|
||||||
|
|
||||||
return bool(result.stdout.strip())
|
# Count non-empty lines to get container count
|
||||||
|
containers = [line for line in result.stdout.strip().split('\n') if line]
|
||||||
|
return len(containers)
|
||||||
|
|
||||||
def cmd_list(args):
|
def cmd_list(args):
|
||||||
"""List available Docker services"""
|
"""List available Docker services"""
|
||||||
@@ -102,9 +104,16 @@ def cmd_list(args):
|
|||||||
|
|
||||||
println("Available Docker services:", 'blue')
|
println("Available Docker services:", 'blue')
|
||||||
for service in sorted(services):
|
for service in sorted(services):
|
||||||
is_running = check_service_running(service)
|
container_count = check_service_running(service)
|
||||||
status = "[RUNNING]" if is_running else "[STOPPED]"
|
is_running = container_count > 0
|
||||||
color = "green" if is_running else "red"
|
|
||||||
|
if is_running:
|
||||||
|
status = f"[RUNNING - {container_count} container{'s' if container_count > 1 else ''}]"
|
||||||
|
color = "green"
|
||||||
|
else:
|
||||||
|
status = "[STOPPED]"
|
||||||
|
color = "red"
|
||||||
|
|
||||||
printfe(color, f" - {service:<20} {status}")
|
printfe(color, f" - {service:<20} {status}")
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
Reference in New Issue
Block a user