From 30bfdf1fa292b2f60b3421fea91aefcb9af197f7 Mon Sep 17 00:00:00 2001 From: Tianyong Qiu Date: Tue, 11 Feb 2025 11:16:03 +0800 Subject: [PATCH] Update to add more component stop and start logic --- devbox/devbox.local/devbox | 62 +++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/devbox/devbox.local/devbox b/devbox/devbox.local/devbox index edbd595..a64202d 100644 --- a/devbox/devbox.local/devbox +++ b/devbox/devbox.local/devbox @@ -1540,7 +1540,7 @@ devbox_start_command() { # If no component is specified, start all components if [[ -z "$COMPONENT" ]]; then - COMPONENTS=("mongodb" "rabbitmq" "backend" "frontend") + COMPONENTS=("mongodb" "rabbitmq" "backend" "frontend" "devsvc" "payment" "content" "central_storage" "authentication") else COMPONENTS=("$COMPONENT") fi @@ -1757,6 +1757,27 @@ EOF fi 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" exit 1 @@ -1778,11 +1799,9 @@ devbox_stop_command() { local COMPONENT="$(get_arg '--component')" local WORKING_HOME="$(get_arg '--working-home' "${HOME}/.devbox")" - echo "==> Stopping DevBox services..." - # If the DevBox container is not running, exit if [[ -z "$COMPONENT" ]]; then - COMPONENTS=("mongodb" "rabbitmq" "backend" "frontend") + COMPONENTS=("mongodb" "rabbitmq" "backend" "frontend" "devsvc" "payment" "content" "central_storage" "authentication") else COMPONENTS=("$COMPONENT") fi @@ -1830,6 +1849,16 @@ devbox_stop_command() { echo "==> Frontend service is not running." 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" exit 1 @@ -2055,13 +2084,11 @@ devbox_restart_command() { fi if [[ -z "$COMPONENT" ]]; then - COMPONENTS=("mongodb" "rabbitmq" "backend" "frontend") + COMPONENTS=("mongodb" "rabbitmq" "backend" "frontend" "devsvc" "payment" "content" "central_storage" "authentication") else COMPONENTS=("$COMPONENT") fi - echo "==> Restarting DevBox services..." - # Stop the specified components for comp in "${COMPONENTS[@]}"; do case "$comp" in @@ -2105,6 +2132,16 @@ devbox_restart_command() { echo "==> Frontend service is not running." 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" exit 1 @@ -2213,7 +2250,6 @@ EOF # Start frontend service in the container docker exec -i "$DEVBOX_NAME" bash < Frontend service is not running." 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" exit 1