diff --git a/devbox/cli/devbox b/devbox/cli/devbox index 7e05f6a..f98075e 100755 --- a/devbox/cli/devbox +++ b/devbox/cli/devbox @@ -49,6 +49,7 @@ exit_with_message() { exit $code } + detect_os() { if [[ "$OSTYPE" == "darwin"* ]]; then echo "darwin" @@ -461,11 +462,11 @@ inspect_args() { install_docker() { - log_info "==> Installing Docker..." + log_info "Installing Docker..." # Check if Docker is already installed if command -v docker &>/dev/null; then - log_info "==> Docker is already installed." + log_info "Docker is already installed." return 0 fi @@ -541,55 +542,55 @@ install_docker() { } check_docker_running() { - log_info "==> Checking if Docker service is running..." + log_info "Checking if Docker service is running..." # if Docker CLI is installed and Docker daemon is running if docker info >/dev/null 2>&1; then - log_info "==> Docker is running." + log_info "Docker is running." return 0 fi # if running on WSL, check for Docker socket if grep -qi microsoft /proc/version; then - log_info " Detected WSL environment. Verifying /var/run/docker.sock..." + log_info "Detected WSL environment. Verifying /var/run/docker.sock..." if [ -S /var/run/docker.sock ]; then - log_info "==> Docker socket found. Docker should be available via Docker Desktop." + log_info "Docker socket found. Docker should be available via Docker Desktop." return 0 else - log_error " Docker socket not found in WSL environment." + log_error "Docker socket not found in WSL environment." return 1 fi fi - log_info "==> Docker is not running. Attempting to start it..." + log_info "Docker is not running. Attempting to start it..." # Start Docker service using systemctl or service command if command -v systemctl &>/dev/null; then if systemctl list-units --type=service | grep -q "docker.service"; then - log_info "==> Starting Docker with systemctl..." - sudo systemctl start docker && log_info "==> Docker started successfully." && return 0 + log_info "Starting Docker with systemctl..." + sudo systemctl start docker && log_info "Docker started successfully." && return 0 fi fi if command -v service &>/dev/null; then if service --status-all | grep -q "docker"; then - log_info "==> Starting Docker with service..." - sudo service docker start && log_info "==> Docker started successfully." && return 0 + log_info "Starting Docker with service..." + sudo service docker start && log_info "Docker started successfully." && return 0 fi fi if command -v snap &>/dev/null && snap list | grep -q "docker"; then - log_info "==> Starting Docker with snap..." - sudo snap start docker && log_info "==> Docker started successfully." && return 0 + log_info "Starting Docker with snap..." + sudo snap start docker && log_info "Docker started successfully." && return 0 fi - log_error " Unable to start Docker automatically. Please start it manually." + log_error "Unable to start Docker automatically. Please start it manually." return 1 } build_local_image() { local dockerfile_path="$1" - log_info "==> [Build] use Dockerfile: $(grep '^FROM' "$dockerfile_path")" + log_info "[Build] use Dockerfile: $(grep '^FROM' "$dockerfile_path")" # Check if the image already exists docker rmi -f $devbox_full_image 2>/dev/null || true @@ -634,17 +635,6 @@ get_port() { done } -# Build the local image -build_local_image() { - local dockerfile_path="$1" - log_info "==> [BUILD] Building local image..." - docker buildx build \ - --platform linux/amd64 \ - --build-arg BUILDARCH="x86-64-v3" \ - -t $devbox_full_image \ - -f "$dockerfile_path" . -} - ############################################### # Initialize the development environment @@ -794,18 +784,37 @@ if true ; then # 3️⃣ Clean up old dependencies if [ -f "pnpm-lock.yaml" ]; then - mv pnpm-lock.yaml /tmp/pnpm-lock.yaml.bak + cp pnpm-lock.yaml /tmp/pnpm-lock.yaml.bak fi - rm -rf node_modules pnpm-lock.yaml + rm -rf node_modules # 4️⃣ Install dependencies (ensuring lockfile updates) - pnpm install --no-frozen-lockfile + pnpm install --no-frozen-lockfile \\ + --shamefully-hoist \\ + --link-workspace-packages false \\ + --store-dir /home/devbox/.pnpm-store + + # 4️⃣ Build the frontend pnpm run build - echo "==> [INIT] Backend and frontend environment initialization completed." + + # 5️⃣ Check git status + echo + echo "[INIT] \$(date '+%Y-%m-%d %H:%M:%S') Checking git status..." + echo + + git config --global --add safe.directory /home/devbox/freeleaps + git status -s + + echo + echo "[INIT] \$(date '+%Y-%m-%d %H:%M:%S') Git status check completed." + echo + + + echo "[INIT] \$(date '+%Y-%m-%d %H:%M:%S') Backend and frontend environment initialization completed." fi EOF @@ -876,7 +885,7 @@ docker exec -i "$DEVBOX_NAME" bash < "\$baseline_frontend" + echo "[FRONTEND] \$(date '+%Y-%m-%d %H:%M:%S') Recorded baseline before compilation: \$baseline_frontend" # Check if the frontend service is already running according to the package.json and pnpm-lock.yaml files timestamps @@ -1163,12 +1179,18 @@ docker exec -i "$DEVBOX_NAME" bash < /home/devbox/logs/frontend.logs 2>&1 & + # Check git status + echo + echo "[FRONTEND] \$(date '+%Y-%m-%d %H:%M:%S') Checking git status..." + echo + git status -s + echo + echo "[FRONTEND] \$(date '+%Y-%m-%d %H:%M:%S') Git status check completed." + echo + # Check the health of the frontend service: poll to detect HTTP status MAX_ATTEMPTS=30 ATTEMPT=0 @@ -1244,18 +1296,7 @@ docker exec -i "$DEVBOX_NAME" bash < /dev/null + if [ \$ATTEMPT -eq \$MAX_ATTEMPTS ]; then + echo + echo "============================================================================================" + echo + echo "[FRONTEND] [ERROR] Frontend service startup failed. Please check the logs for more information. Logs: ${WORKING_HOME}/logs/frontend.logs" + echo + echo "============================================================================================" + echo + exit 1 + fi + echo echo "[FRONTEND] \$(date '+%Y-%m-%d %H:%M:%S') Frontend compilation and startup completed." echo EOF } +reset_freeleaps_repo() { + echo "[INIT] $(date '+%Y-%m-%d %H:%M:%S') Resetting FreeLeaps repository..." + devbox_container_id_file_path="${WORKING_HOME}/.devbox-instance" + DEVBOX_NAME=$(cat "$devbox_container_id_file_path") + + docker exec -i "$DEVBOX_NAME" bash < /dev/null + git config --global --add safe.directory /home/devbox/freeleaps + git reset --hard HEAD + popd > /dev/null + echo "[INIT] \$(date '+%Y-%m-%d %H:%M:%S') FreeLeaps repository reset completed." +EOF +} + # :command.command_functions # :command.function devbox_init_command() { - log_info " [INIT] Starting DevBox environment initialization..." + log_info "[INIT] Starting DevBox environment initialization..." echo # ------------------------------------------------------------------- @@ -1386,8 +1453,8 @@ devbox_init_command() { # If is_pull_all_components is true, then pull all components if [[ "$is_pull_all_components" == true ]]; then start_components=("${components[@]}") - log_info "==> Pulling all components..." - log_info "==> start components: ${start_components[@]}" + log_info "Pulling all components..." + log_info "start components: ${start_components[@]}" fi # Remove duplicated components @@ -1395,21 +1462,21 @@ devbox_init_command() { echo "===================================================== " log_info "Parameters:" - log_info " OS = $OS" - log_info " ARCH = $ARCH" - log_info " DEVBOX_NAME = $DEVBOX_NAME" - log_info " DEVBOX_PORT = $DEVBOX_PORT" - log_info " DEVBOX_FRONTEND_PORT = $DEVBOX_FRONTEND_PORT" - log_info " DEVBOX_BACKEND_PORT = $DEVBOX_BACKEND_PORT" - log_info " DEVBOX_REPO = $DEVBOX_REPO" - log_info " DEVBOX_IMAGE = $DEVBOX_IMAGE" - log_info " DEVBOX_TAG = $DEVBOX_TAG" - log_info " WORKING_HOME = $WORKING_HOME" - log_info " FREELEAPS_USERNAME= $FREELEAPS_USERNAME" - log_info " (FREELEAPS_PASSWORD is hidden for security)" - log_info " USE_LOCAL_COMPONENT= $USE_LOCAL_COMPONENT" - log_info " FREELEAPS_COMPONENTS= ${start_components[@]}" - log_info " FORCE_INIT = $FORCE_INIT" + log_info " OS = $OS" + log_info " ARCH = $ARCH" + log_info " DEVBOX_NAME = $DEVBOX_NAME" + log_info " DEVBOX_PORT = $DEVBOX_PORT" + log_info " DEVBOX_FRONTEND_PORT = $DEVBOX_FRONTEND_PORT" + log_info " DEVBOX_BACKEND_PORT = $DEVBOX_BACKEND_PORT" + log_info " DEVBOX_REPO = $DEVBOX_REPO" + log_info " DEVBOX_IMAGE = $DEVBOX_IMAGE" + log_info " DEVBOX_TAG = $DEVBOX_TAG" + log_info " WORKING_HOME = $WORKING_HOME" + log_info " FREELEAPS_USERNAME= $FREELEAPS_USERNAME" + log_info " (FREELEAPS_PASSWORD is hidden for security)" + log_info " USE_LOCAL_COMPONENT= $USE_LOCAL_COMPONENT" + log_info " FREELEAPS_COMPONENTS= ${start_components[@]}" + log_info " FORCE_INIT = $FORCE_INIT" echo # ------------------------------------------------------------------- @@ -1422,9 +1489,9 @@ devbox_init_command() { # Auto detected $OS if [[ "$OS" == "auto" ]]; then - log_info "==> Auto detecting OS..." + log_info "Auto detecting OS..." OS="$(detect_os)" - log_info "==> Detected OS: $OS" + log_info "Detected OS: $OS" fi if [[ "$ARCH" != "auto" && "$ARCH" != "amd64" && "$ARCH" != "arm64" ]]; then @@ -1440,7 +1507,7 @@ devbox_init_command() { if grep -q avx2 /proc/cpuinfo; then ARCH="amd64" ARCH_MICRO="v3" - log_info "==> Detected AMD64 architecture." + log_info "Detected AMD64 architecture." else ARCH="amd64" fi @@ -1540,7 +1607,7 @@ devbox_init_command() { # Check if Installed the net-tools netstat under MacOS, WSL2 and Linux OS if [[ "$OS" == "darwin" || "$OS" == "wsl2" || "$OS" == "linux" ]]; then if ! command -v netstat &>/dev/null; then - log_info "==> Installing net-tools package..." + log_info "Installing net-tools package..." if [[ "$OS" == "darwin" ]]; then brew install net-tools elif [[ "$OS" == "wsl2" ]]; then @@ -1553,11 +1620,11 @@ devbox_init_command() { exit_with_message " Failed install net-tools package on OS: $OS, please install it manually." 1 fi else - log_info "==> net-tools package already installed." + log_info "net-tools package already installed." fi fi - log_info "==> Checking if the ports are in use..." + log_info "Checking if the ports are in use..." # Check if the gittea, mongodb, rabbitmq, redis ports are in use if netstat -tuln | grep -q ":3000"; then exit_with_message " gitea port 3000 is already in use, please stop the service." 1 @@ -1579,16 +1646,16 @@ devbox_init_command() { exit_with_message " redis port 6379 is already in use, please stop the service." 1 fi - log_info "==> Checking if the ports are in use... Done." + log_info "Checking if the ports are in use... Done." local devbox_full_image="${DEVBOX_REPO}/${DEVBOX_IMAGE}:${DEVBOX_TAG}" # Check local and remote version. User doesn’t need to rebuild devbox if local version is consistent with remote version if [[ -n "$DEVBOX_REPO" && -n "$DEVBOX_IMAGE" && -n "$DEVBOX_TAG" ]]; then if docker images --format '{{.Repository}}:{{.Tag}}' | grep -q "^${DEVBOX_REPO}/${DEVBOX_IMAGE}:${DEVBOX_TAG}\$"; then - log_info "==> DevBox image $devbox_full_image already exists." + log_info "DevBox image $devbox_full_image already exists." else - log_info "==> Pulling DevBox image $devbox_full_image..." + log_info "Pulling DevBox image $devbox_full_image..." docker pull "$devbox_full_image" fi else @@ -1598,7 +1665,7 @@ devbox_init_command() { # If container with same name exists, remove it if docker ps -a --format '{{.Names}}' | grep -q "^${DEVBOX_NAME}\$"; then if [[ -n "$FORCE_INIT" ]]; then - log_info "==> Removing existing container named $DEVBOX_NAME ..." + log_info "Removing existing container named $DEVBOX_NAME ..." docker stop "$DEVBOX_NAME" &>/dev/null || true docker rm "$DEVBOX_NAME" &>/dev/null || true @@ -1619,15 +1686,15 @@ devbox_init_command() { log_info ' Starting DevBox environment initialization...' # Check if docker network create devbox_freeleaps2-network if ! docker network ls | grep -q "$DEVBOX_FREELEAPS2_NETWORK"; then - log_info "==> Creating Docker network: $DEVBOX_FREELEAPS2_NETWORK" + log_info "Creating Docker network: $DEVBOX_FREELEAPS2_NETWORK" docker network create "$DEVBOX_FREELEAPS2_NETWORK" else - log_info "==> Docker network devbox_freeleaps2-network already exists." + log_info "Docker network devbox_freeleaps2-network already exists." fi # Check if use custom repository if [[ -n "$USE_CUSTOM_REPOSITORY" ]]; then - log_info " [INIT] Using custom repository." + log_info "[INIT] Using custom repository." elif [[ -z "$FREELEAPS_USERNAME" || -z "$FREELEAPS_PASSWORD" ]]; then exit_with_message " Username or password is missing. Please provide a valid username and password for freeleaps.com repository." 1 fi @@ -1666,7 +1733,7 @@ devbox_init_command() { ENCODEING_FREELEAPS_USERNAME=$(url_encode "$FREELEAPS_USERNAME") ENCODEING_FREELEAPS_PASSWORD=$(url_encode "$FREELEAPS_PASSWORD") # Test if the user can access the freeleaps.com repository - log_info "==> Testing access to freeleaps.com repository..." + log_info "Testing access to freeleaps.com repository..." if ! git ls-remote "https://$ENCODEING_FREELEAPS_USERNAME:$ENCODEING_FREELEAPS_PASSWORD@freeleaps.com:3443/products/freeleaps.git" &>/dev/null; then exit_with_message " Failed to access freeleaps.com repository. Please check your username and password." 1 fi @@ -1708,7 +1775,7 @@ devbox_init_command() { # Check if the custom repository is a git repository # Test if the user can access the custom repository - log_info "==> Testing access to custom repository..." + log_info "Testing access to custom repository..." if ! git ls-remote "$USE_CUSTOM_REPOSITORY" &>/dev/null; then exit_with_message " Failed to access custom repository. Please check the repository URL." 1 fi @@ -1751,7 +1818,7 @@ devbox_init_command() { # 6. linbwang: pull and start other components # ------------------------------------------------------------------- -log_info "==> [INIT] Starting Freeleaps services... Use Local component $USE_LOCAL_COMPONENT_VAL" +log_info "[INIT] Starting Freeleaps services... Use Local component $USE_LOCAL_COMPONENT_VAL" export ARCH="$ARCH" export WORKING_HOME="$WORKING_HOME" @@ -1768,10 +1835,10 @@ if [[ -n "$USE_CUSTOM_REPOSITORY" ]]; then echo echo "===========================================================" echo - log_info "==> [INIT] Custom repository initialization completed." - log_info "==> Custom repository is located at: ${WORKING_HOME}/${CUSTOM_FOLDER_NAME}" - log_info "==> Custom repository URL: $ECHO_USE_CUSTOM_REPOSITORY" - log_info "==> Custom repository is ready for use." + log_info "[INIT] Custom repository initialization completed." + log_info "Custom repository is located at: ${WORKING_HOME}/${CUSTOM_FOLDER_NAME}" + log_info "Custom repository URL: $ECHO_USE_CUSTOM_REPOSITORY" + log_info "Custom repository is ready for use." echo echo "===========================================================" echo @@ -1780,7 +1847,7 @@ if [[ -n "$USE_CUSTOM_REPOSITORY" ]]; then fi # Check if docker-compose command exists -log_info "==> Cehck if docker-compose command exists" +log_info "Cehck if docker-compose command exists" # Check if docker-compose is installed local DC_CMD if command -v docker-compose >/dev/null 2>&1; then @@ -1790,7 +1857,7 @@ elif docker compose version >/dev/null 2>&1; then DC_CMD="docker compose" else DC_CMD="" - log_error " docker-compose is not installed." + log_error "docker-compose is not installed." fi if [[ "$DC_CMD" == "" ]]; then exit_with_message "Please install docker-compose or docker compose (v2) and try again." 1 @@ -1798,7 +1865,7 @@ fi # If USE_LOCAL_COMPONENT is true, then use local components if [[ $USE_LOCAL_COMPONENT_VAL == true ]]; then - log_info ' ===> Using local components for Freeleaps services.' + log_info ' = Using local components for Freeleaps services.' export DEVSVC_IMAGE_TAG="$component_tag" export CONTENT_IMAGE_TAG="$component_tag" @@ -1856,7 +1923,7 @@ if [[ $USE_LOCAL_COMPONENT_VAL == true ]]; then done # Start Gitea, MongoDB, RabbitMQ and other components containers - log_info "===> start Gitea, MongoDB, RabbitMQ and other components containers" + log_info "start Gitea, MongoDB, RabbitMQ and other components containers" $DC_CMD -f docker-compose.yaml up -d mongodb rabbitmq gitea redis "${start_components[@]}" gitea_container_id=$(docker ps --no-trunc -a --filter "name=^freeleaps2-gitea$" --format "{{.ID}}") @@ -1887,9 +1954,9 @@ if [[ $USE_LOCAL_COMPONENT_VAL == true ]]; then fi done else - echo '============================================' - log_info ' ===> Using online components for Freeleaps services.' - echo '============================================' + echo '============================================================' + log_info 'Using online components for Freeleaps services.' + echo '============================================================' # Start Gitea, MongoDB, RabbitMQ containers $DC_CMD -f docker-compose.yaml up -d mongodb rabbitmq redis @@ -1928,8 +1995,8 @@ if [[ "$user_input" == "N" || "$user_input" == "n" ]]; then echo "===========================================================" log_info "DevBox init completed successfully!" log_info "DevBox Environment Details:" - log_info " DevBox container name: $DEVBOX_NAME" - log_info " DevBox container ID: $WORKING_HOME/.devbox-instance" + log_info "DevBox container name: $DEVBOX_NAME" + log_info "DevBox container ID: $WORKING_HOME/.devbox-instance" echo "===========================================================" echo exit 0 @@ -1942,28 +2009,23 @@ IS_START_FRONTEND=true compile_backend_service compile_frontend_service -docker exec -i "$DEVBOX_NAME" bash < Deinitialization parameters:" - log_info " WORKING_HOME = $WORKING_HOME" - log_info " CLEAR_LOGS = $CLEAR_LOGS" - log_info " CLEAR_REPO = $CLEAR_REPO" - log_info " CLEAR_ALL = $CLEAR_ALL" + log_info "Deinitialization parameters:" + log_info " WORKING_HOME = $WORKING_HOME" + log_info " CLEAR_LOGS = $CLEAR_LOGS" + log_info " CLEAR_REPO = $CLEAR_REPO" + log_info " CLEAR_ALL = $CLEAR_ALL" - log_info "==> Starting DevBox deinitialization..." + log_info "Starting DevBox deinitialization..." # Stop and remove DevBox container if [[ -f "$WORKING_HOME/.devbox-instance" ]]; then local container_id container_id=$(cat "$WORKING_HOME/.devbox-instance") - log_info "==> Stopping and removing DevBox container: $container_id" + log_info "Stopping and removing DevBox container: $container_id" docker stop "$container_id" &>/dev/null || true docker rm "$container_id" &>/dev/null || true @@ -2006,14 +2068,14 @@ devbox_deinit_command() { rm -f "$WORKING_HOME/.backend.pid" rm -f "$WORKING_HOME/.frontend.pid" else - echo "==> DevBox container is not running." + log_info "DevBox container is not running." if [[ -n "$(docker ps -a --format '{{.Names}}' | grep "^devbox\$")" ]]; then # Get the container ID of the DevBox container - echo "==> DevBox container is stopped." + log_info "DevBox container is stopped." local container_id container_id=$(docker ps -a --format '{{.Names}}' | grep "^devbox\$") - log_info "==> Stopping and removing DevBox container: $container_id" + log_info "Stopping and removing DevBox container: $container_id" docker stop "$container_id" &>/dev/null || true docker rm "$container_id" &>/dev/null || true fi @@ -2022,13 +2084,13 @@ devbox_deinit_command() { if [[ -f "$WORKING_HOME/.gitea-instance" ]]; then local gitea_container_id gitea_container_id=$(cat "$WORKING_HOME/.gitea-instance") - log_info "==> Stopping and removing Gitea container: $gitea_container_id" + log_info "Stopping and removing Gitea container: $gitea_container_id" docker stop "$gitea_container_id" &>/dev/null || true docker rm "$gitea_container_id" &>/dev/null || true # Check if the Gitea container is still running, then use docker compose down to stop and remove the container if [[ -n "$(docker ps -a --format '{{.Names}}' | grep "^freeleaps2-gitea\$")" ]]; then - log_info "==> Using docker-compose down to stop and remove Gitea container." + log_info "Using docker-compose down to stop and remove Gitea container." $DC_CMD -f docker-compose.yaml down gitea fi @@ -2039,13 +2101,13 @@ devbox_deinit_command() { if [[ -f "$WORKING_HOME/.mongodb-instance" ]]; then local mongodb_container_id mongodb_container_id=$(cat "$WORKING_HOME/.mongodb-instance") - log_info "==> Stopping and removing MongoDB container: $mongodb_container_id" + log_info "Stopping and removing MongoDB container: $mongodb_container_id" docker stop "$mongodb_container_id" &>/dev/null || true docker rm "$mongodb_container_id" &>/dev/null || true # Check if the MongoDB container is still running, then use docker compose down to stop and remove the container if [[ -n "$(docker ps -a --format '{{.Names}}' | grep "^freeleaps2-mongodb\$")" ]]; then - log_info "==> Using docker-compose down to stop and remove MongoDB container." + log_info "Using docker-compose down to stop and remove MongoDB container." $DC_CMD -f docker-compose.yaml down mongodb fi @@ -2055,13 +2117,13 @@ devbox_deinit_command() { if [[ -f "$WORKING_HOME/.redis-instance" ]]; then local redis_container_id redis_container_id=$(cat "$WORKING_HOME/.redis-instance") - log_info "==> Stopping and removing Redis container: $redis_container_id" + log_info "Stopping and removing Redis container: $redis_container_id" docker stop "$redis_container_id" &>/dev/null || true docker rm "$redis_container_id" &>/dev/null || true # Check if the Redis container is still running, then use docker compose down to stop and remove the container if [[ -n "$(docker ps -a --format '{{.Names}}' | grep "^freeleaps2-redis\$")" ]]; then - log_info "==> Using docker-compose down to stop and remove Redis container." + log_info "Using docker-compose down to stop and remove Redis container." $DC_CMD -f docker-compose.yaml down redis fi @@ -2072,13 +2134,13 @@ devbox_deinit_command() { if [[ -f "$WORKING_HOME/.rabbitmq-instance" ]]; then local rabbitmq_container_id rabbitmq_container_id=$(cat "$WORKING_HOME/.rabbitmq-instance") - log_info "==> Stopping and removing RabbitMQ container: $rabbitmq_container_id" + log_info "Stopping and removing RabbitMQ container: $rabbitmq_container_id" docker stop "$rabbitmq_container_id" &>/dev/null || true docker rm "$rabbitmq_container_id" &>/dev/null || true # Check if the RabbitMQ container is still running, then use docker compose down to stop and remove the container if [[ -n "$(docker ps -a --format '{{.Names}}' | grep "^freeleaps2-rabbitmq\$")" ]]; then - log_info "==> Using docker-compose down to stop and remove RabbitMQ container." + log_info "Using docker-compose down to stop and remove RabbitMQ container." $DC_CMD -f docker-compose.yaml down rabbitmq fi @@ -2091,13 +2153,13 @@ devbox_deinit_command() { if [[ -f "$WORKING_HOME/.${component}-instance" ]]; then local component_container_id component_container_id=$(cat "$WORKING_HOME/.${component}-instance") - log_info "==> Stopping and removing ${component} container: $component_container_id" + log_info "Stopping and removing ${component} container: $component_container_id" docker stop "$component_container_id" &>/dev/null || true docker rm "$component_container_id" &>/dev/null || true # Check if the component is still running, then use docker compose down to stop and remove the container if [[ -n "$(docker ps -a --format '{{.Names}}' | grep "^$component\$")" ]]; then - log_info "==> Using docker-compose down to stop and remove $component container." + log_info "Using docker-compose down to stop and remove $component container." $DC_CMD -f docker-compose.yaml down "$component" fi @@ -2108,7 +2170,7 @@ devbox_deinit_command() { # Clear the DevBox container logs if [[ "$CLEAR_LOGS" == "true" ]]; then - log_info "==> Clearing logs in $WORKING_HOME/logs..." + log_info "Clearing logs in $WORKING_HOME/logs..." if [[ -d "$WORKING_HOME/logs" ]]; then uid=$(id -u) gid=$(id -g) @@ -2117,19 +2179,19 @@ devbox_deinit_command() { mkdir -p "$WORKING_HOME/logs" 2>/dev/null || true fi else - log_info "==> Skipping log clearing." + log_info "Skipping log clearing." fi # Clear the source repository if [[ "$CLEAR_REPO" == "true" && -d "$WORKING_HOME/freeleaps" ]]; then - log_info "==> Deleting source repository at $WORKING_HOME/freeleaps" + log_info "Deleting source repository at $WORKING_HOME/freeleaps" uid=$(id -u) gid=$(id -g) sudo chown -R ${uid}:${gid} "$WORKING_HOME/freeleaps" rm -rf "$WORKING_HOME/freeleaps" 2>/dev/null || true rmdir "$WORKING_HOME/freeleaps" 2>/dev/null || true else - log_info "==> Skipping repository deletion." + log_info "Skipping repository deletion." fi if [[ "$CLEAR_LOGS" == "true" ]]; then @@ -2138,7 +2200,7 @@ devbox_deinit_command() { log_warn " $WORKING_HOME/logs still exists after removal." rm -rf "$WORKING_HOME/logs" else - log_info "==> Logs directory removed successfully." + log_info "Logs directory removed successfully." fi fi @@ -2151,7 +2213,7 @@ devbox_deinit_command() { REMOVE_WORKING_HOME=true # Remove the working home directory - log_info "==> Removing working home directory: $WORKING_HOME" + log_info "Removing working home directory: $WORKING_HOME" if [[ -d "$WORKING_HOME" ]]; then uid=$(id -u) gid=$(id -g) @@ -2159,25 +2221,26 @@ devbox_deinit_command() { rm -rf "$WORKING_HOME" 2>/dev/null || true rmdir "$WORKING_HOME" 2>/dev/null || true fi - log_info "==> Working home directory removed successfully." + log_info "Working home directory removed successfully." else REMOVE_WORKING_HOME=false - log_info "==> Skipping working home directory removal." + log_info "Skipping working home directory removal." fi fi # Sleep 5 seconds to allow the services to stop, for each second echo 5 seconds increase from 1 to 5 in each second by - - for i in {1..5}; do - echo -n "=" - sleep 1 + echo -n "[INFO] $(date '+%Y-%m-%d %H:%M:%S') Stopping services" + for i in {1..10}; do + echo -n "." + sleep 0.5 done - + echo # Remove the use-local-component file rm -f "$WORKING_HOME/.use-local-component" - log_info "==> DevBox deinitialization completed." + exit_with_message "DevBox deinitialization completed." 0 } # :command.function @@ -2217,10 +2280,10 @@ devbox_start_command() { fi if [[ "$(lower "$USE_LOCAL_COMPONENT")" == "true" ]]; then - log_info "==> Using local components for Freeleaps services." + log_info "Using local components for Freeleaps services." USE_LOCAL_COMPONENT="true" else - log_info "==> Using online components for Freeleaps services." + log_info "Using online components for Freeleaps services." USE_LOCAL_COMPONENT="false" fi @@ -2237,7 +2300,7 @@ devbox_start_command() { COMPONENTS=("mongodb" "rabbitmq" "devbox") else if [[ "$COMPONENT" == "devsvc" || "$COMPONENT" == "notification" || "$COMPONENT" == "content" || "$COMPONENT" == "central_storage" || "$COMPONENT" == "chat" || "$COMPONENT" == "authentication" ]]; then - exit_with_message "ERROR: Remote component $COMPONENT cannot be restarted, please use local components." 1 + exit_with_message "Remote component $COMPONENT cannot be restarted, please use local components." 1 fi COMPONENTS=("$COMPONENT") @@ -2248,23 +2311,23 @@ devbox_start_command() { for comp in "${COMPONENTS[@]}"; do case "$comp" in "gitea" | "mongodb" | "rabbitmq" | "devbox" | "devsvc" | "notification" | "content" | "central_storage" | "chat" | "authentication") - log_info "==> Starting $comp service..." + log_info "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 - log_error " $comp container is not running. Please run 'devbox init' first." + log_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 - log_info "==> $comp container is not running, starting container..." + log_info "$comp container is not running, starting container..." # Start the container if ! docker start "${component_container_id}"; then - log_error " Failed to start $comp container." + log_error "Failed to start $comp container." else - log_info "==> $comp container started successfully." + log_info "$comp container started successfully." fi else - log_info "==> $comp container is already running." + log_info "$comp container is already running." fi fi ;; @@ -2287,7 +2350,7 @@ devbox_start_command() { done if docker ps --no-trunc --format '{{.ID}}' | grep -q "^${devbox_container_id}\$"; then - log_info "==> Starting Freeleaps frontend and backend services..." + log_info "Starting Freeleaps frontend and backend services..." # Check if start backend service if [[ "${START_BACKEND}" == "true" ]]; then compile_backend_service @@ -2302,7 +2365,7 @@ devbox_start_command() { fi fi - success_message="==> Freeleaps services started successfully. " + success_message=" Freeleaps services started successfully. " frontend_port=$(cat "${WORKING_HOME}/.devbox-frontend-port") if [[ "${START_FRONTEND}" == "true" && "${START_BACKEND}" == "true" ]]; then @@ -2352,7 +2415,7 @@ devbox_stop_command() { if [[ -f "${WORKING_HOME}/.backend.pid" ]]; then stop_backend_service else - log_info "==> Backend service is not running." + log_info "Backend service is not running." fi fi @@ -2361,7 +2424,7 @@ devbox_stop_command() { if [[ -f "${WORKING_HOME}/.frontend.pid" ]]; then stop_frontend_service else - log_info "==> Frontend service is not running." + log_info "Frontend service is not running." fi fi fi @@ -2407,16 +2470,16 @@ devbox_stop_command() { local container_id container_id=$(cat "${WORKING_HOME}/.devbox-instance") if docker ps --no-trunc --format '{{.ID}}' | grep -q "^${container_id}\$"; then - log_info "==> Stopping devbox..." + log_info "Stopping devbox..." docker stop "$container_id" &>/dev/null || true # Remove the frontend and backend pid files rm -f "${WORKING_HOME}/.backend.pid" rm -f "${WORKING_HOME}/.frontend.pid" else - log_info "==> DevBox container is not running." + log_info "DevBox container is not running." fi else - log_info "==> Backend service is not running." + log_info "Backend service is not running." fi ;; @@ -2425,13 +2488,13 @@ devbox_stop_command() { local container_id container_id=$(cat "${WORKING_HOME}/.${comp}-instance") if docker ps --no-trunc --format '{{.ID}}' | grep -q "^${container_id}\$"; then - log_info "==> Stopping $comp service..." + log_info "Stopping $comp service..." docker stop "$container_id" &>/dev/null || true else - log_info "==> $comp service is not running." + log_info "$comp service is not running." fi else - log_info "==> $comp service is not running." + log_info "$comp service is not running." fi ;; *) @@ -2440,14 +2503,14 @@ devbox_stop_command() { esac done - exit_with_message "[INFO] Stopped Freeleaps services successfully. " 0 + exit_with_message "Stopped Freeleaps services successfully. " 0 } # :command.function devbox_status_command() { - log_info "==> Checking DevBox services status..." + log_info "Checking DevBox services status..." local COMPONENT="$(get_arg '--component')" local WORKING_HOME="$(get_arg '--working-home' "${HOME}/devbox")" @@ -2474,7 +2537,7 @@ devbox_status_command() { for comp in "${COMPONENTS[@]}"; do case "$comp" in "mongodb") - log_info "==> Checking MongoDB status..." + log_info "Checking MongoDB status..." if [[ -f "${WORKING_HOME}/.mongodb-instance" ]]; then local container_id container_id=$(cat "${WORKING_HOME}/.mongodb-instance") @@ -2489,7 +2552,7 @@ devbox_status_command() { ;; "rabbitmq") - log_info "==> Checking RabbitMQ status..." + log_info "Checking RabbitMQ status..." if [[ -f "${WORKING_HOME}/.rabbitmq-instance" ]]; then local container_id container_id=$(cat "${WORKING_HOME}/.rabbitmq-instance") @@ -2504,7 +2567,7 @@ devbox_status_command() { ;; "devbox") - log_info "==> Checking devbox service status..." + log_info "Checking devbox service status..." if [[ -f "${WORKING_HOME}/.devbox-instance" ]]; then local container_id container_id=$(cat "${WORKING_HOME}/.devbox-instance") @@ -2519,7 +2582,7 @@ devbox_status_command() { ;; "devsvc" | "notification" | "content" | "central_storage" | "chat" | "authentication") - log_info "==> Checking $comp service status..." + log_info "Checking $comp service status..." if [[ -f "${WORKING_HOME}/.${comp}-instance" ]]; then local container_id container_id=$(cat "${WORKING_HOME}/.${comp}-instance") @@ -2538,12 +2601,12 @@ devbox_status_command() { ;; esac done - exit_with_message "==> DevBox services status checked successfully." 0 + exit_with_message " DevBox services status checked successfully." 0 } # :command.function devbox_restart_command() { - log_info "==> Restarting DevBox services..." + log_info "Restarting DevBox services..." local COMPONENT="$(get_arg '--component')" local WORKING_HOME="$(get_arg '--working-home' "${HOME}/devbox")" local FREELEAPS_ENDPOINT="$(get_arg '--freeleaps-endpoint')" @@ -2574,7 +2637,7 @@ devbox_restart_command() { devbox_container_id=$(cat "${WORKING_HOME}/.devbox-instance") log_info "docker ps --no-trunc --format ${devbox_container_id} " if docker ps --no-trunc --format '{{.ID}}' | grep -q "${devbox_container_id}\$"; then - log_info "==> Starting Freeleaps frontend and backend services..." + log_info "Starting Freeleaps frontend and backend services..." # Check if start backend service if [[ "${START_BACKEND}" == "true" ]]; then stop_backend_service @@ -2609,14 +2672,14 @@ devbox_restart_command() { # Check if current environment is using local components USE_LOCAL_COMPONENT=$(cat "${WORKING_HOME}/.use-local-component" 2>/dev/null || true) if [[ "$USE_LOCAL_COMPONENT" == "true" ]]; then - log_info "==> Using local components..." + log_info "Using local components..." if [[ -z "$COMPONENT" ]]; then COMPONENTS=("gitea" "mongodb" "rabbitmq" "devbox" "devsvc" "notification" "content" "central_storage" "chat" "authentication") else COMPONENTS=("$COMPONENT") fi else - log_info "==> Using remote components..." + log_info "Using remote components..." if [[ -z "$COMPONENT" ]]; then COMPONENTS=("mongodb" "rabbitmq" "devbox") else @@ -2635,14 +2698,14 @@ devbox_restart_command() { if [[ -f "${WORKING_HOME}/.devbox-instance" ]]; then local container_id container_id=$(cat "${WORKING_HOME}/.devbox-instance") - log_info "==> Stopping devbox service..." + log_info "Stopping devbox service..." docker stop "$container_id" &>/dev/null || true # Remove the frontend and backend pid files rm -f "${WORKING_HOME}/.backend.pid" rm -f "${WORKING_HOME}/.frontend.pid" else - log_info "==> Devbox is not running." + log_info "Devbox is not running." fi ;; @@ -2651,10 +2714,10 @@ devbox_restart_command() { if [[ -f "${WORKING_HOME}/.${comp}-instance" ]]; then local container_id container_id=$(cat "${WORKING_HOME}/.${comp}-instance") - log_info "==> Stopping $comp service..." + log_info "Stopping $comp service..." docker stop "$container_id" &>/dev/null || true else - log_info "==> $comp service is not running." + log_info "$comp service is not running." fi ;; *) @@ -2667,13 +2730,13 @@ devbox_restart_command() { for comp in "${COMPONENTS[@]}"; do case "$comp" in "gitea" | "mongodb" | "rabbitmq" | "devbox" | "devsvc" | "notification" | "content" | "central_storage" | "chat" | "authentication") - log_info "==> Restarting $comp service..." + log_info "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 - log_info "==> $comp service is not running." + log_info "$comp service is not running." fi ;; *) @@ -2682,7 +2745,7 @@ devbox_restart_command() { esac done - exit_with_message "==> DevBox services restarted successfully." 0 + exit_with_message " DevBox services restarted successfully." 0 } # :command.parse_requirements