Files
TSYSDevStack/artifacts/SupportStack/code/TSYSDevStack-SupportStack-Demo-Control.sh
ReachableCEO ce60ffcb1f refactor: reorganize file structure and update .gitignore
- Move settings file to config/ directory
- Move control script to code/ directory
- Remove create-network.sh script as requested
- Create comprehensive .gitignore file to handle test logs and artifacts
- Update all scripts to reference new file locations
- Update STATUS.md to reflect new file structure

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2025-10-28 18:21:30 -05:00

335 lines
10 KiB
Bash
Executable File

#!/bin/bash
# TSYSDevStack SupportStack Demo - Control Script
# Provides start/stop/uninstall/update/test functionality for the MVP stack
set -e # Exit on any error
# Load environment settings
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONFIG_DIR="$(dirname "$SCRIPT_DIR")/config"
ENV_FILE="${CONFIG_DIR}/TSYSDevStack-SupportStack-Demo-Settings"
if [ ! -f "$ENV_FILE" ]; then
echo "Error: Environment settings file not found at $ENV_FILE"
exit 1
fi
source "$ENV_FILE"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Logging function
log() {
echo -e "${BLUE}[$(date +'%Y-%m-%d %H:%M:%S')]${NC} $1"
}
log_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
log_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
# Function to check if docker is available
check_docker() {
if ! command -v docker &> /dev/null; then
log_error "Docker is not installed or not in PATH"
exit 1
fi
if ! docker info &> /dev/null; then
log_error "Docker is not running or not accessible"
exit 1
fi
}
# Function to create the shared network
create_network() {
log "Creating shared network: $TSYSDEVSTACK_NETWORK_NAME"
if ! docker network ls | grep -q "$TSYSDEVSTACK_NETWORK_NAME"; then
docker network create "$TSYSDEVSTACK_NETWORK_NAME" --driver bridge
log_success "Network created: $TSYSDEVSTACK_NETWORK_NAME"
else
log "Network already exists: $TSYSDEVSTACK_NETWORK_NAME"
fi
}
# Function to remove the shared network
remove_network() {
log "Removing shared network: $TSYSDEVSTACK_NETWORK_NAME"
if docker network ls | grep -q "$TSYSDEVSTACK_NETWORK_NAME"; then
docker network rm "$TSYSDEVSTACK_NETWORK_NAME"
log_success "Network removed: $TSYSDEVSTACK_NETWORK_NAME"
else
log "Network does not exist: $TSYSDEVSTACK_NETWORK_NAME"
fi
}
# Function to start the MVP stack
start() {
log "Starting TSYSDevStack SupportStack Demo MVP"
check_docker
create_network
# Start docker-socket-proxy first (dependency for homepage)
log "Starting docker-socket-proxy..."
COMPOSE_DIR="$(dirname "$SCRIPT_DIR")/docker-compose"
if [ -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-docker-socket-proxy.yml" ]; then
docker compose -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-docker-socket-proxy.yml" up -d
log_success "docker-socket-proxy started"
else
log_warning "docker-socket-proxy compose file not found, skipping..."
fi
# Wait for docker socket proxy to be ready
log "Waiting for docker-socket-proxy to be ready..."
sleep 10
# Start homepage
log "Starting homepage..."
COMPOSE_DIR="$(dirname "$SCRIPT_DIR")/docker-compose"
if [ -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-homepage.yml" ]; then
docker compose -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-homepage.yml" up -d
log_success "homepage started"
else
log_warning "homepage compose file not found, skipping..."
fi
# Wait for homepage to be ready
log "Waiting for homepage to be ready..."
sleep 15
# Start wakaapi
log "Starting wakaapi..."
COMPOSE_DIR="$(dirname "$SCRIPT_DIR")/docker-compose"
if [ -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-wakaapi.yml" ]; then
docker compose -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-wakaapi.yml" up -d
log_success "wakaapi started"
else
log_warning "wakaapi compose file not found, skipping..."
fi
# Wait for services to be ready
log "Waiting for all services to be ready..."
sleep 20
log_success "MVP stack started successfully"
echo "Homepage available at: http://$BIND_ADDRESS:$HOMEPAGE_PORT"
echo "WakaAPI available at: http://$BIND_ADDRESS:$WAKAAPI_PORT"
}
# Function to stop the MVP stack
stop() {
log "Stopping TSYSDevStack SupportStack Demo MVP"
check_docker
# Stop wakaapi first
COMPOSE_DIR="$(dirname "$SCRIPT_DIR")/docker-compose"
log "Stopping wakaapi..."
if [ -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-wakaapi.yml" ]; then
docker compose -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-wakaapi.yml" down
log_success "wakaapi stopped"
else
log_warning "wakaapi compose file not found, skipping..."
fi
# Stop homepage
log "Stopping homepage..."
if [ -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-homepage.yml" ]; then
docker compose -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-homepage.yml" down
log_success "homepage stopped"
else
log_warning "homepage compose file not found, skipping..."
fi
# Stop docker-socket-proxy last
log "Stopping docker-socket-proxy..."
if [ -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-docker-socket-proxy.yml" ]; then
docker compose -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-docker-socket-proxy.yml" down
log_success "docker-socket-proxy stopped"
else
log_warning "docker-socket-proxy compose file not found, skipping..."
fi
log_success "MVP stack stopped successfully"
}
# Function to uninstall the MVP stack
uninstall() {
log "Uninstalling TSYSDevStack SupportStack Demo MVP"
check_docker
# Stop all services first
stop
# Remove containers, volumes, and networks
log "Removing containers and volumes..."
COMPOSE_DIR="$(dirname "$SCRIPT_DIR")/docker-compose"
if [ -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-docker-socket-proxy.yml" ]; then
docker compose -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-docker-socket-proxy.yml" down -v
fi
if [ -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-homepage.yml" ]; then
docker compose -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-homepage.yml" down -v
fi
if [ -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-wakaapi.yml" ]; then
docker compose -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-wakaapi.yml" down -v
fi
# Remove the shared network
remove_network
log_success "MVP stack uninstalled successfully"
}
# Function to update the MVP stack
update() {
log "Updating TSYSDevStack SupportStack Demo MVP"
check_docker
# Pull the latest images
log "Pulling latest images..."
COMPOSE_DIR="$(dirname "$SCRIPT_DIR")/docker-compose"
if [ -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-docker-socket-proxy.yml" ]; then
docker compose -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-docker-socket-proxy.yml" pull
log_success "docker-socket-proxy images updated"
fi
if [ -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-homepage.yml" ]; then
docker compose -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-homepage.yml" pull
log_success "homepage images updated"
fi
if [ -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-wakaapi.yml" ]; then
docker compose -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-wakaapi.yml" pull
log_success "wakaapi images updated"
fi
log "Restarting services with updated images..."
stop
start
log_success "MVP stack updated successfully"
}
# Function to run tests
test() {
log "Running tests for TSYSDevStack SupportStack Demo MVP"
check_docker
# Add test functions here
log "Checking if services are running..."
COMPOSE_DIR="$(dirname "$SCRIPT_DIR")/docker-compose"
# Check docker-socket-proxy
if [ -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-docker-socket-proxy.yml" ]; then
if docker compose -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-docker-socket-proxy.yml" ps | grep -q "Up"; then
log_success "docker-socket-proxy is running"
else
log_error "docker-socket-proxy is not running"
fi
fi
# Check homepage
if [ -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-homepage.yml" ]; then
if docker compose -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-homepage.yml" ps | grep -q "Up"; then
log_success "homepage is running"
else
log_error "homepage is not running"
fi
fi
# Check wakaapi
if [ -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-wakaapi.yml" ]; then
if docker compose -f "${COMPOSE_DIR}/TSYSDevStack-SupportStack-Demo-DockerCompose-wakaapi.yml" ps | grep -q "Up"; then
log_success "wakaapi is running"
else
log_error "wakaapi is not running"
fi
fi
# Run any unit/integration tests if available
if [ -d "${SCRIPT_DIR}/tests" ]; then
log "Running specific tests..."
# Add specific test commands here when test files exist
log_success "Tests completed"
else
log_warning "No tests directory found"
fi
log_success "Test execution completed"
}
# Function to display help
show_help() {
cat << EOF
TSYSDevStack SupportStack Demo - Control Script
Usage: $0 {start|stop|uninstall|update|test|help}
Commands:
start Start the MVP stack (docker-socket-proxy, homepage, wakaapi)
stop Stop the MVP stack
uninstall Uninstall the MVP stack (stop and remove all containers, volumes, and networks)
update Update the MVP stack to latest images and restart
test Run tests to verify the stack functionality
help Show this help message
Examples:
$0 start
$0 stop
$0 uninstall
$0 update
$0 test
EOF
}
# Main script logic
case "$1" in
start)
start
;;
stop)
stop
;;
uninstall)
uninstall
;;
update)
update
;;
test)
test
;;
help|--help|-h)
show_help
;;
*)
if [ -z "$1" ]; then
log_error "No command provided. Use $0 help for usage information."
else
log_error "Unknown command: $1. Use $0 help for usage information."
fi
show_help
exit 1
;;
esac