Files
MOTD/60-docker
2026-02-24 20:06:40 +03:00

61 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
export LANG='en_US.UTF-8'
green="\e[1;32m"
red="\e[1;31m"
yellow="\e[1;33m"
undim="\e[0m"
raw_data=$(docker ps -a --format "{{.Names}}\t{{.Status}}\t{{.Labels}}")
check_status() {
local full_name="$1"
local status="$2"
[ -z "$full_name" ] && return
local name=$(echo "$full_name" | sed -E 's/\.[a-z0-9]{25,26}//g' | sed -E 's/\.[0-9]+$//')
local label="unknown"
local color=$red
if [[ "$status" == *"Paused"* ]]; then
label="paused"
color=$yellow
elif [[ "$status" == *"Restarting"* ]]; then
label="restarting"
color=$yellow
elif [[ "$status" == *"Created"* ]]; then
label="created"
color=$yellow
elif [[ "$status" == *"healthy"* ]] || [[ "$status" == *"Up"* ]]; then
label="up"
color=$green
elif [[ "$status" == *"Exited"* ]]; then
label="exited"
color=$red
fi
printf " %-29s %b%8s%b\n" "$name" "$color" "$label" "$undim"
}
process_group() {
local data="$1"
echo "$data" | sort | while IFS=$'\t' read -r name status labels; do
check_status "$name" "$status"
done
}
printf "\nDocker status:\n"
printf " Game Servers:\n"
process_group "$(echo "$raw_data" | grep "game_server")"
printf "\n Media:\n"
process_group "$(echo "$raw_data" | grep "media")"
printf "\n Other:\n"
process_group "$(echo "$raw_data" | grep -vE "game_server|media")"
printf "\n"