updated structure

This commit is contained in:
ske087
2025-12-13 14:52:37 +02:00
parent 1a3e26d86d
commit e6193511e0
81 changed files with 0 additions and 10745 deletions

View File

@@ -0,0 +1,114 @@
#!/bin/bash
# Production Management Script for Trasabilitate Application
# Usage: ./manage_production.sh {start|stop|restart|status|logs|install-service}
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
print_success() {
echo -e "${GREEN}$1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
print_error() {
echo -e "${RED}$1${NC}"
}
print_info() {
echo -e "${BLUE} $1${NC}"
}
usage() {
echo "Usage: $0 {start|stop|restart|status|logs|install-service|help}"
echo ""
echo "Commands:"
echo " start Start the production server"
echo " stop Stop the production server"
echo " restart Restart the production server"
echo " status Show server status"
echo " logs Show recent logs"
echo " install-service Install systemd service"
echo " help Show this help message"
echo ""
}
case "$1" in
start)
./start_production.sh
;;
stop)
./stop_production.sh
;;
restart)
echo -e "${BLUE}🔄 Restarting Trasabilitate Application${NC}"
echo "=============================================="
./stop_production.sh
sleep 2
./start_production.sh
;;
status)
./status_production.sh
;;
logs)
echo -e "${BLUE}📋 Recent Error Logs${NC}"
echo "=============================================="
if [[ -f "/srv/quality_recticel/logs/error.log" ]]; then
tail -20 /srv/quality_recticel/logs/error.log
else
print_error "Error log file not found"
fi
echo ""
echo -e "${BLUE}📋 Recent Access Logs${NC}"
echo "=============================================="
if [[ -f "/srv/quality_recticel/logs/access.log" ]]; then
tail -10 /srv/quality_recticel/logs/access.log
else
print_error "Access log file not found"
fi
;;
install-service)
echo -e "${BLUE}📦 Installing Systemd Service${NC}"
echo "=============================================="
if [[ ! -f "trasabilitate.service" ]]; then
print_error "Service file not found"
exit 1
fi
print_info "Installing service file..."
sudo cp trasabilitate.service /etc/systemd/system/
print_info "Reloading systemd daemon..."
sudo systemctl daemon-reload
print_info "Enabling service..."
sudo systemctl enable trasabilitate.service
print_success "Service installed successfully!"
echo ""
echo "Systemd commands:"
echo " sudo systemctl start trasabilitate # Start service"
echo " sudo systemctl stop trasabilitate # Stop service"
echo " sudo systemctl restart trasabilitate # Restart service"
echo " sudo systemctl status trasabilitate # Check status"
echo " sudo systemctl enable trasabilitate # Enable auto-start"
echo " sudo systemctl disable trasabilitate # Disable auto-start"
;;
help|--help|-h)
usage
;;
*)
print_error "Invalid command: $1"
echo ""
usage
exit 1
;;
esac

View File

@@ -0,0 +1,185 @@
#!/bin/bash
# ============================================================================
# Quick Deployment Script for Quality Application
# Handles setup, build, and deployment in one command
# ============================================================================
set -e
# 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 functions
log_info() {
echo -e "${BLUE} INFO:${NC} $*"
}
log_success() {
echo -e "${GREEN}✅ SUCCESS:${NC} $*"
}
log_warning() {
echo -e "${YELLOW}⚠️ WARNING:${NC} $*"
}
log_error() {
echo -e "${RED}❌ ERROR:${NC} $*" >&2
}
# ============================================================================
# Functions
# ============================================================================
check_dependencies() {
log_info "Checking dependencies..."
if ! command -v docker &> /dev/null; then
log_error "Docker is not installed. Please install Docker first."
exit 1
fi
if ! command -v docker-compose &> /dev/null; then
log_error "docker-compose is not installed. Please install docker-compose first."
exit 1
fi
log_success "Dependencies check passed"
}
setup_environment() {
log_info "Setting up environment..."
# Create directories
bash setup-volumes.sh
# Check for .env file
if [ ! -f ".env" ]; then
log_warning ".env file not found, creating from example..."
cp .env.example .env
log_warning "Please edit .env file and set your passwords and configuration!"
log_warning "Press CTRL+C to cancel or ENTER to continue with default values (NOT RECOMMENDED FOR PRODUCTION)"
read -r
fi
log_success "Environment setup complete"
}
build_images() {
log_info "Building Docker images..."
docker-compose build --no-cache
log_success "Docker images built successfully"
}
start_services() {
log_info "Starting services..."
docker-compose up -d
log_success "Services started"
}
show_status() {
echo ""
echo "============================================================================"
echo "📊 Service Status"
echo "============================================================================"
docker-compose ps
echo ""
}
show_logs() {
log_info "Showing recent logs (press CTRL+C to exit)..."
sleep 2
docker-compose logs -f --tail=50
}
# ============================================================================
# Main Deployment
# ============================================================================
main() {
echo "============================================================================"
echo "🚀 Quality Application - Quick Deployment"
echo "============================================================================"
echo ""
# Parse arguments
BUILD_ONLY=false
SKIP_LOGS=false
while [[ $# -gt 0 ]]; do
case $1 in
--build-only)
BUILD_ONLY=true
shift
;;
--skip-logs)
SKIP_LOGS=true
shift
;;
--help)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --build-only Only build images, don't start services"
echo " --skip-logs Don't show logs after deployment"
echo " --help Show this help message"
echo ""
exit 0
;;
*)
log_error "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
# Check if we're in the right directory
if [ ! -f "docker-compose.yml" ]; then
log_error "docker-compose.yml not found. Please run this script from the application root directory."
exit 1
fi
# Execute deployment steps
check_dependencies
setup_environment
build_images
if [ "$BUILD_ONLY" = true ]; then
log_success "Build complete! Use 'docker-compose up -d' to start services."
exit 0
fi
start_services
show_status
echo "============================================================================"
echo "✅ Deployment Complete!"
echo "============================================================================"
echo ""
echo "Application URL: http://localhost:8781"
echo "Database Port: 3306 (accessible from host)"
echo ""
echo "Useful commands:"
echo " View logs: docker-compose logs -f web"
echo " Stop services: docker-compose down"
echo " Restart: docker-compose restart"
echo " Database shell: docker-compose exec db mysql -u trasabilitate -p"
echo ""
echo "Volume locations:"
echo " Database: ./data/mariadb/"
echo " Configuration: ./config/instance/"
echo " Logs: ./logs/"
echo " Backups: ./backups/"
echo ""
if [ "$SKIP_LOGS" = false ]; then
show_logs
fi
}
# Run main function
main "$@"

View File

@@ -0,0 +1,173 @@
#!/bin/bash
# Production Startup Script for Trasabilitate Application
# This script starts the application using Gunicorn WSGI server
set -e # Exit on any error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
print_step() {
echo -e "\n${BLUE}📋 $1${NC}"
echo "----------------------------------------"
}
print_success() {
echo -e "${GREEN}$1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
print_error() {
echo -e "${RED}$1${NC}"
}
echo -e "${BLUE}🚀 Trasabilitate Application - Production Startup${NC}"
echo "=============================================="
# Check if we're in the right directory
if [[ ! -f "wsgi.py" ]]; then
print_error "Please run this script from the py_app directory"
print_error "Expected location: /srv/quality_app/py_app or /srv/quality_recticel/py_app"
exit 1
fi
# Detect which installation we're running from
if [[ "$PWD" == *"/quality_app/"* ]]; then
LOG_DIR="/srv/quality_app/logs"
PROJECT_NAME="quality_app"
else
LOG_DIR="/srv/quality_recticel/logs"
PROJECT_NAME="quality_recticel"
fi
print_step "Checking Prerequisites"
# Check if virtual environment exists
if [[ ! -d "../recticel" ]]; then
print_error "Virtual environment 'recticel' not found"
print_error "Please create it first or run './quick_deploy.sh'"
exit 1
fi
print_success "Virtual environment found"
# Activate virtual environment
print_step "Activating Virtual Environment"
source ../recticel/bin/activate
print_success "Virtual environment activated"
# Check if Gunicorn is installed
if ! command -v gunicorn &> /dev/null; then
print_error "Gunicorn not found. Installing..."
pip install gunicorn
fi
print_success "Gunicorn is available"
# Check database connection
print_step "Testing Database Connection"
if python3 -c "
import mariadb
try:
conn = mariadb.connect(user='trasabilitate', password='Initial01!', host='localhost', database='trasabilitate')
conn.close()
print('Database connection successful')
except Exception as e:
print(f'Database connection failed: {e}')
exit(1)
" > /dev/null 2>&1; then
print_success "Database connection verified"
else
print_error "Database connection failed. Please run database setup first:"
print_error "python3 app/db_create_scripts/setup_complete_database.py"
exit 1
fi
# Create PID file directory
print_step "Setting up Runtime Environment"
mkdir -p ../run
print_success "Runtime directory created"
# Check if already running
PID_FILE="../run/trasabilitate.pid"
if [[ -f "$PID_FILE" ]]; then
PID=$(cat "$PID_FILE")
if ps -p "$PID" > /dev/null 2>&1; then
print_warning "Application is already running (PID: $PID)"
echo "To stop the application, run:"
echo "kill $PID"
echo "rm $PID_FILE"
exit 1
else
print_warning "Stale PID file found, removing..."
rm -f "$PID_FILE"
fi
fi
# Start Gunicorn
print_step "Starting Production Server"
echo "Starting Gunicorn WSGI server..."
echo "Configuration: gunicorn.conf.py"
echo "Workers: $(python3 -c 'import multiprocessing; print(multiprocessing.cpu_count() * 2 + 1)')"
echo "Binding to: 0.0.0.0:8781"
echo ""
# Start Gunicorn with configuration file
gunicorn --config gunicorn.conf.py \
--pid "$PID_FILE" \
--daemon \
wsgi:application
# Wait a moment for startup
sleep 2
# Check if the process started successfully
if [[ -f "$PID_FILE" ]]; then
PID=$(cat "$PID_FILE")
if ps -p "$PID" > /dev/null 2>&1; then
print_success "Application started successfully!"
echo ""
echo "=============================================="
echo -e "${GREEN}🎉 PRODUCTION SERVER RUNNING${NC}"
echo "=============================================="
echo ""
echo "📋 Server Information:"
echo " • Process ID: $PID"
echo " • Configuration: gunicorn.conf.py"
echo " • Project: $PROJECT_NAME"
echo " • Access Log: $LOG_DIR/access.log"
echo " • Error Log: $LOG_DIR/error.log"
echo ""
echo "🌐 Application URLs:"
echo " • Local: http://127.0.0.1:8781"
echo " • Network: http://$(hostname -I | awk '{print $1}'):8781"
echo ""
echo "👤 Default Login:"
echo " • Username: superadmin"
echo " • Password: superadmin123"
echo ""
echo "🔧 Management Commands:"
echo " • Stop server: kill $PID && rm $PID_FILE"
echo " • View logs: tail -f $LOG_DIR/error.log"
echo " • Monitor access: tail -f $LOG_DIR/access.log"
echo " • Server status: ps -p $PID"
echo ""
print_warning "Server is running in daemon mode (background)"
else
print_error "Failed to start application. Check logs:"
print_error "tail $LOG_DIR/error.log"
exit 1
fi
else
print_error "Failed to create PID file. Check permissions and logs."
exit 1
fi

View File

@@ -0,0 +1,88 @@
#!/bin/bash
# Production Status Script for Trasabilitate Application
# This script shows the current status of the Gunicorn WSGI server
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
print_success() {
echo -e "${GREEN}$1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
print_error() {
echo -e "${RED}$1${NC}"
}
echo -e "${BLUE}📊 Trasabilitate Application - Status Check${NC}"
echo "=============================================="
PID_FILE="../run/trasabilitate.pid"
# Detect which installation we're running from
if [[ "$PWD" == *"/quality_app/"* ]]; then
LOG_DIR="/srv/quality_app/logs"
PROJECT_NAME="quality_app"
else
LOG_DIR="/srv/quality_recticel/logs"
PROJECT_NAME="quality_recticel"
fi
if [[ ! -f "$PID_FILE" ]]; then
print_error "Application is not running (no PID file found)"
echo "To start the application, run: ./start_production.sh"
exit 1
fi
PID=$(cat "$PID_FILE")
if ps -p "$PID" > /dev/null 2>&1; then
print_success "Application is running (PID: $PID)"
echo ""
echo "📋 Process Information:"
ps -p "$PID" -o pid,ppid,pcpu,pmem,etime,cmd --no-headers | while read line; do
echo " $line"
done
echo ""
echo "🌐 Server Information:"
echo " • Project: $PROJECT_NAME"
echo " • Listening on: 0.0.0.0:8781"
echo " • Local URL: http://127.0.0.1:8781"
echo " • Network URL: http://$(hostname -I | awk '{print $1}'):8781"
echo ""
echo "📁 Log Files:"
echo " • Access Log: $LOG_DIR/access.log"
echo " • Error Log: $LOG_DIR/error.log"
echo ""
echo "🔧 Quick Commands:"
echo " • Stop server: ./stop_production.sh"
echo " • Restart server: ./stop_production.sh && ./start_production.sh"
echo " • View error log: tail -f $LOG_DIR/error.log"
echo " • View access log: tail -f $LOG_DIR/access.log"
echo ""
# Check if the web server is responding
if command -v curl > /dev/null 2>&1; then
echo "🌐 Connection Test:"
if curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:8781 | grep -q "200\|302\|401"; then
print_success "Web server is responding"
else
print_warning "Web server may not be responding properly"
fi
fi
else
print_error "Process $PID not found (stale PID file)"
print_warning "Cleaning up stale PID file..."
rm -f "$PID_FILE"
echo "To start the application, run: ./start_production.sh"
exit 1
fi

View File

@@ -0,0 +1,69 @@
#!/bin/bash
# Production Stop Script for Trasabilitate Application
# This script stops the Gunicorn WSGI server
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
print_success() {
echo -e "${GREEN}$1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
print_error() {
echo -e "${RED}$1${NC}"
}
echo -e "${BLUE}🛑 Trasabilitate Application - Production Stop${NC}"
echo "=============================================="
PID_FILE="../run/trasabilitate.pid"
if [[ ! -f "$PID_FILE" ]]; then
print_warning "No PID file found. Server may not be running."
echo "PID file location: $PID_FILE"
exit 1
fi
PID=$(cat "$PID_FILE")
if ps -p "$PID" > /dev/null 2>&1; then
echo "Stopping Trasabilitate application (PID: $PID)..."
# Send SIGTERM first (graceful shutdown)
kill "$PID"
# Wait for graceful shutdown
sleep 3
# Check if still running
if ps -p "$PID" > /dev/null 2>&1; then
print_warning "Process still running, sending SIGKILL..."
kill -9 "$PID"
sleep 1
fi
# Check if process is finally stopped
if ! ps -p "$PID" > /dev/null 2>&1; then
print_success "Application stopped successfully"
rm -f "$PID_FILE"
else
print_error "Failed to stop application (PID: $PID)"
exit 1
fi
else
print_warning "Process $PID not found. Cleaning up PID file..."
rm -f "$PID_FILE"
print_success "PID file cleaned up"
fi
echo ""
print_success "Trasabilitate application has been stopped"

View File

@@ -0,0 +1,27 @@
[Unit]
Description=Trasabilitate Quality Management Application
After=network.target mariadb.service
Wants=mariadb.service
[Service]
Type=forking
User=ske087
Group=ske087
WorkingDirectory=/srv/quality_recticel/py_app
Environment="PATH=/srv/quality_recticel/recticel/bin"
ExecStart=/srv/quality_recticel/recticel/bin/gunicorn --config gunicorn.conf.py --pid /srv/quality_recticel/run/trasabilitate.pid --daemon wsgi:application
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PIDFile=/srv/quality_recticel/run/trasabilitate.pid
Restart=always
RestartSec=10
# Security settings
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ReadWritePaths=/srv/quality_recticel
ProtectHome=true
[Install]
WantedBy=multi-user.target