Update for add more component for devbox status command

This commit is contained in:
Tianyong Qiu 2025-02-11 10:15:53 +08:00
parent 96a5e7a870
commit b363f50ae7

View File

@ -1855,8 +1855,6 @@ devbox_status_command() {
local devbox_container_id=$(cat "${WORKING_HOME}/.devbox-instance") local devbox_container_id=$(cat "${WORKING_HOME}/.devbox-instance")
echo "==> Checking DevBox services status..."
# If the DevBox container devbox_container_id is not running, exit # If the DevBox container devbox_container_id is not running, exit
if ! docker ps --no-trunc --format '{{.ID}}' | grep -q "^${devbox_container_id}\$"; then if ! docker ps --no-trunc --format '{{.ID}}' | grep -q "^${devbox_container_id}\$"; then
echo "==> DevBox container is not running." echo "==> DevBox container is not running."
@ -1866,7 +1864,7 @@ devbox_status_command() {
# If no component is specified, check all components # If no component is specified, check all components
if [[ -z "$COMPONENT" ]]; then if [[ -z "$COMPONENT" ]]; then
COMPONENTS=("mongodb" "rabbitmq" "backend" "frontend") COMPONENTS=("mongodb" "rabbitmq" "backend" "frontend" "devsvc" "payment" "content" "central_storage" "authentication")
else else
COMPONENTS=("$COMPONENT") COMPONENTS=("$COMPONENT")
fi fi
@ -1880,57 +1878,145 @@ devbox_status_command() {
local container_id local container_id
container_id=$(cat "${WORKING_HOME}/.mongodb-instance") container_id=$(cat "${WORKING_HOME}/.mongodb-instance")
if docker ps --no-trunc --format '{{.ID}}' | grep -q "^${container_id}\$"; then if docker ps --no-trunc --format '{{.ID}}' | grep -q "^${container_id}\$"; then
echo "==> MongoDB container is running." echo "[RESULT]: MongoDB container is running."
else else
echo "==> MongoDB container is not running." echo "[RESULT]: MongoDB container is not running."
fi fi
else else
echo "==> MongoDB container is not running." echo "[RESULT]: MongoDB container is not running."
fi fi
;; ;;
"rabbitmq") "rabbitmq")
echo "==> Checking RabbitMQ status..." echo "==> Checking RabbitMQ status..."
if [[ -f "${WORKING_HOME}/.rabbitmq-instance" ]]; then if [[ -f "${WORKING_HOME}/.rabbitmq-instance" ]]; then
local container_id local container_id
container_id=$(cat "${WORKING_HOME}/.rabbitmq-instance") container_id=$(cat "${WORKING_HOME}/.rabbitmq-instance")
if docker ps --no-trunc --format '{{.ID}}' | grep -q "^${container_id}\$"; then if docker ps --no-trunc --format '{{.ID}}' | grep -q "^${container_id}\$"; then
echo "==> RabbitMQ container is running." echo "[RESULT]: RabbitMQ container is running."
else else
echo "==> RabbitMQ container is not running." echo "[RESULT]: RabbitMQ container is not running."
fi fi
else else
echo "==> RabbitMQ container is not running." echo "[RESULT]: RabbitMQ container is not running."
fi fi
;; ;;
"backend") "backend")
echo "==> Checking backend service status..." echo "==> Checking backend service status..."
if [[ -f "${WORKING_HOME}/.devbox-instance" ]]; then if [[ -f "${WORKING_HOME}/.devbox-instance" ]]; then
local container_id local container_id
container_id=$(cat "${WORKING_HOME}/.devbox-instance") container_id=$(cat "${WORKING_HOME}/.devbox-instance")
if docker ps --no-trunc --format '{{.ID}}' | grep -q "^${container_id}\$"; then if docker ps --no-trunc --format '{{.ID}}' | grep -q "^${container_id}\$"; then
echo "==> Backend service is running." if [[ -f "${WORKING_HOME}/.backend.pid" ]]; then
local backend_pid
backend_pid=$(cat "${WORKING_HOME}/.backend.pid")
if docker exec -i "$container_id" ps -p "$backend_pid" &>/dev/null; then
echo "[RESULT]: Backend service is running."
else
echo "[RESULT]: Backend service is not running."
fi
else
echo "[RESULT]: Backend service is not running."
fi
else else
echo "==> Backend service is not running." echo "[RESULT]: Backend service is not running."
fi fi
else
echo "==> Backend service is not running."
fi fi
;; ;;
"frontend") "frontend")
echo "==> Checking frontend service status..." echo "==> Checking frontend service status..."
if [[ -f "${WORKING_HOME}/.devbox-instance" ]]; then if [[ -f "${WORKING_HOME}/.devbox-instance" ]]; then
local container_id local container_id
container_id=$(cat "${WORKING_HOME}/.devbox-instance") container_id=$(cat "${WORKING_HOME}/.devbox-instance")
if docker ps --no-trunc --format '{{.ID}}' | grep -q "^${container_id}\$"; then if docker ps --no-trunc --format '{{.ID}}' | grep -q "^${container_id}\$"; then
echo "==> Frontend service is running." if [[ -f "${WORKING_HOME}/.frontend.pid" ]]; then
local frontend_pid
frontend_pid=$(cat "${WORKING_HOME}/.frontend.pid")
if docker exec -i "$container_id" ps -p "$frontend_pid" &>/dev/null; then
echo "[RESULT]: Frontend service is running."
else
echo "[RESULT]: Frontend service is not running."
fi
else
echo "[RESULT]: Frontend service is not running."
fi
else else
echo "==> Frontend service is not running." echo "[RESULT]: Frontend service is not running."
fi fi
else
echo "==> Frontend service is not running."
fi fi
;; ;;
"devsvc")
echo "==> Checking devsvc service status..."
if [[ -f "${WORKING_HOME}/.devsvc-instance" ]]; then
local container_id
container_id=$(cat "${WORKING_HOME}/.devsvc-instance")
if docker ps --no-trunc --format '{{.ID}}' | grep -q "^${container_id}\$"; then
echo "[RESULT]: devsvc container is running."
else
echo "[RESULT]: devsvc container is not running."
fi
else
echo "[RESULT]: devsvc container is not running."
fi
;;
"payment")
echo "==> Checking payment service status..."
if [[ -f "${WORKING_HOME}/.payment-instance" ]]; then
local container_id
container_id=$(cat "${WORKING_HOME}/.payment-instance")
if docker ps --no-trunc --format '{{.ID}}' | grep -q "^${container_id}\$"; then
echo "[RESULT]: payment container is running."
else
echo "[RESULT]: payment container is not running."
fi
else
echo "[RESULT]: payment container is not running."
fi
;;
"content")
echo "==> Checking content service status..."
if [[ -f "${WORKING_HOME}/.content-instance" ]]; then
local container_id
container_id=$(cat "${WORKING_HOME}/.content-instance")
if docker ps --no-trunc --format '{{.ID}}' | grep -q "^${container_id}\$"; then
echo "[RESULT]: content container is running."
else
echo "[RESULT]: content container is not running."
fi
else
echo "[RESULT]: content container is not running."
fi
;;
"central_storage")
echo "==> Checking central_storage service status..."
if [[ -f "${WORKING_HOME}/.central_storage-instance" ]]; then
local container_id
container_id=$(cat "${WORKING_HOME}/.central_storage-instance")
if docker ps --no-trunc --format '{{.ID}}' | grep -q "^${container_id}\$"; then
echo "[RESULT]: central_storage container is running."
else
echo "[RESULT]: central_storage container is not running."
fi
else
echo "[RESULT]: central_storage container is not running."
fi
;;
"authentication")
echo "==> Checking authentication service status..."
if [[ -f "${WORKING_HOME}/.authentication-instance" ]]; then
local container_id
container_id=$(cat "${WORKING_HOME}/.authentication-instance")
if docker ps --no-trunc --format '{{.ID}}' | grep -q "^${container_id}\$"; then
echo "[RESULT]: authentication container is running."
else
echo "[RESULT]: authentication container is not running."
fi
else
echo "[RESULT]: authentication container is not running."
fi
;;
*) *)
echo "ERROR: Unknown component: $comp" echo "ERROR: Unknown component: $comp"
exit 1 exit 1