Files
roa2web-service-auto/bot.sh
Marius Mutu d507a81b0a feat: Implement unified Vue SPA with granular service control
Consolidate Reports and Data Entry apps into a single Vue.js SPA with:

Architecture:
- Module-based structure with lazy-loaded routes (@reports, @data-entry)
- Error boundaries per module to prevent cascade failures
- Dual API proxy in Vite for microservices (reports:8001, data-entry:8003)
- Pinia store factories for shared auth, company, and period stores
- Vite path aliases for clear module boundaries (@shared, @reports, @data-entry)

Service Management:
- Granular service control scripts (backend-reports.sh, backend-data-entry.sh, bot.sh, frontend.sh)
- 87% faster frontend restart: 7s vs 53s full restart
- 38% faster full startup: 33s vs 53s via parallel backend initialization
- Enhanced start-dev.sh with proper service timeouts (OCR: 30s, Vite: 15s, Bot: 10s)
- status.sh for comprehensive health checks

Features:
- Auto-select first company on login with period auto-load
- Hamburger menu with feature toggle support
- JWT token auto-injection via axios interceptors
- Unified header with company/period selectors
- IIS web.config for production deployment with multi-API routing

UX Improvements:
- Vue watchers for reactive company/period loading
- Lazy store initialization with graceful error handling
- Period persistence per user+company in localStorage
- Feature flags for optional modules

Deployment:
- Single IIS site serves unified frontend with API proxy rules
- Maintains separate backend processes for microservices
- Windows line ending fixes (.env CRLF → LF conversion)

Stats: 112 files changed, 38,342 insertions(+), 2,342 deletions(-)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-24 19:06:23 +02:00

148 lines
3.5 KiB
Bash

#!/bin/bash
# Telegram Bot Service Control Script for ROA2WEB Unified App
# Manages the Telegram Bot on port 8002
# Script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$SCRIPT_DIR"
# Source helper functions
source "$SCRIPT_DIR/scripts/service-helpers.sh"
# Service configuration
SERVICE_NAME="Telegram Bot"
PORT=8002
LOG_FILE="/tmp/telegram-bot.log"
BOT_DIR="$ROOT_DIR/reports-app/telegram-bot"
VENV_DIR="$BOT_DIR/venv"
ENV_FILE="$BOT_DIR/.env"
# Function to start bot
start_bot() {
print_header "Starting $SERVICE_NAME"
# Check if port is already in use
if ! check_port_available $PORT "$SERVICE_NAME"; then
print_warning "$SERVICE_NAME may already be running"
print_info "Use './bot.sh status' to check or './bot.sh stop' to stop it"
return 1
fi
# Check bot directory
if [ ! -d "$BOT_DIR" ]; then
print_error "Bot directory not found: $BOT_DIR"
return 1
fi
# Check virtual environment
if [ ! -d "$VENV_DIR" ]; then
print_error "Virtual environment not found: $VENV_DIR"
print_info "Please run setup first: cd reports-app/telegram-bot && python3 -m venv venv && source venv/bin/activate && pip install -r requirements.txt"
return 1
fi
# Check .env file
if [ ! -f "$ENV_FILE" ]; then
print_warning ".env file not found: $ENV_FILE"
print_info "Bot may not start without TELEGRAM_BOT_TOKEN"
fi
# Start bot
print_info "Starting Telegram bot..."
cd "$BOT_DIR"
# Activate venv and start bot in background
(
source venv/bin/activate
nohup python -m app.main > "$LOG_FILE" 2>&1 &
echo $! > /tmp/telegram-bot.pid
)
local pid=$(cat /tmp/telegram-bot.pid 2>/dev/null)
print_info "Started with PID: $pid"
print_info "Log file: $LOG_FILE"
# Wait for port to be ready
if wait_for_port $PORT "$SERVICE_NAME" 5; then
print_success "$SERVICE_NAME started successfully!"
echo ""
print_info "🤖 Bot is running and listening for commands"
print_info "📄 View logs: tail -f $LOG_FILE"
return 0
else
print_error "Failed to start $SERVICE_NAME (timeout waiting for port $PORT)"
print_info "Check logs: tail -20 $LOG_FILE"
rm -f /tmp/telegram-bot.pid
return 1
fi
}
# Function to stop bot
stop_bot() {
print_header "Stopping $SERVICE_NAME"
kill_port $PORT "$SERVICE_NAME"
# Clean up PID file
if [ -f "/tmp/telegram-bot.pid" ]; then
rm /tmp/telegram-bot.pid
fi
return 0
}
# Function to show bot status
status_bot() {
print_header "$SERVICE_NAME Status"
if check_service_status $PORT "$SERVICE_NAME"; then
echo ""
print_info "Service is running"
# Show recent logs
if [ -f "$LOG_FILE" ]; then
echo ""
tail_logs "$LOG_FILE" 10
fi
return 0
else
echo ""
print_warning "Service is not running"
# Show last logs if available
if [ -f "$LOG_FILE" ]; then
echo ""
print_info "Last logs before shutdown:"
tail_logs "$LOG_FILE" 10
fi
return 1
fi
}
# Main script logic
case "${1:-}" in
start)
start_bot
;;
stop)
stop_bot
;;
status)
status_bot
;;
*)
echo "Usage: $0 {start|stop|status}"
echo ""
echo "Commands:"
echo " start - Start the Telegram bot"
echo " stop - Stop the Telegram bot"
echo " status - Show bot status"
echo ""
echo "Examples:"
echo " ./bot.sh start # Start bot"
echo " ./bot.sh status # Check if running"
echo " ./bot.sh stop # Stop bot"
exit 1
;;
esac