refactor: remove redundant startup script and use systemd services directly
SystemD Simplification - Complete: ✅ REDUNDANT STARTUP SCRIPT REMOVED: Eliminated unnecessary manual startup script - setup.sh: Removed create_startup_script function entirely - Reason: SystemD services are used directly, making manual startup script redundant - Impact: Simplified setup process and eliminated unnecessary file creation ✅ FUNCTIONS REMOVED: 🗑️ create_startup_script: No longer needed with systemd services 🗑️ /opt/aitbc/start-services.sh: File is no longer created 🗑️ aitbc-startup.service: No longer needed for auto-start ✅ UPDATED WORKFLOW: 📋 Main function: Removed create_startup_script call 📋 Auto-start: Services enabled directly with systemctl enable 📋 Management: Updated commands to use systemctl 📋 Logging: Updated to use journalctl instead of tail ✅ SIMPLIFIED AUTO-START: 🔧 Before: Created aitbc-startup.service that called start-services.sh 🔧 After: Direct systemctl enable for each service 🎯 Benefit: Cleaner, more direct systemd integration 📁 Services: aitbc-wallet, aitbc-coordinator-api, aitbc-exchange-api, aitbc-blockchain-rpc ✅ UPDATED MANAGEMENT COMMANDS: 📋 Before: /opt/aitbc/start-services.sh 📋 After: systemctl restart aitbc-wallet aitbc-coordinator-api aitbc-exchange-api 📋 Before: tail -f /var/lib/aitbc/logs/aitbc-*.log 📋 After: journalctl -u aitbc-wallet -f 🎯 Purpose: Modern systemd-based service management ✅ CLEANER SETUP PROCESS: 1. Install systemd services (symbolic links) 2. Create health check script 3. Start services directly with systemctl 4. Enable services for auto-start 5. Complete setup with systemd-managed services ✅ BENEFITS ACHIEVED: ✅ Simplicity: No unnecessary intermediate scripts ✅ Direct Management: Services managed directly by systemd ✅ Modern Practice: Uses standard systemd service management ✅ Less Complexity: Fewer files and functions to maintain ✅ Better Integration: Full systemd ecosystem utilization ✅ CONSISTENT SYSTEMD APPROACH: 🔧 Service Installation: Symbolic links to /etc/systemd/system/ 🔧 Service Management: systemctl start/stop/restart/enable 🔧 Service Monitoring: systemctl status and journalctl logs 🔧 Service Configuration: Service files in /opt/aitbc/systemd/ RESULT: Successfully removed redundant startup script and simplified the setup process to use systemd services directly, providing a cleaner, more modern, and maintainable service management approach.
This commit is contained in:
71
setup.sh
71
setup.sh
@@ -206,49 +206,6 @@ install_services() {
|
||||
success "Systemd services installed"
|
||||
}
|
||||
|
||||
# Create startup script
|
||||
create_startup_script() {
|
||||
log "Creating startup script..."
|
||||
|
||||
cat > /opt/aitbc/start-services.sh << 'EOF'
|
||||
#!/bin/bash
|
||||
|
||||
# AITBC Services Startup Script
|
||||
|
||||
log() {
|
||||
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1"
|
||||
}
|
||||
|
||||
log "Starting AITBC services using systemd..."
|
||||
|
||||
# Start services using systemd
|
||||
log "Starting wallet service..."
|
||||
systemctl start aitbc-wallet.service || log "Warning: Failed to start wallet service"
|
||||
|
||||
log "Starting coordinator API service..."
|
||||
systemctl start aitbc-coordinator-api.service || log "Warning: Failed to start coordinator API service"
|
||||
|
||||
log "Starting exchange API service..."
|
||||
systemctl start aitbc-exchange-api.service || log "Warning: Failed to start exchange API service"
|
||||
|
||||
log "Starting blockchain RPC service..."
|
||||
systemctl start aitbc-blockchain-rpc.service || log "Warning: Failed to start blockchain RPC service"
|
||||
|
||||
# Enable services for auto-start
|
||||
log "Enabling services for auto-start..."
|
||||
systemctl enable aitbc-wallet.service
|
||||
systemctl enable aitbc-coordinator-api.service
|
||||
systemctl enable aitbc-exchange-api.service
|
||||
systemctl enable aitbc-blockchain-rpc.service
|
||||
|
||||
log "All services started and enabled"
|
||||
EOF
|
||||
|
||||
chmod +x /opt/aitbc/start-services.sh
|
||||
|
||||
success "Startup script created"
|
||||
}
|
||||
|
||||
# Create health check script
|
||||
create_health_check() {
|
||||
log "Creating health check script..."
|
||||
@@ -334,24 +291,11 @@ start_services() {
|
||||
setup_autostart() {
|
||||
log "Setting up auto-start..."
|
||||
|
||||
# Create systemd service for startup script
|
||||
cat > /etc/systemd/system/aitbc-startup.service << EOF
|
||||
[Unit]
|
||||
Description=AITBC Services Startup
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/opt/aitbc/start-services.sh
|
||||
RemainAfterExit=yes
|
||||
User=root
|
||||
Group=root
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
systemctl enable aitbc-startup.service
|
||||
# Enable services for auto-start on boot
|
||||
systemctl enable aitbc-wallet.service
|
||||
systemctl enable aitbc-coordinator-api.service
|
||||
systemctl enable aitbc-exchange-api.service
|
||||
systemctl enable aitbc-blockchain-rpc.service
|
||||
|
||||
success "Auto-start configured"
|
||||
}
|
||||
@@ -366,7 +310,6 @@ main() {
|
||||
setup_runtime_directories
|
||||
setup_venvs
|
||||
install_services
|
||||
create_startup_script
|
||||
create_health_check
|
||||
start_services
|
||||
setup_autostart
|
||||
@@ -386,8 +329,8 @@ main() {
|
||||
echo ""
|
||||
echo "Management Commands:"
|
||||
echo " Health check: /opt/aitbc/health-check.sh"
|
||||
echo " Restart services: /opt/aitbc/start-services.sh"
|
||||
echo " View logs: tail -f /var/lib/aitbc/logs/aitbc-*.log"
|
||||
echo " Restart services: systemctl restart aitbc-wallet aitbc-coordinator-api aitbc-exchange-api"
|
||||
echo " View logs: journalctl -u aitbc-wallet -f"
|
||||
}
|
||||
|
||||
# Run main function
|
||||
|
||||
Reference in New Issue
Block a user