Update to add more component stop and start logic

This commit is contained in:
Tianyong Qiu 2025-02-11 11:16:03 +08:00
parent b363f50ae7
commit 30bfdf1fa2

View File

@ -1540,7 +1540,7 @@ devbox_start_command() {
# If no component is specified, start all components # If no component is specified, start 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
@ -1757,6 +1757,27 @@ EOF
fi fi
EOF EOF
;; ;;
"devsvc" | "payment" | "content" | "central_storage" | "authentication")
echo "==> Starting $comp service..."
# Check if the component container file exists
local component_container_id_file_path="${WORKING_HOME}/.${comp}-instance"
if [[ ! -f "$component_container_id_file_path" ]]; then
echo "ERROR: $comp container is not running. Please run 'devbox init' first."
else
local component_container_id=$(cat "$component_container_id_file_path")
if ! docker ps --no-trunc --format '{{.ID}}' | grep -q "^${component_container_id}\$"; then
echo "==> $comp container is not running, starting container..."
# Start the container
if ! docker start "${component_container_id}"; then
echo "ERROR: Failed to start $comp container."
else
echo "==> $comp container started successfully."
fi
else
echo "==> $comp container is already running."
fi
fi
;;
*) *)
echo "ERROR: Unknown component: $comp" echo "ERROR: Unknown component: $comp"
exit 1 exit 1
@ -1778,11 +1799,9 @@ devbox_stop_command() {
local COMPONENT="$(get_arg '--component')" local COMPONENT="$(get_arg '--component')"
local WORKING_HOME="$(get_arg '--working-home' "${HOME}/.devbox")" local WORKING_HOME="$(get_arg '--working-home' "${HOME}/.devbox")"
echo "==> Stopping DevBox services..."
# If the DevBox container is not running, exit # If the DevBox container is not running, exit
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
@ -1830,6 +1849,16 @@ devbox_stop_command() {
echo "==> Frontend service is not running." echo "==> Frontend service is not running."
fi fi
;; ;;
"devsvc" | "payment" | "content" | "central_storage" | "authentication")
echo "==> Stopping $comp service..."
if [[ -f "${WORKING_HOME}/.${comp}-instance" ]]; then
local container_id
container_id=$(cat "${WORKING_HOME}/.${comp}-instance")
docker stop "$container_id" &>/dev/null || true
else
echo "==> $comp service is not running."
fi
;;
*) *)
echo "ERROR: Unknown component: $comp" echo "ERROR: Unknown component: $comp"
exit 1 exit 1
@ -2055,13 +2084,11 @@ devbox_restart_command() {
fi fi
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
echo "==> Restarting DevBox services..."
# Stop the specified components # Stop the specified components
for comp in "${COMPONENTS[@]}"; do for comp in "${COMPONENTS[@]}"; do
case "$comp" in case "$comp" in
@ -2105,6 +2132,16 @@ devbox_restart_command() {
echo "==> Frontend service is not running." echo "==> Frontend service is not running."
fi fi
;; ;;
"devsvc" | "payment" | "content" | "central_storage" | "authentication")
echo "==> Stopping $comp service..."
if [[ -f "${WORKING_HOME}/.${comp}-instance" ]]; then
local container_id
container_id=$(cat "${WORKING_HOME}/.${comp}-instance")
docker stop "$container_id" &>/dev/null || true
else
echo "==> $comp service is not running."
fi
;;
*) *)
echo "ERROR: Unknown component: $comp" echo "ERROR: Unknown component: $comp"
exit 1 exit 1
@ -2213,7 +2250,6 @@ EOF
# Start frontend service in the container # Start frontend service in the container
docker exec -i "$DEVBOX_NAME" bash <<EOF docker exec -i "$DEVBOX_NAME" bash <<EOF
# Start the frontend service # Start the frontend service
echo "Starting frontend service..."
# Check if /home/.devbox/.frontend.pid exists # Check if /home/.devbox/.frontend.pid exists
if [ -f /home/.devbox/.frontend.pid ]; then if [ -f /home/.devbox/.frontend.pid ]; then
frontend_pid=\$(cat /home/.devbox/.frontend.pid) frontend_pid=\$(cat /home/.devbox/.frontend.pid)
@ -2293,6 +2329,16 @@ EOF
echo "==> Frontend service is not running." echo "==> Frontend service is not running."
fi fi
;; ;;
"devsvc" | "payment" | "content" | "central_storage" | "authentication")
echo "==> Restarting $comp service..."
if [[ -f "${WORKING_HOME}/.${comp}-instance" ]]; then
local container_id
container_id=$(cat "${WORKING_HOME}/.${comp}-instance")
docker start "$container_id" &>/dev/null || true
else
echo "==> $comp service is not running."
fi
;;
*) *)
echo "ERROR: Unknown component: $comp" echo "ERROR: Unknown component: $comp"
exit 1 exit 1