status.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/bin/bash
  2. ##############################################
  3. # Snapshot 后端服务状态检查脚本
  4. # 适用于 Linux 环境
  5. ##############################################
  6. # 颜色输出
  7. RED='\033[0;31m'
  8. GREEN='\033[0;32m'
  9. YELLOW='\033[1;33m'
  10. BLUE='\033[0;34m'
  11. NC='\033[0m' # No Color
  12. print_info() {
  13. echo -e "${GREEN}[INFO]${NC} $1"
  14. }
  15. print_error() {
  16. echo -e "${RED}[ERROR]${NC} $1"
  17. }
  18. print_warning() {
  19. echo -e "${YELLOW}[WARNING]${NC} $1"
  20. }
  21. echo "============================================"
  22. echo "Snapshot 后端服务状态"
  23. echo "============================================"
  24. echo
  25. # 检查进程
  26. echo "[1] 进程状态"
  27. echo "--------------------------------------------"
  28. PIDS=$(pgrep -f "snapshot-backend-1.0.0.jar")
  29. if [ -n "$PIDS" ]; then
  30. print_info "服务正在运行"
  31. echo "进程ID: $PIDS"
  32. echo
  33. ps -p $PIDS -o pid,ppid,cmd,%mem,%cpu,etime
  34. else
  35. print_warning "服务未运行"
  36. fi
  37. echo
  38. # 检查端口占用
  39. echo "[2] 端口状态"
  40. echo "--------------------------------------------"
  41. if command_exists netstat; then
  42. PORT_INFO=$(netstat -tuln 2>/dev/null | grep :7626)
  43. if [ -n "$PORT_INFO" ]; then
  44. print_info "端口 7626 已被占用"
  45. echo "$PORT_INFO"
  46. else
  47. print_warning "端口 7626 未被占用"
  48. fi
  49. elif command_exists ss; then
  50. PORT_INFO=$(ss -tuln 2>/dev/null | grep :7626)
  51. if [ -n "$PORT_INFO" ]; then
  52. print_info "端口 7626 已被占用"
  53. echo "$PORT_INFO"
  54. else
  55. print_warning "端口 7626 未被占用"
  56. fi
  57. else
  58. print_warning "无法检查端口状态(缺少netstat和ss命令)"
  59. fi
  60. echo
  61. # 检查日志
  62. echo "[3] 日志信息"
  63. echo "--------------------------------------------"
  64. if [ -f "app.log" ]; then
  65. print_info "日志文件存在: app.log"
  66. LOG_SIZE=$(du -h app.log | cut -f1)
  67. echo "文件大小: $LOG_SIZE"
  68. echo
  69. echo "最近20行日志:"
  70. echo "--------------------------------------------"
  71. tail -n 20 app.log
  72. echo "--------------------------------------------"
  73. echo
  74. echo "查看完整日志: tail -f app.log"
  75. else
  76. print_warning "日志文件不存在"
  77. fi
  78. echo
  79. # 健康检查
  80. echo "[4] 健康检查"
  81. echo "--------------------------------------------"
  82. if command_exists curl; then
  83. HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:7626 2>/dev/null)
  84. if [ "$HTTP_CODE" = "200" ]; then
  85. print_info "HTTP健康检查通过 (200)"
  86. elif [ -n "$HTTP_CODE" ] && [ "$HTTP_CODE" != "000" ]; then
  87. print_warning "HTTP响应: $HTTP_CODE"
  88. else
  89. print_error "无法连接到服务"
  90. fi
  91. else
  92. print_warning "未找到curl命令,跳过HTTP健康检查"
  93. fi
  94. echo
  95. # JVM信息(如果进程在运行)
  96. if [ -n "$PIDS" ]; then
  97. echo "[5] JVM信息"
  98. echo "--------------------------------------------"
  99. if command_exists jps; then
  100. print_info "Java进程信息:"
  101. jps -lvm | grep snapshot
  102. fi
  103. echo
  104. fi
  105. echo "============================================"