aspans_patrol/scripts/server-check.sh
2026-10-22 10:53:02 +05:00

85 lines
3.4 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# Диагностика сервера перед развёртыванием «Обходов». Только читает, ничего не меняет и не ставит.
# Запуск с локальной машины: ssh user@IP 'bash -s' < scripts/server-check.sh
# Команды, которым нужен root, выполняются через sudo -n (без пароля) или пропускаются.
section() { printf '\n===== %s =====\n' "$1"; }
have() { command -v "$1" >/dev/null 2>&1; }
asroot() { if [ "$(id -u)" = 0 ]; then "$@"; elif sudo -n true 2>/dev/null; then sudo -n "$@"; else echo "(нужен root — пропущено: $*)"; return 1; fi; }
section "Система"
uname -srm
[ -r /etc/os-release ] && . /etc/os-release && echo "$PRETTY_NAME"
echo "Пользователь: $(id -un), группы: $(id -Gn)"
uptime
section "Процессор и память"
echo "CPU: $(nproc) ядер, $(uname -m)"
free -h
swapon --show 2>/dev/null || true
section "Диск"
df -hT -x tmpfs -x devtmpfs -x overlay 2>/dev/null || df -h
echo
df -i / | tail -1 | awk '{print "inodes на /: занято " $5}'
section "Docker"
if have docker; then
docker version --format 'Docker {{.Server.Version}} ({{.Server.Os}}/{{.Server.Arch}})' 2>&1
docker compose version 2>&1 || echo "docker compose (v2) НЕ найден"
echo "Каталог данных: $(docker info --format '{{.DockerRootDir}}' 2>/dev/null)"
root=$(docker info --format '{{.DockerRootDir}}' 2>/dev/null)
[ -n "$root" ] && df -h "$root" 2>/dev/null | tail -1 | awk '{print "Свободно под Docker: " $4 " из " $2}'
echo
docker system df 2>&1
echo
echo "Контейнеры:"
docker ps -a --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}' 2>&1
echo
echo "Сети:"
docker network ls --format '{{.Name}}\t{{.Driver}}' 2>&1
echo
echo "Compose-проекты:"
docker compose ls -a 2>&1
else
echo "Docker НЕ установлен"
fi
section "Слушающие порты"
if have ss; then
asroot ss -tulpn 2>/dev/null || ss -tuln
else
netstat -tuln 2>/dev/null || echo "нет ss/netstat"
fi
echo
for p in 80 443 8090; do
if ss -tln 2>/dev/null | awk '{print $4}' | grep -Eq "[:.]$p$"; then echo "порт $p: ЗАНЯТ"; else echo "порт $p: свободен"; fi
done
section "Файрвол"
if have ufw; then asroot ufw status verbose; fi
if have firewall-cmd; then asroot firewall-cmd --list-all; fi
if have iptables; then asroot iptables -S INPUT 2>/dev/null | head -30; fi
if have nft; then asroot nft list ruleset 2>/dev/null | grep -E 'chain input|policy|dport' | head -30; fi
section "Сеть наружу (код ответа и время)"
for u in \
https://passport.aspans.com \
https://id.aspans.com \
https://git.aspans.com \
https://pk.uchet.kz \
https://nominatim.openstreetmap.org/status \
https://registry-1.docker.io/v2/ \
https://registry.npmjs.org/ \
https://github.com; do
printf '%-45s ' "$u"
curl -sS -o /dev/null -m 10 -w '%{http_code} %{time_total}s' "$u" 2>&1 | tr '\n' ' '; echo
done
printf '%-45s ' "git.aspans.com:2222 (ssh)"
if timeout 5 bash -c 'exec 3<>/dev/tcp/git.aspans.com/2222' 2>/dev/null; then echo открыт; else echo недоступен; fi
section "Адреса сервера"
hostname -I 2>/dev/null || ip -4 addr show scope global | awk '/inet/{print $2}'
section "Готово"