Update for component update easier

This commit is contained in:
timqiu 2025-04-07 11:56:11 +08:00
parent 12b1bddf02
commit 1e4aef9dda

View File

@ -1,6 +1,9 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Modifying it manually is not recommended # Modifying it manually is not recommended
# All components that can be started in the DevBox container. [COMPONENT_SETTINGS]
DEVBOX_COMPONENTS=("devsvc" "notification" "content" "central_storage" "chat" "authentication")
log_info() { log_info() {
echo "[INFO] $(date '+%Y-%m-%d %H:%M:%S') $*" echo "[INFO] $(date '+%Y-%m-%d %H:%M:%S') $*"
} }
@ -612,28 +615,12 @@ build_local_image() {
fi fi
} }
# Define the local components and their corresponding ports
local_components_ports_keys=("devsvc" "notification" "content" "central_storage" "chat" "authentication")
local_components_ports_values=("8007" "8003" "8013" "8005" "8012" "8004")
# used for repository username and password encoding # used for repository username and password encoding
url_encode() { url_encode() {
echo "$1" | sed 's/@/%40/g' echo "$1" | sed 's/@/%40/g'
} }
# Get the port number for a local component
get_port() {
local comp="$1"
local port=""
for i in "${!local_components_ports_keys[@]}"; do
if [ "${local_components_ports_keys[i]}" = "$comp" ]; then
port="${local_components_ports_values[i]}"
break
fi
done
}
############################################### ###############################################
@ -641,6 +628,7 @@ get_port() {
############################################### ###############################################
init_compile_env() { init_compile_env() {
# Update for export environments []
docker exec -i "$DEVBOX_NAME" bash <<EOF docker exec -i "$DEVBOX_NAME" bash <<EOF
echo "[INIT] \$(date '+%Y-%m-%d %H:%M:%S') Starting DevBox initialization..." echo "[INIT] \$(date '+%Y-%m-%d %H:%M:%S') Starting DevBox initialization..."
@ -689,8 +677,6 @@ EOFinner
echo "[INIT] \$(date '+%Y-%m-%d %H:%M:%S') Update VITE_PROXY_WEBSOCKET_CHAT_URL and VITE_PROXY_API_CHAT_URL in frontend/.env.development" echo "[INIT] \$(date '+%Y-%m-%d %H:%M:%S') Update VITE_PROXY_WEBSOCKET_CHAT_URL and VITE_PROXY_API_CHAT_URL in frontend/.env.development"
sed -i "s|VITE_PROXY_WEBSOCKET_CHAT_URL=.*|VITE_PROXY_WEBSOCKET_CHAT_URL=ws://chat:8012|g" /home/devbox/freeleaps/frontend/freeleaps/.env.development sed -i "s|VITE_PROXY_WEBSOCKET_CHAT_URL=.*|VITE_PROXY_WEBSOCKET_CHAT_URL=ws://chat:8012|g" /home/devbox/freeleaps/frontend/freeleaps/.env.development
sed -i "s|VITE_PROXY_API_CHAT_URL=.*|VITE_PROXY_API_CHAT_URL=http://chat:8012|g" /home/devbox/freeleaps/frontend/freeleaps/.env.development sed -i "s|VITE_PROXY_API_CHAT_URL=.*|VITE_PROXY_API_CHAT_URL=http://chat:8012|g" /home/devbox/freeleaps/frontend/freeleaps/.env.development
git update-index --skip-worktree /home/devbox/freeleaps/frontend/freeleaps/.env.development
else else
# Online component environment variables # Online component environment variables
echo "[INIT] \$(date '+%Y-%m-%d %H:%M:%S') Use online component dev environment." echo "[INIT] \$(date '+%Y-%m-%d %H:%M:%S') Use online component dev environment."
@ -725,8 +711,6 @@ EOFinner
sed -i "s|VITE_PROXY_WEBSOCKET_CHAT_URL=.*|VITE_PROXY_WEBSOCKET_CHAT_URL=wss://freeleaps-alpha.com|g" /home/devbox/freeleaps/frontend/freeleaps/.env.development sed -i "s|VITE_PROXY_WEBSOCKET_CHAT_URL=.*|VITE_PROXY_WEBSOCKET_CHAT_URL=wss://freeleaps-alpha.com|g" /home/devbox/freeleaps/frontend/freeleaps/.env.development
sed -i "s|VITE_PROXY_API_CHAT_URL=.*|VITE_PROXY_API_CHAT_URL=https://freeleaps-alpha.com|g" /home/devbox/freeleaps/frontend/freeleaps/.env.development sed -i "s|VITE_PROXY_API_CHAT_URL=.*|VITE_PROXY_API_CHAT_URL=https://freeleaps-alpha.com|g" /home/devbox/freeleaps/frontend/freeleaps/.env.development
git update-index --skip-worktree /home/devbox/freeleaps/frontend/freeleaps/.env.development
echo "[INIT] \$(date '+%Y-%m-%d %H:%M:%S') Online component dev environment variables set." echo "[INIT] \$(date '+%Y-%m-%d %H:%M:%S') Online component dev environment variables set."
fi fi
@ -738,6 +722,8 @@ if true ; then
git update-index --skip-worktree /home/devbox/freeleaps/frontend/freeleaps/.env.development git update-index --skip-worktree /home/devbox/freeleaps/frontend/freeleaps/.env.development
popd > /dev/null
# Load the environment variables # Load the environment variables
source /home/devbox/freeleaps/apps/.env source /home/devbox/freeleaps/apps/.env
@ -1203,15 +1189,16 @@ docker exec -i "$DEVBOX_NAME" bash <<EOF
echo "[FRONTEND] \$(date '+%Y-%m-%d %H:%M:%S') Use local component dev environment." echo "[FRONTEND] \$(date '+%Y-%m-%d %H:%M:%S') Use local component dev environment."
sed -i 's#VITE_PROXY_WEBSOCKET_CHAT_URL=ws://localhost:8012#VITE_PROXY_WEBSOCKET_CHAT_URL=ws://chat:8012#g' /home/devbox/freeleaps/frontend/freeleaps/.env.development sed -i 's#VITE_PROXY_WEBSOCKET_CHAT_URL=ws://localhost:8012#VITE_PROXY_WEBSOCKET_CHAT_URL=ws://chat:8012#g' /home/devbox/freeleaps/frontend/freeleaps/.env.development
sed -i 's#VITE_PROXY_API_CHAT_URL=http://localhost:8012#VITE_PROXY_API_CHAT_URL=http://chat:8012#g' /home/devbox/freeleaps/frontend/freeleaps/.env.development sed -i 's#VITE_PROXY_API_CHAT_URL=http://localhost:8012#VITE_PROXY_API_CHAT_URL=http://chat:8012#g' /home/devbox/freeleaps/frontend/freeleaps/.env.development
git update-index --skip-worktree /home/devbox/freeleaps/frontend/freeleaps/.env.development
else else
echo "[FRONTEND] \$(date '+%Y-%m-%d %H:%M:%S') Use online component dev environment." echo "[FRONTEND] \$(date '+%Y-%m-%d %H:%M:%S') Use online component dev environment."
sed -i 's#VITE_PROXY_WEBSOCKET_CHAT_URL=wss://localhost:8012#VITE_PROXY_WEBSOCKET_CHAT_URL=wss://freeleaps-alpha.com#g' /home/devbox/freeleaps/frontend/freeleaps/.env.development sed -i 's#VITE_PROXY_WEBSOCKET_CHAT_URL=wss://localhost:8012#VITE_PROXY_WEBSOCKET_CHAT_URL=wss://freeleaps-alpha.com#g' /home/devbox/freeleaps/frontend/freeleaps/.env.development
sed -i 's#VITE_PROXY_API_CHAT_URL=http://localhost:8012#VITE_PROXY_API_CHAT_URL=https://freeleaps-alpha.com#g' /home/devbox/freeleaps/frontend/freeleaps/.env.development sed -i 's#VITE_PROXY_API_CHAT_URL=http://localhost:8012#VITE_PROXY_API_CHAT_URL=https://freeleaps-alpha.com#g' /home/devbox/freeleaps/frontend/freeleaps/.env.development
git update-index --skip-worktree /home/devbox/freeleaps/frontend/freeleaps/.env.development
fi fi
pushd /home/devbox/freeleaps > /dev/null
git update-index --skip-worktree /home/devbox/freeleaps/frontend/freeleaps/.env.development
popd > /dev/null
if [[ ! -d "node_modules" || "package.json" -nt "node_modules" || \$time_diff -gt \$threshold ]]; then if [[ ! -d "node_modules" || "package.json" -nt "node_modules" || \$time_diff -gt \$threshold ]]; then
echo "[FRONTEND] \$(date '+%Y-%m-%d %H:%M:%S') Installing/Updating frontend dependencies..." echo "[FRONTEND] \$(date '+%Y-%m-%d %H:%M:%S') Installing/Updating frontend dependencies..."
@ -1481,7 +1468,8 @@ devbox_init_command() {
local FORCE_INIT="$(get_arg '--force')" local FORCE_INIT="$(get_arg '--force')"
local is_pull_all_components=true local is_pull_all_components=true
local components=("devsvc" "notification" "content" "central_storage" "chat" "authentication") # set local components to content of DEVBOX_COMPONENTS
local components=("${DEVBOX_COMPONENTS[@]}")
local start_components=() local start_components=()
# Check if using local components # Check if using local components
@ -1656,7 +1644,10 @@ devbox_init_command() {
# Check if any component is running on the host when force init is not set # Check if any component is running on the host when force init is not set
if [ -z "$FORCE_INIT" ]; then if [ -z "$FORCE_INIT" ]; then
running_containers=$(docker ps --format '{{.Names}}') running_containers=$(docker ps --format '{{.Names}}')
components_to_check=("devbox" "freeleaps2-gitea" "freeleaps2-mongodb" "freeleaps2-rabbitmq" "freeleaps2-redis" "devsvc" "notification" "content" "central_storage" "chat" "authentication") # Check if any component is running on the host
components_to_check=("devbox" "freeleaps2-gitea" "freeleaps2-mongodb" "freeleaps2-rabbitmq" "freeleaps2-redis")
components_to_check+=("${DEVBOX_COMPONENTS[@]}")
for comp in "${components_to_check[@]}"; do for comp in "${components_to_check[@]}"; do
if echo "$running_containers" | grep -qx "$comp"; then if echo "$running_containers" | grep -qx "$comp"; then
echo echo
@ -2218,6 +2209,16 @@ devbox_deinit_command() {
fi fi
fi fi
# Check if devbox container is running
if [[ -n "$(docker ps -a --format '{{.Names}}' | grep "^devbox\$")" ]]; then
# Get the container ID of the DevBox container
log_info "DevBox container is stopped."
local container_id
container_id=$(docker ps -a --format '{{.Names}}' | grep "^devbox\$")
exit_with_message " Failed to stop and remove DevBox container when deinitializing. Please try deinit again or manually stop and remove the container." 1
fi
if [[ -f "$WORKING_HOME/.gitea-instance" ]]; then if [[ -f "$WORKING_HOME/.gitea-instance" ]]; then
local gitea_container_id local gitea_container_id
gitea_container_id=$(cat "$WORKING_HOME/.gitea-instance") gitea_container_id=$(cat "$WORKING_HOME/.gitea-instance")
@ -2324,7 +2325,7 @@ devbox_deinit_command() {
fi fi
# Stop and remove other components # Stop and remove other components
local components=("devsvc" "notification" "content" "central_storage" "chat" "authentication") local components=("${DEVBOX_COMPONENTS[@]}")
for component in "${components[@]}"; do for component in "${components[@]}"; do
if [[ -f "$WORKING_HOME/.${component}-instance" ]]; then if [[ -f "$WORKING_HOME/.${component}-instance" ]]; then
local component_container_id local component_container_id
@ -2475,16 +2476,26 @@ devbox_start_command() {
if [[ "$USE_LOCAL_COMPONENT" == "true" ]]; then if [[ "$USE_LOCAL_COMPONENT" == "true" ]]; then
# 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=( "gitea" "mongodb" "rabbitmq" "devbox" "devsvc" "notification" "content" "central_storage" "chat" "authentication") COMPONENTS=("mongodb" "rabbitmq" "gitea" "redis" "devbox")
COMPONENTS+=("${DEVBOX_COMPONENTS[@]}")
else else
COMPONENTS=("$COMPONENT") COMPONENTS=("$COMPONENT")
fi fi
else else
# 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" "devbox") COMPONENTS=("mongodb" "rabbitmq" "gitea" "redis" "devbox")
else else
if [[ "$COMPONENT" == "devsvc" || "$COMPONENT" == "notification" || "$COMPONENT" == "content" || "$COMPONENT" == "central_storage" || "$COMPONENT" == "chat" || "$COMPONENT" == "authentication" ]]; then # Check if the component is a local component from DEVBOX_COMPONENT
found=false
for item in "${DEVBOX_COMPONENTS[@]}"; do
if [ "$item" = "$COMPONENT" ]; then
found=true
break
fi
done
if [ "$found" = true ]; then
exit_with_message "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 fi
@ -2492,20 +2503,38 @@ devbox_start_command() {
fi fi
fi fi
# Start the specified components BASIC_COMPONENTS=("mongodb" "rabbitmq" "gitea" "redis" "devbox")
for comp in "${COMPONENTS[@]}"; do for comp in "${COMPONENTS[@]}"; do
case "$comp" in should_start=false
"gitea" | "mongodb" | "rabbitmq" | "devbox" | "devsvc" | "notification" | "content" | "central_storage" | "chat" | "authentication")
# Check if it's in BASIC_COMPONENTS
for basic in "${BASIC_COMPONENTS[@]}"; do
if [ "$comp" = "$basic" ]; then
should_start=true
break
fi
done
# Check if it's in DEVBOX_COMPONENTS
if [ "$should_start" = false ]; then
for dev in "${DEVBOX_COMPONENTS[@]}"; do
if [ "$comp" = "$dev" ]; then
should_start=true
break
fi
done
fi
if [ "$should_start" = true ]; then
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" local component_container_id_file_path="${WORKING_HOME}/.${comp}-instance"
if [[ ! -f "$component_container_id_file_path" ]]; then
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 else
local component_container_id=$(cat "$component_container_id_file_path") local component_container_id=$(cat "$component_container_id_file_path")
if ! docker ps --no-trunc --format '{{.ID}}' | grep -q "^${component_container_id}\$"; then 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 if ! docker start "${component_container_id}"; then
log_error "Failed to start $comp container." log_error "Failed to start $comp container."
else else
@ -2515,14 +2544,13 @@ devbox_start_command() {
log_info "$comp container is already running." log_info "$comp container is already running."
fi fi
fi fi
;; else
*)
exit_with_message " Unknown component: $comp, please check the component name." 1 exit_with_message " Unknown component: $comp, please check the component name." 1
;; fi
esac
done done
# Check if $FREELEAPS_ENDPOINT is not empty and start the frontend and backend services # Check if $FREELEAPS_ENDPOINT is not empty and start the frontend and backend services
if [[ "$FREELEAPS_ENDPOINT" != "" ]]; then if [[ "$FREELEAPS_ENDPOINT" != "" ]]; then
# Sleep for 10 seconds to allow the services to start and echo 10 seconds increase from 1 to 10 in each second # Sleep for 10 seconds to allow the services to start and echo 10 seconds increase from 1 to 10 in each second
@ -2642,22 +2670,23 @@ devbox_stop_command() {
# 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=("gitea" "mongodb" "rabbitmq" "devbox" "devsvc" "notification" "content" "central_storage" "chat" "authentication") COMPONENTS=("mongodb" "rabbitmq" "gitea" "redis" "devbox")
COMPONENTS+=("${DEVBOX_COMPONENTS[@]}")
else else
COMPONENTS=("$COMPONENT") COMPONENTS=("$COMPONENT")
fi fi
# Stop the specified components # Stop the specified components
BASIC_COMPONENTS=("mongodb" "rabbitmq" "gitea" "redis")
for comp in "${COMPONENTS[@]}"; do for comp in "${COMPONENTS[@]}"; do
case "$comp" in if [ "$comp" = "devbox" ]; then
"devbox") 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
log_info "Stopping devbox..." log_info "Stopping devbox..."
docker stop "$container_id" &>/dev/null || true docker stop "$container_id" &>/dev/null || true
# Remove the frontend and backend pid files
rm -f "${WORKING_HOME}/.backend.pid" rm -f "${WORKING_HOME}/.backend.pid"
rm -f "${WORKING_HOME}/.frontend.pid" rm -f "${WORKING_HOME}/.frontend.pid"
else else
@ -2666,10 +2695,29 @@ devbox_stop_command() {
else else
log_info "Backend service is not running." log_info "Backend service is not running."
fi fi
;; continue
fi
"gitea"| "mongodb"| "rabbitmq" | "devsvc" | "notification" | "content" | "central_storage" | "chat" | "authentication") should_stop=false
if [[ -f "${WORKING_HOME}/.${comp}-instance" ]]; then
for basic in "${BASIC_COMPONENTS[@]}"; do
if [ "$comp" = "$basic" ]; then
should_stop=true
break
fi
done
if [ "$should_stop" = false ]; then
for dev in "${DEVBOX_COMPONENTS[@]}"; do
if [ "$comp" = "$dev" ]; then
should_stop=true
break
fi
done
fi
if [ "$should_stop" = true ]; then
if [ -f "${WORKING_HOME}/.${comp}-instance" ]; then
local container_id local container_id
container_id=$(cat "${WORKING_HOME}/.${comp}-instance") container_id=$(cat "${WORKING_HOME}/.${comp}-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
@ -2681,13 +2729,12 @@ devbox_stop_command() {
else else
log_info "$comp service is not running." log_info "$comp service is not running."
fi fi
;; else
*)
exit_with_message " Unknown component: $comp, please check the component name." 1 exit_with_message " Unknown component: $comp, please check the component name." 1
;; fi
esac
done done
exit_with_message "Stopped Freeleaps services successfully. " 0 exit_with_message "Stopped Freeleaps services successfully. " 0
} }
@ -2713,62 +2760,24 @@ 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" "devbox" "devsvc" "notification" "content" "central_storage" "chat" "authentication") COMPONENTS=("mongodb" "rabbitmq" "gitea" "redis" "devbox")
COMPONENTS+=("${DEVBOX_COMPONENTS[@]}")
else else
COMPONENTS=("$COMPONENT") COMPONENTS=("$COMPONENT")
fi fi
# Check the status of the specified components # Check the status of the specified components
BASIC_COMPONENTS=("mongodb" "rabbitmq" "gitea" "redis")
ALL_COMPONENTS=("${BASIC_COMPONENTS[@]}" "${DEVBOX_COMPONENTS[@]}" "devbox")
for comp in "${COMPONENTS[@]}"; do for comp in "${COMPONENTS[@]}"; do
case "$comp" in case_checked=false
"mongodb") # devsvc, notification, content...
log_info "Checking MongoDB status..." if [ "$case_checked" = false ]; then
if [[ -f "${WORKING_HOME}/.mongodb-instance" ]]; then for svc in "${ALL_COMPONENTS[@]}"; do
local container_id if [ "$comp" = "$svc" ]; then
container_id=$(cat "${WORKING_HOME}/.mongodb-instance")
if docker ps --no-trunc --format '{{.ID}}' | grep -q "^${container_id}\$"; then
log_info "[RESULT]: MongoDB container is running."
else
log_info "[RESULT]: MongoDB container is not running."
fi
else
log_info "[RESULT]: MongoDB container is not running."
fi
;;
"rabbitmq")
log_info "Checking RabbitMQ status..."
if [[ -f "${WORKING_HOME}/.rabbitmq-instance" ]]; then
local container_id
container_id=$(cat "${WORKING_HOME}/.rabbitmq-instance")
if docker ps --no-trunc --format '{{.ID}}' | grep -q "^${container_id}\$"; then
log_info "[RESULT]: RabbitMQ container is running."
else
log_info "[RESULT]: RabbitMQ container is not running."
fi
else
log_info "[RESULT]: RabbitMQ container is not running."
fi
;;
"devbox")
log_info "Checking devbox service status..."
if [[ -f "${WORKING_HOME}/.devbox-instance" ]]; then
local container_id
container_id=$(cat "${WORKING_HOME}/.devbox-instance")
if docker ps --no-trunc --format '{{.ID}}' | grep -q "^${container_id}\$"; then
log_info "[RESULT]: devbox container is running."
else
log_info "[RESULT]: devbox container is not running."
fi
else
log_info "[RESULT]: devbox container is not running."
fi
;;
"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 if [ -f "${WORKING_HOME}/.${comp}-instance" ]; then
local container_id local container_id
container_id=$(cat "${WORKING_HOME}/.${comp}-instance") container_id=$(cat "${WORKING_HOME}/.${comp}-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
@ -2779,13 +2788,18 @@ devbox_status_command() {
else else
log_info "[RESULT]: $comp service is not running." log_info "[RESULT]: $comp service is not running."
fi fi
;; case_checked=true
break
*) fi
exit_with_message " Unknown component: $comp, please check the component name." 1
;;
esac
done done
fi
# unknown
if [ "$case_checked" = false ]; then
exit_with_message " Unknown component: $comp, please check the component name." 1
fi
done
exit_with_message " DevBox services status checked successfully." 0 exit_with_message " DevBox services status checked successfully." 0
} }
@ -2859,16 +2873,25 @@ devbox_restart_command() {
if [[ "$USE_LOCAL_COMPONENT" == "true" ]]; then if [[ "$USE_LOCAL_COMPONENT" == "true" ]]; then
log_info "Using local components..." log_info "Using local components..."
if [[ -z "$COMPONENT" ]]; then if [[ -z "$COMPONENT" ]]; then
COMPONENTS=("gitea" "mongodb" "rabbitmq" "devbox" "devsvc" "notification" "content" "central_storage" "chat" "authentication") COMPONENTS=("mongodb" "rabbitmq" "gitea" "redis" "devbox")
COMPONENTS+=("${DEVBOX_COMPONENTS[@]}")
else else
COMPONENTS=("$COMPONENT") COMPONENTS=("$COMPONENT")
fi fi
else else
log_info "Using remote components..." log_info "Using remote components..."
if [[ -z "$COMPONENT" ]]; then if [[ -z "$COMPONENT" ]]; then
COMPONENTS=("mongodb" "rabbitmq" "devbox") COMPONENTS=("mongodb" "rabbitmq" "gitea" "redis" "devbox")
else else
if [[ "$COMPONENT" == "devsvc" || "$COMPONENT" == "notification" || "$COMPONENT" == "content" || "$COMPONENT" == "central_storage" || "$COMPONENT" == "chat" || "$COMPONENT" == "authentication" ]]; then found=false
for item in "${DEVBOX_COMPONENTS[@]}"; do
if [ "$item" = "$COMPONENT" ]; then
found=true
break
fi
done
if [ "$found" = true ]; then
exit_with_message "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 fi
@ -2876,27 +2899,37 @@ devbox_restart_command() {
fi fi
fi fi
# Stop the specified components
BASIC_COMPONENTS=("mongodb" "rabbitmq" "gitea" "redis")
ALL_COMPONENTS=("${BASIC_COMPONENTS[@]}" "${DEVBOX_COMPONENTS[@]}" "devbox")
# Stop the specified components # Stop the specified components
for comp in "${COMPONENTS[@]}"; do for comp in "${COMPONENTS[@]}"; do
case "$comp" in if [ "$comp" = "devbox" ]; then
"devbox") 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")
log_info "Stopping devbox service..." log_info "Stopping devbox service..."
docker stop "$container_id" &>/dev/null || true docker stop "$container_id" &>/dev/null || true
# Remove the frontend and backend pid files
rm -f "${WORKING_HOME}/.backend.pid" rm -f "${WORKING_HOME}/.backend.pid"
rm -f "${WORKING_HOME}/.frontend.pid" rm -f "${WORKING_HOME}/.frontend.pid"
else else
log_info "Devbox is not running." log_info "Devbox is not running."
fi fi
;; continue
fi
"gitea" | "mongodb" | "rabbitmq" | "devsvc" | "notification" | "content" | "central_storage" | "chat" | "authentication") should_stop=false
for known in "${BASIC_COMPONENTS[@]}" "${DEVBOX_COMPONENTS[@]}"; do
if [ "$comp" = "$known" ]; then
should_stop=true
break
fi
done
if [[ -f "${WORKING_HOME}/.${comp}-instance" ]]; then if [ "$should_stop" = true ]; then
if [ -f "${WORKING_HOME}/.${comp}-instance" ]; then
local container_id local container_id
container_id=$(cat "${WORKING_HOME}/.${comp}-instance") container_id=$(cat "${WORKING_HOME}/.${comp}-instance")
log_info "Stopping $comp service..." log_info "Stopping $comp service..."
@ -2904,32 +2937,36 @@ devbox_restart_command() {
else else
log_info "$comp service is not running." log_info "$comp service is not running."
fi fi
;; else
*)
exit_with_message " Unknown component: $comp, please check the component name." 1 exit_with_message " Unknown component: $comp, please check the component name." 1
;; fi
esac
done done
# Start the specified components # 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 comp in "${COMPONENTS[@]}"; do for comp in "${COMPONENTS[@]}"; do
case "$comp" in is_known=false
"gitea" | "mongodb" | "rabbitmq" | "devbox" | "devsvc" | "notification" | "content" | "central_storage" | "chat" | "authentication") for known in "${ALL_COMPONENTS[@]}"; do
if [ "$comp" = "$known" ]; then
is_known=true
break
fi
done
if [ "$is_known" = true ]; then
log_info "Restarting $comp service..." log_info "Restarting $comp service..."
if [[ -f "${WORKING_HOME}/.${comp}-instance" ]]; then if [ -f "${WORKING_HOME}/.${comp}-instance" ]; then
local container_id local container_id
container_id=$(cat "${WORKING_HOME}/.${comp}-instance") container_id=$(cat "${WORKING_HOME}/.${comp}-instance")
docker start "$container_id" &>/dev/null || true docker start "$container_id" &>/dev/null || true
else else
log_info "$comp service is not running." log_info "$comp service is not running."
fi fi
;; else
*)
exit_with_message " Unknown component: $comp, please check the component name." 1 exit_with_message " Unknown component: $comp, please check the component name." 1
;; fi
esac
done done
exit_with_message " DevBox services restarted successfully." 0 exit_with_message " DevBox services restarted successfully." 0
} }
@ -3308,54 +3345,6 @@ devbox_init_parse_requirements() {
add_arg '--devbox-image-tag' "devbox_local" add_arg '--devbox-image-tag' "devbox_local"
fi fi
if [ -z "$(get_arg '--devsvc-image-tag')" ]; then
if [ "$current_arch" == "arm64" ]; then
add_arg '--devsvc-image-tag' "latest-linux-arm64"
else
add_arg '--devsvc-image-tag' "latest-linux-amd64"
fi
fi
if [ -z "$(get_arg '--content-image-tag')" ]; then
if [ "$current_arch" == "arm64" ]; then
add_arg '--content-image-tag' "latest-linux-arm64"
else
add_arg '--content-image-tag' "latest-linux-amd64"
fi
fi
if [ -z "$(get_arg '--central_storage-image-tag')" ]; then
if [ "$current_arch" == "arm64" ]; then
add_arg '--central_storage-image-tag' "latest-linux-arm64"
else
add_arg '--central_storage-image-tag' "latest-linux-amd64"
fi
fi
if [ -z "$(get_arg '--chat-image-tag')" ]; then
if [ "$current_arch" == "arm64" ]; then
add_arg '--chat-image-tag' "latest-linux-arm64"
else
add_arg '--chat-image-tag' "latest-linux-amd64"
fi
fi
if [ -z "$(get_arg '--notification-image-tag')" ]; then
if [ "$current_arch" == "arm64" ]; then
add_arg '--notification-image-tag' "latest-linux-arm64"
else
add_arg '--notification-image-tag' "latest-linux-amd64"
fi
fi
if [ -z "$(get_arg '--authentication-image-tag')" ]; then
if [ "$current_arch" == "arm64" ]; then
add_arg '--authentication-image-tag' "latest-linux-arm64"
else
add_arg '--authentication-image-tag' "latest-linux-amd64"
fi
fi
if [ -z "$(get_arg '--use-custom-repository')" ]; then if [ -z "$(get_arg '--use-custom-repository')" ]; then
add_arg '--use-custom-repository' "" add_arg '--use-custom-repository' ""
fi fi