Eddited 60-docker
This commit is contained in:
88
60-docker
88
60-docker
@@ -1,64 +1,60 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export LANG='en_US.UTF-8'
|
export LANG='en_US.UTF-8'
|
||||||
# set column width
|
|
||||||
COLUMNS=1
|
|
||||||
# colors
|
|
||||||
green="\e[1;32m"
|
green="\e[1;32m"
|
||||||
red="\e[1;31m"
|
red="\e[1;31m"
|
||||||
yellow="\e[1;33m"
|
yellow="\e[1;33m"
|
||||||
undim="\e[0m"
|
undim="\e[0m"
|
||||||
|
|
||||||
docker_format='docker ps --format "{{.Names}} {{.Status}}" -a'
|
raw_data=$(docker ps -a --format "{{.Names}}\t{{.Status}}\t{{.Labels}}")
|
||||||
game_label='eval "$docker_format" --filter "label=game_server"'
|
|
||||||
traker='eval "$docker_format" --filter "label=traker"'
|
|
||||||
combined='(eval "$docker_format" --filter "label=traker" && eval "$docker_format" --filter "label=game_server") | sort'
|
|
||||||
|
|
||||||
mapfile -t containers < <( comm -2 -3 <( eval "$docker_format" | sort) <( eval "$combined") | sed '/^\s*$/d' | tail -n +1)
|
|
||||||
mapfile -t game_servers < <( eval "$game_label" | sort | sed '/^\s*$/d'| tail -n +1)
|
|
||||||
mapfile -t trakers < <( eval "$traker" | sort | sed '/^\s*$/d'| tail -n +1)
|
|
||||||
|
|
||||||
check_status() {
|
check_status() {
|
||||||
IFS=" " read name status <<< $1
|
local full_name="$1"
|
||||||
replica=$( echo ${name} | sed 's/\([^.]*\)\.\([^.]*\)\.\([^.]*\)/\2/')
|
local status="$2"
|
||||||
name=$( echo ${name} | sed 's/\([^.]*\)\.\([^.]*\)\.\([^.]*\)/\1/')
|
[ -z "$full_name" ] && return
|
||||||
|
|
||||||
if [[ "${status}" == *"healthy"* ]]; then
|
local name=$(echo "$full_name" | sed -E 's/\.[a-z0-9]{25,26}//g' | sed -E 's/\.[0-9]+$//')
|
||||||
_status="${green}healthy${undim}"
|
|
||||||
|
|
||||||
elif [[ "${status}" == *"Restarting"* ]]; then
|
local label="unknown"
|
||||||
_status="${yellow}restarting${undim}"
|
local color=$red
|
||||||
|
|
||||||
elif [[ "${status}" == *"Paused"* ]]; then
|
|
||||||
_status="${yellow}paused${undim}"
|
|
||||||
|
|
||||||
elif [[ "${status}" == *"Up"* ]]; then
|
|
||||||
_status="${green}up${undim}"
|
|
||||||
|
|
||||||
elif [[ "${status}" == *"Created"* ]]; then
|
|
||||||
_status="${yellow}created${undim}"
|
|
||||||
|
|
||||||
elif [[ "${status}" == *"Exited"* ]]; then
|
|
||||||
_status="${red}exited${undim}"
|
|
||||||
|
|
||||||
|
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
|
fi
|
||||||
|
printf " %-29s %b%8s%b\n" "$name" "$color" "$label" "$undim"
|
||||||
_line=${name},${_status}
|
|
||||||
echo -e "${name} ${_status}" | awk '{printf(" %-20s %+20s\n", $1, $2); }'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf "\nDocker status:\n Game Servers:\n"
|
|
||||||
for i in "${!game_servers[@]}"; do
|
|
||||||
check_status "${game_servers[$i]}"
|
|
||||||
done
|
|
||||||
|
|
||||||
printf "\n Tracker:\n"
|
process_group() {
|
||||||
for i in "${!trakers[@]}"; do
|
local data="$1"
|
||||||
check_status "${trakers[$i]}"
|
echo "$data" | sort | while IFS=$'\t' read -r name status labels; do
|
||||||
done
|
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"
|
printf "\n Other:\n"
|
||||||
for i in "${!containers[@]}"; do
|
process_group "$(echo "$raw_data" | grep -vE "game_server|media")"
|
||||||
check_status "${containers[$i]}"
|
|
||||||
done
|
printf "\n"
|
||||||
printf ""
|
|
||||||
|
|||||||
Reference in New Issue
Block a user