docs: refactor workflow with script references and add mempool RPC endpoint
All checks were successful
Documentation Validation / validate-docs (push) Successful in 8s
Integration Tests / test-service-integration (push) Successful in 46s
Python Tests / test-python (push) Successful in 1m26s
Systemd Sync / sync-systemd (push) Successful in 3s
Security Scanning / security-scan (push) Successful in 1m36s

📋 Workflow Documentation:
• Replace inline service optimization with 15_service_optimization.sh reference
• Replace inline monitoring setup with 16_monitoring_setup.sh reference
• Replace inline security hardening with 17_security_hardening.sh reference
• Add production readiness validation with 18_production_readiness.sh
• Consolidate scaling and load balancing script references
• Remove duplicate integration
This commit is contained in:
aitbc1
2026-03-29 17:50:52 +02:00
parent 1e60fd010c
commit 00d607ce21
8 changed files with 824 additions and 128 deletions

View File

@@ -0,0 +1,57 @@
#!/bin/bash
# Service Optimization Script for AITBC Production
# This script optimizes systemd services for production environment
set -e # Exit on any error
echo "=== AITBC Service Optimization ==="
# Create service overrides for production (stored in git repo)
echo "1. Creating production service overrides..."
mkdir -p /opt/aitbc/systemd/aitbc-blockchain-node.service.d
cat > /opt/aitbc/systemd/aitbc-blockchain-node.service.d/production.conf << EOF
[Service]
Restart=always
RestartSec=10
LimitNOFILE=65536
Environment="PYTHONPATH=/opt/aitbc/apps/blockchain-node/src"
Environment="AITBC_ENV=production"
EOF
# Create symlink from systemd to git repo (ensures git always has current files)
echo "2. Creating symlink from systemd to git repo..."
ln -sf /opt/aitbc/systemd/aitbc-blockchain-node.service.d/production.conf /etc/systemd/system/aitbc-blockchain-node.service.d/production.conf
# Create RPC service optimization
echo "3. Creating RPC service optimization..."
mkdir -p /opt/aitbc/systemd/aitbc-blockchain-rpc.service.d
cat > /opt/aitbc/systemd/aitbc-blockchain-rpc.service.d/production.conf << EOF
[Service]
Restart=always
RestartSec=5
LimitNOFILE=65536
Environment="PYTHONPATH=/opt/aitbc/apps/blockchain-node/src"
Environment="AITBC_ENV=production"
Environment="UVICORN_WORKERS=4"
Environment="UVICORN_BACKLOG=2048"
EOF
ln -sf /opt/aitbc/systemd/aitbc-blockchain-rpc.service.d/production.conf /etc/systemd/system/aitbc-blockchain-rpc.service.d/production.conf
# Reload and restart services
echo "4. Reloading and restarting services..."
systemctl daemon-reload
systemctl restart aitbc-blockchain-node aitbc-blockchain-rpc
# Verify services are running
echo "5. Verifying service status..."
sleep 3
echo " Blockchain node: $(systemctl is-active aitbc-blockchain-node)"
echo " RPC service: $(systemctl is-active aitbc-blockchain-rpc)"
echo "✅ Service optimization completed successfully!"
echo " • Production overrides created in git repo"
echo " • Symlinks established for version control"
echo " • Services restarted and verified"

View File

@@ -0,0 +1,168 @@
#!/bin/bash
# Monitoring Setup Script for AITBC Production
# This script sets up comprehensive health monitoring and alerting
set -e # Exit on any error
echo "=== AITBC Monitoring Setup ==="
# Create health check script
echo "1. Creating health check script..."
cat > /opt/aitbc/scripts/health_check.sh << 'EOF'
#!/bin/bash
# AITBC Health Check Script
HEALTH_LOG="/var/log/aitbc/health_check.log"
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
# Create log directory if it doesn't exist
mkdir -p /var/log/aitbc
# Function to check service health
check_service() {
local service=$1
local status=$(systemctl is-active "$service" 2>/dev/null)
if [ "$status" = "active" ]; then
echo "[$TIMESTAMP] ✅ $service: $status" >> $HEALTH_LOG
return 0
else
echo "[$TIMESTAMP] ❌ $service: $status" >> $HEALTH_LOG
return 1
fi
}
# Function to check RPC endpoint
check_rpc() {
local url=$1
local response=$(curl -s --max-time 5 "$url" 2>/dev/null)
if [ $? -eq 0 ] && [ -n "$response" ]; then
echo "[$TIMESTAMP] ✅ RPC $url: Responsive" >> $HEALTH_LOG
return 0
else
echo "[$TIMESTAMP] ❌ RPC $url: Not responding" >> $HEALTH_LOG
return 1
fi
}
# Function to check blockchain sync
check_sync() {
local height=$(curl -s --max-time 5 http://localhost:8006/rpc/head | jq .height 2>/dev/null)
if [ -n "$height" ] && [ "$height" -gt 0 ]; then
echo "[$TIMESTAMP] ✅ Blockchain height: $height" >> $HEALTH_LOG
return 0
else
echo "[$TIMESTAMP] ❌ Blockchain sync: Failed" >> $HEALTH_LOG
return 1
fi
}
# Run health checks
FAILED_CHECKS=0
check_service "aitbc-blockchain-node" || ((FAILED_CHECKS++))
check_service "aitbc-blockchain-rpc" || ((FAILED_CHECKS++))
check_rpc "http://localhost:8006/rpc/info" || ((FAILED_CHECKS++))
check_sync || ((FAILED_CHECKS++))
# Check Redis if available
if systemctl is-active redis >/dev/null 2>&1; then
check_service "redis" || ((FAILED_CHECKS++))
fi
# Exit with appropriate status
if [ $FAILED_CHECKS -eq 0 ]; then
echo "[$TIMESTAMP] ✅ All health checks passed" >> $HEALTH_LOG
exit 0
else
echo "[$TIMESTAMP] ❌ $FAILED_CHECKS health checks failed" >> $HEALTH_LOG
exit 1
fi
EOF
chmod +x /opt/aitbc/scripts/health_check.sh
# Setup cron job for health checks
echo "2. Setting up health check cron job..."
(crontab -l 2>/dev/null; echo "*/5 * * * * /opt/aitbc/scripts/health_check.sh") | crontab -
# Create log rotation configuration
echo "3. Setting up log rotation..."
cat > /etc/logrotate.d/aitbc << EOF
/var/log/aitbc/*.log {
daily
missingok
rotate 30
compress
delaycompress
notifempty
create 644 root root
postrotate
systemctl reload aitbc-blockchain-rpc >/dev/null 2>&1 || true
endscript
}
EOF
# Create monitoring dashboard script
echo "4. Creating monitoring dashboard..."
cat > /opt/aitbc/scripts/monitoring_dashboard.sh << 'EOF'
#!/bin/bash
# AITBC Monitoring Dashboard
echo "=== AITBC Monitoring Dashboard ==="
echo "Timestamp: $(date)"
echo
# Service Status
echo "🔧 Service Status:"
systemctl is-active aitbc-blockchain-node aitbc-blockchain-rpc redis 2>/dev/null | while read service status; do
echo " $service: $status"
done
echo
# Blockchain Status
echo "⛓️ Blockchain Status:"
BLOCK_HEIGHT=$(curl -s http://localhost:8006/rpc/head | jq .height 2>/dev/null)
BLOCK_TIME=$(curl -s http://localhost:8006/rpc/info | jq .genesis_params.block_time_seconds 2>/dev/null)
echo " Height: $BLOCK_HEIGHT"
echo " Block Time: $BLOCK_TIME seconds"
echo
# Mining Status
echo "⛏️ Mining Status:"
MINING_STATUS=$(curl -s http://localhost:8006/rpc/mining/status | jq .active 2>/dev/null)
HASH_RATE=$(curl -s http://localhost:8006/rpc/mining/status | jq .hash_rate 2>/dev/null)
echo " Active: $MINING_STATUS"
echo " Hash Rate: $HASH_RATE H/s"
echo
# Marketplace Status
echo "🏪 Marketplace Status:"
MARKETPLACE_COUNT=$(curl -s http://localhost:8006/rpc/marketplace/listings | jq .total 2>/dev/null)
echo " Active Listings: $MARKETPLACE_COUNT"
echo
# AI Services Status
echo "🤖 AI Services Status:"
AI_STATS=$(curl -s http://localhost:8006/rpc/ai/stats | jq .total_jobs 2>/dev/null)
echo " Total Jobs: $AI_STATS"
echo
echo "=== End Dashboard ==="
EOF
chmod +x /opt/aitbc/scripts/monitoring_dashboard.sh
# Deploy to aitbc node
echo "5. Deploying monitoring to aitbc node..."
scp /opt/aitbc/scripts/health_check.sh aitbc:/opt/aitbc/scripts/
scp /opt/aitbc/scripts/monitoring_dashboard.sh aitbc:/opt/aitbc/scripts/
ssh aitbc 'chmod +x /opt/aitbc/scripts/health_check.sh /opt/aitbc/scripts/monitoring_dashboard.sh'
# Setup cron on aitbc
ssh aitbc '(crontab -l 2>/dev/null; echo "*/5 * * * * /opt/aitbc/scripts/health_check.sh") | crontab -'
echo "✅ Monitoring setup completed successfully!"
echo " • Health check script created and scheduled"
echo " • Log rotation configured"
echo " • Monitoring dashboard available"
echo " • Deployed to both nodes"

View File

@@ -0,0 +1,176 @@
#!/bin/bash
# Security Hardening Script for AITBC Production
# This script implements security best practices for the blockchain network
set -e # Exit on any error
echo "=== AITBC Security Hardening ==="
# Network Security
echo "1. Configuring network security..."
echo " ⚠️ Firewall configuration skipped as requested"
echo " ✅ Network security configuration completed"
# SSH Security
echo "2. Hardening SSH configuration..."
SSH_CONFIG="/etc/ssh/sshd_config"
# Backup original config
cp "$SSH_CONFIG" "$SSH_CONFIG.backup.$(date +%Y%m%d_%H%M%S)"
# SSH security settings - allow root for development
sed -i 's|#PermitRootLogin yes|PermitRootLogin yes|g' "$SSH_CONFIG"
sed -i 's|#PasswordAuthentication yes|PasswordAuthentication no|g' "$SSH_CONFIG"
sed -i 's|#PermitEmptyPasswords yes|PermitEmptyPasswords no|g' "$SSH_CONFIG"
sed -i 's|#X11Forwarding yes|X11Forwarding no|g' "$SSH_CONFIG"
sed -i 's|#MaxAuthTries 6|MaxAuthTries 3|g' "$SSH_CONFIG"
# Add additional security settings
cat >> "$SSH_CONFIG" << 'EOF'
# Additional security settings
ClientAliveInterval 300
ClientAliveCountMax 2
MaxStartups 10:30:60
AllowTcpForwarding no
AllowAgentForwarding no
EOF
# Restart SSH service
systemctl restart ssh
echo " ✅ SSH security configured (root access allowed for development)"
# Access Control
echo "3. Setting up access controls..."
echo " ⚠️ Sudo configuration skipped as requested"
echo " ✅ Basic access control setup completed"
# File Permissions
echo "4. Securing file permissions..."
# Secure keystore directory
chmod 700 /var/lib/aitbc/keystore
chown -R root:root /var/lib/aitbc/keystore
# Secure configuration files
chmod 600 /etc/aitbc/blockchain.env
chmod 600 /var/lib/aitbc/keystore/.password
# Secure systemd service files
chmod 644 /etc/systemd/system/aitbc-*.service
chmod 600 /etc/systemd/system/aitbc-*.service.d/*
echo " ✅ File permissions secured"
# Security Monitoring
echo "5. Setting up security monitoring..."
# Create security monitoring script
cat > /opt/aitbc/scripts/security_monitor.sh << 'EOF'
#!/bin/bash
# AITBC Security Monitoring Script
SECURITY_LOG="/var/log/aitbc/security.log"
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
# Create log directory
mkdir -p /var/log/aitbc
# Function to log security events
log_security() {
echo "[$TIMESTAMP] SECURITY: $1" >> $SECURITY_LOG
}
# Check for failed SSH attempts
FAILED_SSH=$(grep "authentication failure" /var/log/auth.log | grep "$(date '+%b %d')" | wc -l)
if [ "$FAILED_SSH" -gt 10 ]; then
log_security "High number of failed SSH attempts: $FAILED_SSH"
fi
# Check for unusual login activity
UNUSUAL_LOGINS=$(last -n 20 | grep -v "reboot" | grep -v "shutdown" | wc -l)
if [ "$UNUSUAL_LOGINS" -gt 0 ]; then
log_security "Recent login activity detected: $UNUSUAL_LOGINS logins"
fi
# Check service status
SERVICES_DOWN=$(systemctl list-units --state=failed | grep aitbc | wc -l)
if [ "$SERVICES_DOWN" -gt 0 ]; then
log_security "Failed AITBC services detected: $SERVICES_DOWN"
fi
# Check disk space
DISK_USAGE=$(df / | awk 'NR==2 {print $5}' | sed 's/%//')
if [ "$DISK_USAGE" -gt 80 ]; then
log_security "High disk usage: $DISK_USAGE%"
fi
echo "Security monitoring completed"
EOF
chmod +x /opt/aitbc/scripts/security_monitor.sh
# Add to cron for hourly security checks
(crontab -l 2>/dev/null; echo "0 * * * * /opt/aitbc/scripts/security_monitor.sh") | crontab -
# Deploy to aitbc node
echo "6. Deploying security configuration to aitbc node..."
scp /opt/aitbc/scripts/security_monitor.sh aitbc:/opt/aitbc/scripts/
ssh aitbc 'chmod +x /opt/aitbc/scripts/security_monitor.sh'
# Apply SSH hardening on aitbc (allow root for development)
ssh aitbc '
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup
sed -i "s/#PermitRootLogin yes/PermitRootLogin yes/g" /etc/ssh/sshd_config
sed -i "s/#PasswordAuthentication yes/PasswordAuthentication no/g" /etc/ssh/sshd_config
systemctl restart ssh
'
echo " ✅ Security monitoring deployed"
# Security Summary
echo "7. Generating security summary..."
cat > /opt/aitbc/security_summary.txt << EOF
AITBC Security Configuration Summary
Generated: $(date)
Network Security:
- Firewall configuration: Skipped as requested
- Network security: Basic configuration completed
SSH Hardening:
- Root login: Enabled (development mode)
- Password authentication disabled
- Max authentication attempts: 3
- Session timeout: 5 minutes
Access Control:
- User creation: Skipped as requested
- Sudo configuration: Skipped as requested
- Basic access control: Completed
Monitoring:
- Security monitoring script created
- Hourly security checks scheduled
- Logs stored in /var/log/aitbc/security.log
Recommendations:
1. Use SSH key authentication only
2. Monitor security logs regularly
3. Keep systems updated
4. Review access controls regularly
5. Implement intrusion detection system
6. Configure firewall according to your security policy
EOF
echo "✅ Security hardening completed successfully!"
echo " • SSH access configured (root allowed for development)"
echo " • File permissions secured"
echo " • Security monitoring active"
echo " • Configuration deployed to both nodes"
echo " • Firewall configuration skipped as requested"
echo " • Sudo configuration skipped as requested"
echo " • User creation skipped (using root)"
echo ""
echo "📋 Security summary saved to /opt/aitbc/security_summary.txt"

View File

@@ -0,0 +1,216 @@
#!/bin/bash
# Production Readiness Script for AITBC
# This script performs comprehensive production readiness validation
set -e # Exit on any error
echo "=== AITBC Production Readiness Check ==="
# Initialize counters
TOTAL_CHECKS=0
PASSED_CHECKS=0
FAILED_CHECKS=0
# Function to perform check
check() {
local description=$1
local command=$2
local expected=$3
TOTAL_CHECKS=$((TOTAL_CHECKS + 1))
echo -n " Checking $description... "
if eval "$command" | grep -q "$expected" 2>/dev/null; then
echo "✅ PASS"
PASSED_CHECKS=$((PASSED_CHECKS + 1))
return 0
else
echo "❌ FAIL"
FAILED_CHECKS=$((FAILED_CHECKS + 1))
return 1
fi
}
# Function to check service status
check_service() {
local service=$1
TOTAL_CHECKS=$((TOTAL_CHECKS + 1))
echo -n " Checking $service status... "
if systemctl is-active "$service" >/dev/null 2>&1; then
echo "✅ PASS"
PASSED_CHECKS=$((PASSED_CHECKS + 1))
return 0
else
echo "❌ FAIL"
FAILED_CHECKS=$((FAILED_CHECKS + 1))
return 1
fi
}
# Function to check endpoint
check_endpoint() {
local url=$1
local description=$2
TOTAL_CHECKS=$((TOTAL_CHECKS + 1))
echo -n " Checking $description... "
if curl -s --max-time 10 "$url" >/dev/null 2>&1; then
echo "✅ PASS"
PASSED_CHECKS=$((PASSED_CHECKS + 1))
return 0
else
echo "❌ FAIL"
FAILED_CHECKS=$((FAILED_CHECKS + 1))
return 1
fi
}
echo "1. Service Status Checks"
check_service "aitbc-blockchain-node"
check_service "aitbc-blockchain-rpc"
check_service "redis"
echo ""
echo "2. Network Connectivity Checks"
check_endpoint "http://localhost:8006/rpc/info" "RPC endpoint"
check_endpoint "http://localhost:8006/rpc/head" "Blockchain head"
check_endpoint "http://localhost:8006/rpc/mempool" "Mempool"
echo ""
echo "3. Blockchain Functionality Checks"
check "Blockchain height" "curl -s http://localhost:8006/rpc/head | jq .height" "^[0-9]"
check "Genesis block exists" "curl -s http://localhost:8006/rpc/blocks/0" "hash"
echo ""
echo "4. Security Configuration Checks"
check "Root login disabled" "grep '^PermitRootLogin no' /etc/ssh/sshd_config" "PermitRootLogin no"
check "Password auth disabled" "grep '^PasswordAuthentication no' /etc/ssh/sshd_config" "PasswordAuthentication no"
check "Firewall active" "ufw status | grep 'Status: active'" "Status: active"
echo ""
echo "5. File System Checks"
check "Keystore directory exists" "test -d /var/lib/aitbc/keystore" ""
check "Keystore permissions" "stat -c '%a' /var/lib/aitbc/keystore" "700"
check "Config file exists" "test -f /etc/aitbc/blockchain.env" ""
echo ""
echo "6. Cross-Node Connectivity Checks"
if ssh -o ConnectTimeout=5 aitbc 'echo "SSH_OK"' >/dev/null 2>&1; then
echo " SSH to aitbc: ✅ PASS"
PASSED_CHECKS=$((PASSED_CHECKS + 1))
else
echo " SSH to aitbc: ❌ FAIL"
FAILED_CHECKS=$((FAILED_CHECKS + 1))
fi
TOTAL_CHECKS=$((TOTAL_CHECKS + 1))
if ssh aitbc 'curl -s http://localhost:8006/rpc/info' >/dev/null 2>&1; then
echo " Remote RPC: ✅ PASS"
PASSED_CHECKS=$((PASSED_CHECKS + 1))
else
echo " Remote RPC: ❌ FAIL"
FAILED_CHECKS=$((FAILED_CHECKS + 1))
fi
TOTAL_CHECKS=$((TOTAL_CHECKS + 1))
echo ""
echo "7. Performance Checks"
MEMORY_USAGE=$(free | awk 'NR==2{printf "%.1f", $3*100/$2}')
if (( $(echo "$MEMORY_USAGE < 80" | bc -l) )); then
echo " Memory usage ($MEMORY_USAGE%): ✅ PASS"
PASSED_CHECKS=$((PASSED_CHECKS + 1))
else
echo " Memory usage ($MEMORY_USAGE%): ❌ FAIL"
FAILED_CHECKS=$((FAILED_CHECKS + 1))
fi
TOTAL_CHECKS=$((TOTAL_CHECKS + 1))
DISK_USAGE=$(df / | awk 'NR==2 {print $5}' | sed 's/%//')
if [ "$DISK_USAGE" -lt 80 ]; then
echo " Disk usage ($DISK_USAGE%): ✅ PASS"
PASSED_CHECKS=$((PASSED_CHECKS + 1))
else
echo " Disk usage ($DISK_USAGE%): ❌ FAIL"
FAILED_CHECKS=$((FAILED_CHECKS + 1))
fi
TOTAL_CHECKS=$((TOTAL_CHECKS + 1))
echo ""
echo "8. Integration Tests"
if /opt/aitbc/tests/integration_test.sh >/dev/null 2>&1; then
echo " Integration tests: ✅ PASS"
PASSED_CHECKS=$((PASSED_CHECKS + 1))
else
echo " Integration tests: ❌ FAIL"
FAILED_CHECKS=$((FAILED_CHECKS + 1))
fi
TOTAL_CHECKS=$((TOTAL_CHECKS + 1))
echo ""
echo "=== Production Readiness Results ==="
echo "Total Checks: $TOTAL_CHECKS"
echo "Passed: $PASSED_CHECKS"
echo "Failed: $FAILED_CHECKS"
echo "Success Rate: $(( PASSED_CHECKS * 100 / TOTAL_CHECKS ))%"
# Generate report
cat > /opt/aitbc/production_readiness_report.txt << EOF
AITBC Production Readiness Report
Generated: $(date)
SUMMARY:
Total Checks: $TOTAL_CHECKS
Passed: $PASSED_CHECKS
Failed: $FAILED_CHECKS
Success Rate: $(( PASSED_CHECKS * 100 / TOTAL_CHECKS ))%
RECOMMENDATIONS:
EOF
if [ $FAILED_CHECKS -eq 0 ]; then
echo "✅ PRODUCTION READY" >> /opt/aitbc/production_readiness_report.txt
echo " All checks passed. System is ready for production deployment." >> /opt/aitbc/production_readiness_report.txt
echo ""
echo "🎉 PRODUCTION READY!"
echo " All $TOTAL_CHECKS checks passed successfully"
echo " System is ready for production deployment"
else
echo "⚠️ NOT PRODUCTION READY" >> /opt/aitbc/production_readiness_report.txt
echo " $FAILED_CHECKS checks failed. Address issues before production deployment." >> /opt/aitbc/production_readiness_report.txt
echo ""
echo "⚠️ NOT PRODUCTION READY"
echo " $FAILED_CHECKS checks failed"
echo " Address issues before production deployment"
echo ""
echo "📋 Detailed report saved to /opt/aitbc/production_readiness_report.txt"
fi
echo ""
echo "9. Generating performance baseline..."
cat > /opt/aitbc/performance_baseline.txt << EOF
AITBC Performance Baseline
Generated: $(date)
SYSTEM METRICS:
- CPU Load: $(uptime | awk -F'load average:' '{print $2}')
- Memory Usage: $MEMORY_USAGE%
- Disk Usage: $DISK_USAGE%
- Uptime: $(uptime -p)
BLOCKCHAIN METRICS:
- Current Height: $(curl -s http://localhost:8006/rpc/head | jq .height 2>/dev/null || echo "Unknown")
- Block Time: $(curl -s http://localhost:8006/rpc/info | jq .genesis_params.block_time_seconds 2>/dev/null || echo "Unknown")s
- Mining Status: $(curl -s http://localhost:8006/rpc/mining/status | jq .active 2>/dev/null || echo "Unknown")
NETWORK METRICS:
- RPC Response Time: $(curl -o /dev/null -s -w '%{time_total}' http://localhost:8006/rpc/info)s
- SSH Connectivity: $(ssh -o ConnectTimeout=5 aitbc 'echo "OK"' 2>/dev/null || echo "Failed")
Use this baseline for future performance monitoring.
EOF
echo " ✅ Performance baseline generated"
echo ""
echo "=== Production Readiness Check Complete ==="