Bash public

Compose Service Status

Share this script safely, inspect its metadata, and copy the exact command you need.

Dashboard

Ready to run

One-liner

Copy the command, then review before execution.
curl -fsSL https://runny.sh/r/7T9VB9KCQEPH | bash

Current version: 1.1 · Updated by Godmode · 2026-09-07 02:38:59.390

At a glance

Script metadata

Slug
7T9VB9KCQEPH
Fetches
0
Size
1860 B · 77 lines
Expires
never
Last fetch
Created
2026-09-07 00:36:00.188
Description
docker compose ps for the current project

Readable before runnable

Preview

#!/usr/bin/env bash
# Compose service status
# Read-only: docker compose ps for the current project. Does not start or stop services.
# Exit 0 if running, 1 if a service is exited/unhealthy or compose is missing, 2 on daemon failure.
# Hosted on Runny.sh. Review the script page before you run it.

set -u

status=0
note() { printf '%s\n' "$*"; }
bump() {
  case $1 in
    crit) status=2 ;;
    warn) [ "$status" -lt 1 ] && status=1 ;;
  esac
}

note "=== Docker Compose service status ==="
note "Cwd:      $(pwd)"
if ! command -v docker >/dev/null 2>&1; then
  note "docker:   CLI not found in PATH"
  note "Result: WARNING"
  exit 1
fi
if ! docker info >/dev/null 2>&1; then
  note "Daemon:   unreachable"
  note "Result: CRITICAL"
  exit 2
fi

run_compose() {
  if docker compose version >/dev/null 2>&1; then
    docker compose "$@"
  elif command -v docker-compose >/dev/null 2>&1; then
    docker-compose "$@"
  else
    return 127
  fi
}

if ! run_compose version >/dev/null 2>&1; then
  note "docker compose plugin not available"
  note "Result: WARNING"
  exit 1
fi

if ! table=$(run_compose ps 2>&1); then
  note "$table"
  note "          WARNING: compose ps failed (no project file?)"
  note "Result: WARNING"
  exit 1
fi
printf '%s\n' "$table"
note ""

bad=$(run_compose ps --format '{{.Name}} {{.Status}}' 2>/dev/null | awk 'BEGIN{IGNORECASE=1} /exit|unhealthy|dead|restarting/ {print}')
if [ -n "${bad}" ]; then
  note "Degraded:"
  printf '%s\n' "$bad" | while IFS= read -r row; do
    [ -n "$row" ] && note "  - ${row}"
  done
  bump warn
  if printf '%s\n' "$bad" | awk 'BEGIN{IGNORECASE=1} /unhealthy|dead|restarting/ {found=1} END {exit !found}'; then
    bump crit
  fi
else
  note "          OK"
fi
note ""

case $status in
  0) note "Result: HEALTHY" ;;
  1) note "Result: WARNING" ;;
  *) note "Result: CRITICAL" ;;
esac
exit "$status"

Raw endpointhttps://runny.sh/r/7T9VB9KCQEPH

See something unsafe?

Report this script

Tell us why it should come down. Anyone can also report a URL at /abuse.

Restore revision