Update README.md and scripts for improved setup and service management

- Changed repository URLs in README.md for consistency.
- Enhanced start.sh with a service health check function to verify if services are running and responding.
- Improved output messages in start.sh and stop.sh for better user experience.
- Added checks for port conflicts and ensured proper stopping of services in stop.sh.
This commit is contained in:
chamiakJ
2025-04-21 20:54:50 +05:30
parent 04ffc049b0
commit 50c4f1a6ac
3 changed files with 147 additions and 64 deletions

158
start.sh Normal file → Executable file
View File

@@ -4,12 +4,13 @@
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Print banner
echo -e "${GREEN}"
echo " __ __ _ _"
echo " \ \ / / | | | |"
echo " \ \ / / | | | |"
echo " \ \ /\ / /__ _ __| | _| | ___ _ __ ____"
echo " \ \/ \/ / _ \| '__| |/ / |/ _ \ '_ \|_ /"
echo " \ /\ / (_) | | | <| | __/ | | |/ /"
@@ -29,6 +30,51 @@ if [ ! -f .env ]; then
fi
fi
# Function to check if a service is running
check_service() {
local service_name=$1
local container_name=$2
local url=$3
local max_attempts=30
local attempt=1
echo -e "${BLUE}Checking ${service_name} service...${NC}"
# First check if the container is running
while [ $attempt -le $max_attempts ]; do
if docker ps | grep -q "${container_name}"; then
# Container is running
if [ -z "$url" ]; then
# No URL to check, assume service is up
echo -e "${GREEN}${NC} ${service_name} is running"
return 0
else
# Check if service endpoint is responding
if curl -s -f -o /dev/null "$url"; then
echo -e "${GREEN}${NC} ${service_name} is running and responding at ${url}"
return 0
else
if [ $attempt -eq $max_attempts ]; then
echo -e "${YELLOW}${NC} ${service_name} container is running but not responding at ${url}"
return 1
fi
fi
fi
else
if [ $attempt -eq $max_attempts ]; then
echo -e "${RED}${NC} ${service_name} failed to start"
return 1
fi
fi
echo -n "."
attempt=$((attempt+1))
sleep 1
done
return 1
}
# Check if Docker is installed
if ! command -v docker &> /dev/null; then
echo -e "${RED}Error: Docker is not installed or not in PATH${NC}"
@@ -37,7 +83,7 @@ if ! command -v docker &> /dev/null; then
fi
# Check if Docker daemon is running
echo "Running preflight checks..."
echo -e "${BLUE}Running preflight checks...${NC}"
if ! docker info &> /dev/null; then
echo -e "${RED}Error: Docker daemon is not running${NC}"
echo "Please start Docker and try again"
@@ -45,58 +91,64 @@ if ! docker info &> /dev/null; then
fi
echo -e "${GREEN}${NC} Docker is running"
# Check if Docker Compose is installed
if ! command -v docker compose &> /dev/null; then
echo "Warning: Docker Compose V2 not found, trying docker-compose command..."
if ! command -v docker-compose &> /dev/null; then
echo "Error: Docker Compose is not installed or not in PATH"
echo "Please install Docker Compose: https://docs.docker.com/compose/install/"
exit 1
# Determine Docker Compose command to use
DOCKER_COMPOSE_CMD=""
if command -v docker compose &> /dev/null; then
DOCKER_COMPOSE_CMD="docker compose"
echo -e "${GREEN}${NC} Using Docker Compose V2"
elif command -v docker-compose &> /dev/null; then
DOCKER_COMPOSE_CMD="docker-compose"
echo -e "${YELLOW}${NC} Using legacy Docker Compose"
else
echo -e "${RED}Error: Docker Compose is not installed or not in PATH${NC}"
echo "Please install Docker Compose: https://docs.docker.com/compose/install/"
exit 1
fi
# Check if any of the ports are already in use
ports=(3000 5000 9000 9001 5432)
for port in "${ports[@]}"; do
if lsof -i:"$port" > /dev/null 2>&1; then
echo -e "${YELLOW}⚠ Warning: Port $port is already in use. This may cause conflicts.${NC}"
fi
# Use docker-compose command instead
docker-compose down
docker-compose up -d
done
# Start the containers
echo -e "${BLUE}Starting Worklenz services...${NC}"
$DOCKER_COMPOSE_CMD down
$DOCKER_COMPOSE_CMD up -d
# Wait for services to fully initialize
echo -e "${BLUE}Waiting for services to initialize...${NC}"
echo "This may take a minute or two depending on your system..."
# Check each service
check_service "Database" "worklenz_db" ""
DB_STATUS=$?
check_service "MinIO" "worklenz_minio" "http://localhost:9000/minio/health/live"
MINIO_STATUS=$?
check_service "Backend" "worklenz_backend" "http://localhost:3000/api/health"
BACKEND_STATUS=$?
check_service "Frontend" "worklenz_frontend" "http://localhost:5000"
FRONTEND_STATUS=$?
# Display service URLs
echo -e "\n${BLUE}Service URLs:${NC}"
[ $FRONTEND_STATUS -eq 0 ] && echo " • Frontend: http://localhost:5000"
[ $BACKEND_STATUS -eq 0 ] && echo " • Backend API: http://localhost:3000"
[ $MINIO_STATUS -eq 0 ] && echo " • MinIO Console: http://localhost:9001 (login: minioadmin/minioadmin)"
# Check if all services are up
if [ $DB_STATUS -eq 0 ] && [ $MINIO_STATUS -eq 0 ] && [ $BACKEND_STATUS -eq 0 ] && [ $FRONTEND_STATUS -eq 0 ]; then
echo -e "\n${GREEN}✅ All Worklenz services are running successfully!${NC}"
else
# Use Docker Compose V2
docker compose down
docker compose up -d
echo -e "\n${YELLOW}⚠ Some services may not be running properly. Check the logs for more details:${NC}"
echo " $DOCKER_COMPOSE_CMD logs"
fi
# Wait for services to be ready
echo "Waiting for services to start..."
sleep 5
# Check if services are running
if docker ps | grep -q "worklenz_frontend"; then
echo -e "${GREEN}${NC} Frontend is running"
FRONTEND_URL="http://localhost:5000"
echo " Frontend URL: $FRONTEND_URL"
else
echo "✗ Frontend service failed to start"
fi
if docker ps | grep -q "worklenz_backend"; then
echo -e "${GREEN}${NC} Backend is running"
BACKEND_URL="http://localhost:3000"
echo " Backend URL: $BACKEND_URL"
else
echo "✗ Backend service failed to start"
fi
if docker ps | grep -q "worklenz_minio"; then
echo -e "${GREEN}${NC} MinIO is running"
MINIO_URL="http://localhost:9001"
echo " MinIO Console URL: $MINIO_URL (login: minioadmin/minioadmin)"
else
echo "✗ MinIO service failed to start"
fi
if docker ps | grep -q "worklenz_db"; then
echo -e "${GREEN}${NC} Database is running"
else
echo "✗ Database service failed to start"
fi
echo -e "\n${GREEN}Worklenz is now running!${NC}"
echo "You can access the application at: http://localhost:5000"
echo "To stop the services, run: docker compose down"
echo -e "\n${BLUE}Useful commands:${NC}"
echo " • View logs: $DOCKER_COMPOSE_CMD logs -f"
echo " • Stop services: ./stop.sh"