Files
api-sessions/manage.sh
2026-01-23 01:03:09 +01:00

186 líneas
4.4 KiB
Bash
Archivo Ejecutable

#!/bin/sh
# Project Management Script for API Sessions
print_header() {
echo "================================================"
echo "$1"
echo "================================================"
}
show_help() {
echo ""
print_header "API Sessions - Project Commands"
echo ""
echo "Usage: ./manage.sh [command]"
echo ""
echo "Commands:"
echo " start - Start the Spring Boot application"
echo " stop - Stop the running application"
echo " restart - Restart the application"
echo " test - Run comprehensive API tests"
echo " quick-test - Run quick API tests"
echo " clean - Clean Maven build"
echo " build - Build the project"
echo " console - Show H2 console URL"
echo " logs - Show application logs (tail)"
echo " status - Check if application is running"
echo " help - Show this help message"
echo ""
echo "Examples:"
echo " ./manage.sh start"
echo " ./manage.sh test"
echo " ./manage.sh status"
echo ""
}
start_app() {
print_header "Starting Application"
if pgrep -f "api-sessions" > /dev/null; then
echo "Application is already running!"
echo "Use './manage.sh stop' to stop it first."
else
echo "Starting Spring Boot application..."
./mvnw spring-boot:run > app.log 2>&1 &
echo "Application starting in background..."
echo "Logs are being written to app.log"
echo "Use './manage.sh logs' to view logs"
sleep 5
if pgrep -f "api-sessions" > /dev/null; then
echo "✓ Application started successfully!"
echo "Server running at: http://localhost:8080"
else
echo "✗ Failed to start application. Check app.log for errors."
fi
fi
}
stop_app() {
print_header "Stopping Application"
if pgrep -f "api-sessions" > /dev/null; then
pkill -f "api-sessions"
echo "✓ Application stopped"
else
echo "Application is not running"
fi
}
restart_app() {
stop_app
sleep 2
start_app
}
run_tests() {
print_header "Running Comprehensive Tests"
if ! pgrep -f "api-sessions" > /dev/null; then
echo "Application is not running!"
echo "Starting application first..."
start_app
sleep 10
fi
./test-api.sh
}
run_quick_test() {
print_header "Running Quick Tests"
if ! pgrep -f "api-sessions" > /dev/null; then
echo "Application is not running!"
echo "Starting application first..."
start_app
sleep 10
fi
./quick-test.sh
}
clean_build() {
print_header "Cleaning Build"
./mvnw clean
echo "✓ Build cleaned"
}
build_project() {
print_header "Building Project"
./mvnw clean install
}
show_console() {
print_header "H2 Database Console"
echo "URL: http://localhost:8080/h2-console"
echo ""
echo "Connection Settings:"
echo " JDBC URL: jdbc:h2:mem:testdb"
echo " Username: sa"
echo " Password: (leave empty)"
echo ""
}
show_logs() {
if [ -f app.log ]; then
tail -f app.log
else
echo "No log file found. Application might not have been started with './manage.sh start'"
fi
}
check_status() {
print_header "Application Status"
if pgrep -f "api-sessions" > /dev/null; then
echo "✓ Application is RUNNING"
echo "PID: $(pgrep -f api-sessions)"
echo "URL: http://localhost:8080"
echo ""
echo "Testing connectivity..."
if curl -s http://localhost:8080/api/auth/login > /dev/null 2>&1; then
echo "✓ API is responding"
else
echo "✗ API is not responding"
fi
else
echo "✗ Application is NOT running"
echo "Use './manage.sh start' to start it"
fi
}
# Main command handler
case "$1" in
start)
start_app
;;
stop)
stop_app
;;
restart)
restart_app
;;
test)
run_tests
;;
quick-test)
run_quick_test
;;
clean)
clean_build
;;
build)
build_project
;;
console)
show_console
;;
logs)
show_logs
;;
status)
check_status
;;
help|--help|-h|"")
show_help
;;
*)
echo "Unknown command: $1"
show_help
exit 1
;;
esac