Skip to content

Commit c8a3a54

Browse files
committed
增加部署完成自动启动选项
1 parent df43e6d commit c8a3a54

File tree

1 file changed

+42
-4
lines changed

1 file changed

+42
-4
lines changed

setup-services.sh

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,45 @@ if [ -n "$INPUT_IP" ]; then
423423
fi
424424
fi
425425

426-
echo -e "\nTo start services:"
427-
echo -e "${BLUE}cd $TARGET_DIR${NC}"
428-
echo -e "${BLUE}docker compose up -d${NC}"
429-
echo -e "${BLUE}docker compose restart nginx${NC} (If SSL certs updated)"
426+
# --- 6. Auto-start Services ---
427+
echo -e "\n${BLUE}Service Startup${NC}"
428+
429+
START_SERVICES="n"
430+
431+
if [ "$AUTO_YES" == "true" ]; then
432+
START_SERVICES="y"
433+
echo -e "${YELLOW}Auto-starting services in non-interactive mode.${NC}"
434+
else
435+
read -p "Do you want to start the services now? (y/N) " START_SERVICES
436+
fi
437+
438+
if [[ "$START_SERVICES" == "y" || "$START_SERVICES" == "Y" ]]; then
439+
echo -e "${BLUE}Starting Docker services...${NC}"
440+
cd "$TARGET_DIR" || { echo -e "${RED}Failed to change directory to $TARGET_DIR${NC}"; exit 1; }
441+
442+
# Check if docker-compose command is available (v2 vs v1)
443+
if docker compose version &> /dev/null; then
444+
DOCKER_CMD="docker compose"
445+
elif docker-compose version &> /dev/null; then
446+
DOCKER_CMD="docker-compose"
447+
else
448+
echo -e "${RED}Error: Neither 'docker compose' nor 'docker-compose' found.${NC}"
449+
exit 1
450+
fi
451+
452+
echo -e "${BLUE}Executing: $DOCKER_CMD up -d${NC}"
453+
$DOCKER_CMD up -d
454+
455+
if [ $? -eq 0 ]; then
456+
echo -e "${GREEN}Services started successfully!${NC}"
457+
echo -e "${YELLOW}Note: Some services (like databases) may take a few moments to initialize completely.${NC}"
458+
else
459+
echo -e "${RED}Failed to start services.${NC}"
460+
exit 1
461+
fi
462+
else
463+
echo -e "\nTo start services manually:"
464+
echo -e "${BLUE}cd $TARGET_DIR${NC}"
465+
echo -e "${BLUE}docker compose up -d${NC}"
466+
echo -e "${BLUE}docker compose restart nginx${NC} (If SSL certs updated)"
467+
fi

0 commit comments

Comments
 (0)