- Add configuration of agents, tasks, tools, specialist in context of SPIN specialist
- correct startup of applications using gevent - introduce startup scripts (eveai_app) - caching manager for all configurations
This commit is contained in:
102
scripts/db_backup.sh
Executable file
102
scripts/db_backup.sh
Executable file
@@ -0,0 +1,102 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Configuration
|
||||
DEV_DB_HOST="localhost"
|
||||
DEV_DB_PORT="5432"
|
||||
DEV_DB_NAME="eveai"
|
||||
DEV_DB_USER="luke"
|
||||
DEV_DB_PASSWORD="Skywalker!"
|
||||
|
||||
PROD_DB_HOST="bswnz4.stackhero-network.com"
|
||||
PROD_DB_PORT="5945"
|
||||
PROD_DB_NAME="eveai"
|
||||
PROD_DB_USER="luke_skywalker"
|
||||
PROD_DB_PASSWORD="2MK&1rHmWEydE2rFuJLq*ls%tdkPAk2"
|
||||
|
||||
# Create backup directory if it doesn't exist
|
||||
BACKUP_DIR="./db_backups"
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
|
||||
# Get current date for backup file name
|
||||
DATE=$(date +"%Y%m%d_%H%M%S")
|
||||
|
||||
# Function to check if pg_dump is available
|
||||
check_pg_dump() {
|
||||
if ! command -v pg_dump &> /dev/null; then
|
||||
echo "Error: pg_dump is not installed. Please install PostgreSQL client tools."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to create backup
|
||||
create_backup() {
|
||||
local env=$1
|
||||
local host=$2
|
||||
local port=$3
|
||||
local db=$4
|
||||
local user=$5
|
||||
local password=$6
|
||||
|
||||
# Set backup filename
|
||||
local backup_file="${BACKUP_DIR}/eveai_${env}_backup_${DATE}.sql"
|
||||
|
||||
echo "Creating backup for ${env} environment..."
|
||||
echo "Backing up to: ${backup_file}"
|
||||
|
||||
# Set PGPASSWORD environment variable
|
||||
export PGPASSWORD="$password"
|
||||
|
||||
# Create backup using pg_dump
|
||||
pg_dump -h "$host" -p "$port" -U "$user" -d "$db" -F p > "$backup_file"
|
||||
|
||||
# Check if backup was successful
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Backup completed successfully!"
|
||||
echo "Backup file: ${backup_file}"
|
||||
|
||||
# Create compressed version
|
||||
gzip -f "$backup_file"
|
||||
echo "Compressed backup created: ${backup_file}.gz"
|
||||
else
|
||||
echo "Error: Backup failed!"
|
||||
rm -f "$backup_file" # Clean up failed backup file
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Unset PGPASSWORD for security
|
||||
unset PGPASSWORD
|
||||
}
|
||||
|
||||
# Function to display usage
|
||||
usage() {
|
||||
echo "Usage: $0 [dev|prod]"
|
||||
echo " dev - backup development database"
|
||||
echo " prod - backup production database"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Main script logic
|
||||
main() {
|
||||
# Check for pg_dump
|
||||
check_pg_dump
|
||||
|
||||
# Check command line arguments
|
||||
if [ $# -ne 1 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
"dev")
|
||||
create_backup "dev" "$DEV_DB_HOST" "$DEV_DB_PORT" "$DEV_DB_NAME" "$DEV_DB_USER" "$DEV_DB_PASSWORD"
|
||||
;;
|
||||
"prod")
|
||||
create_backup "prod" "$PROD_DB_HOST" "$PROD_DB_PORT" "$PROD_DB_NAME" "$PROD_DB_USER" "$PROD_DB_PASSWORD"
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Run main function
|
||||
main "$@"
|
||||
173
scripts/db_restore.sh
Executable file
173
scripts/db_restore.sh
Executable file
@@ -0,0 +1,173 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Configuration
|
||||
DEV_DB_HOST="localhost"
|
||||
DEV_DB_PORT="5432"
|
||||
DEV_DB_NAME="eveai"
|
||||
DEV_DB_USER="luke"
|
||||
DEV_DB_PASSWORD="Skywalker!"
|
||||
|
||||
PROD_DB_HOST="bswnz4.stackhero-network.com"
|
||||
PROD_DB_PORT="5945"
|
||||
PROD_DB_NAME="eveai"
|
||||
PROD_DB_USER="luke_skywalker"
|
||||
PROD_DB_PASSWORD="2MK&1rHmWEydE2rFuJLq*ls%tdkPAk2"
|
||||
|
||||
# Backup directory
|
||||
BACKUP_DIR="./db_backups"
|
||||
|
||||
# Function to check if psql is available
|
||||
check_psql() {
|
||||
if ! command -v psql &> /dev/null; then
|
||||
echo "Error: psql is not installed. Please install PostgreSQL client tools."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to list available backups
|
||||
list_backups() {
|
||||
echo "Available backups:"
|
||||
ls -lh "${BACKUP_DIR}"/*.gz 2>/dev/null || echo "No backups found in ${BACKUP_DIR}"
|
||||
}
|
||||
|
||||
# Function to restore backup
|
||||
restore_backup() {
|
||||
local env=$1
|
||||
local backup_file=$2
|
||||
local host=""
|
||||
local port=""
|
||||
local db=""
|
||||
local user=""
|
||||
local password=""
|
||||
|
||||
# Set environment-specific variables
|
||||
case "$env" in
|
||||
"dev")
|
||||
host="$DEV_DB_HOST"
|
||||
port="$DEV_DB_PORT"
|
||||
db="$DEV_DB_NAME"
|
||||
user="$DEV_DB_USER"
|
||||
password="$DEV_DB_PASSWORD"
|
||||
;;
|
||||
"prod")
|
||||
host="$PROD_DB_HOST"
|
||||
port="$PROD_DB_PORT"
|
||||
db="$PROD_DB_NAME"
|
||||
user="$PROD_DB_USER"
|
||||
password="$PROD_DB_PASSWORD"
|
||||
;;
|
||||
*)
|
||||
echo "Invalid environment specified"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Check if backup file exists
|
||||
if [ ! -f "$backup_file" ]; then
|
||||
echo "Error: Backup file not found: $backup_file"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Safety confirmation
|
||||
echo "WARNING: This will overwrite the current $env database!"
|
||||
echo "Database: $db"
|
||||
echo "Host: $host"
|
||||
echo "Port: $port"
|
||||
read -p "Are you sure you want to proceed? (type 'yes' to confirm): " confirm
|
||||
if [ "$confirm" != "yes" ]; then
|
||||
echo "Restore cancelled."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Starting restore process..."
|
||||
|
||||
# Create temporary directory for uncompressed backup
|
||||
local temp_dir=$(mktemp -d)
|
||||
local temp_file="${temp_dir}/temp_backup.sql"
|
||||
|
||||
# Uncompress backup file
|
||||
echo "Uncompressing backup file..."
|
||||
gunzip -c "$backup_file" > "$temp_file"
|
||||
|
||||
# Set PGPASSWORD environment variable
|
||||
export PGPASSWORD="$password"
|
||||
|
||||
# Terminate existing connections
|
||||
echo "Terminating existing database connections..."
|
||||
psql -h "$host" -p "$port" -U "$user" -d "postgres" -c "
|
||||
SELECT pg_terminate_backend(pid)
|
||||
FROM pg_stat_activity
|
||||
WHERE datname = '$db'
|
||||
AND pid <> pg_backend_pid();" >/dev/null 2>&1
|
||||
|
||||
# Drop and recreate database
|
||||
echo "Dropping and recreating database..."
|
||||
psql -h "$host" -p "$port" -U "$user" -d "postgres" -c "DROP DATABASE IF EXISTS $db WITH (FORCE);"
|
||||
psql -h "$host" -p "$port" -U "$user" -d "postgres" -c "CREATE DATABASE $db;"
|
||||
|
||||
# Restore backup
|
||||
echo "Restoring backup..."
|
||||
psql -h "$host" -p "$port" -U "$user" -d "$db" < "$temp_file"
|
||||
|
||||
# Check if restore was successful
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Restore completed successfully!"
|
||||
else
|
||||
echo "Error: Restore failed!"
|
||||
# Clean up
|
||||
rm -rf "$temp_dir"
|
||||
unset PGPASSWORD
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Clean up
|
||||
rm -rf "$temp_dir"
|
||||
unset PGPASSWORD
|
||||
}
|
||||
|
||||
# Function to display usage
|
||||
usage() {
|
||||
echo "Usage: $0 [dev|prod] [backup_file|list]"
|
||||
echo " dev <backup_file> - restore development database from backup file"
|
||||
echo " prod <backup_file> - restore production database from backup file"
|
||||
echo " list - list available backup files"
|
||||
echo ""
|
||||
echo "Example:"
|
||||
echo " $0 dev ./db_backups/eveai_dev_backup_20250116_123456.sql.gz"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Main script logic
|
||||
main() {
|
||||
# Check for psql
|
||||
check_psql
|
||||
|
||||
# Check command line arguments
|
||||
if [ $# -lt 1 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
# Handle list command
|
||||
if [ "$1" = "list" ]; then
|
||||
list_backups
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check for required arguments
|
||||
if [ $# -ne 2 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
# Handle restore commands
|
||||
case "$1" in
|
||||
"dev"|"prod")
|
||||
restore_backup "$1" "$2"
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Run main function
|
||||
main "$@"
|
||||
@@ -3,7 +3,7 @@
|
||||
rm -f *repo.txt
|
||||
|
||||
# Define the list of components
|
||||
components=("docker" "eveai_api" "eveai_app" "eveai_beat" "eveai_chat" "eveai_chat_workers" "eveai_entitlements" "eveai_workers" "nginx" "full" "integrations")
|
||||
components=("docker" "eveai_api" "eveai_app" "eveai_app_startup" "eveai_beat" "eveai_chat" "eveai_chat_workers" "eveai_entitlements" "eveai_workers" "nginx" "full" "integrations")
|
||||
|
||||
# Get the current date and time in the format YYYY-MM-DD_HH-MM
|
||||
timestamp=$(date +"%Y-%m-%d_%H-%M")
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
from gevent import monkey
|
||||
monkey.patch_all()
|
||||
|
||||
from eveai_api import create_app
|
||||
|
||||
app = create_app()
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
from gevent import monkey
|
||||
monkey.patch_all()
|
||||
|
||||
from eveai_app import create_app
|
||||
|
||||
app = create_app()
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
from gevent import monkey
|
||||
monkey.patch_all()
|
||||
|
||||
from eveai_chat import create_app
|
||||
|
||||
app = create_app()
|
||||
|
||||
@@ -12,4 +12,4 @@ export FLASK_APP=${PROJECT_DIR}/scripts/run_eveai_app.py # Adjust the path to y
|
||||
chown -R appuser:appuser /app/logs
|
||||
|
||||
# Start Flask app
|
||||
gunicorn -w 4 -k gevent -b 0.0.0.0:5003 scripts.run_eveai_api:app
|
||||
gunicorn -w 1 -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -b 0.0.0.0:5001 --worker-connections 100 scripts.run_eveai_api:app
|
||||
|
||||
@@ -48,4 +48,5 @@ echo "Initializing initial tenant and user..."
|
||||
python ${PROJECT_DIR}/scripts/initialize_data.py # Adjust the path to your initialization script
|
||||
|
||||
# Start Flask app
|
||||
gunicorn -w 4 -k gevent -b 0.0.0.0:5001 scripts.run_eveai_app:app
|
||||
# gunicorn -w 1 -k gevent -b 0.0.0.0:5001 --worker-connections 100 scripts.run_eveai_app:app
|
||||
gunicorn -w 1 -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -b 0.0.0.0:5001 --worker-connections 100 scripts.run_eveai_app:app
|
||||
|
||||
@@ -13,4 +13,4 @@ chown -R appuser:appuser /app/logs
|
||||
echo "Starting EveAI Chat"
|
||||
|
||||
# Start Flask app
|
||||
gunicorn -w 4 -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -b 0.0.0.0:5002 scripts.run_eveai_chat:app
|
||||
gunicorn -w 1 -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -b 0.0.0.0:5001 --worker-connections 100 scripts.run_eveai_chat:app
|
||||
|
||||
Reference in New Issue
Block a user