Consolidate service scripts into apps directories
- Move blockchain scripts to apps/blockchain-node/scripts/ - Move marketplace scripts to apps/marketplace/scripts/ - Move agent daemon to apps/agent-coordinator/scripts/ - Move monitor to apps/monitor/ - Update systemd service files to point to new locations - Update internal path references in moved scripts - Remove empty /opt/aitbc/services directory
This commit is contained in:
52
apps/blockchain-node/scripts/blockchain_http_launcher.py
Executable file
52
apps/blockchain-node/scripts/blockchain_http_launcher.py
Executable file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Blockchain HTTP Launcher for AITBC Production
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import logging
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def main():
|
||||
"""Main blockchain HTTP launcher function"""
|
||||
logger.info("Starting AITBC Blockchain HTTP Launcher")
|
||||
|
||||
try:
|
||||
# Launch blockchain HTTP service
|
||||
logger.info("Launching blockchain HTTP API")
|
||||
subprocess.run([
|
||||
'/opt/aitbc/venv/bin/python',
|
||||
'-m', 'uvicorn',
|
||||
'aitbc_chain.app:app',
|
||||
'--host', '0.0.0.0',
|
||||
'--port', '8005'
|
||||
], check=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
logger.error(f"Blockchain HTTP service failed with exit code {e.returncode}: {e}")
|
||||
# Fallback
|
||||
import time
|
||||
while True:
|
||||
logger.info("Blockchain HTTP service heartbeat (fallback mode)")
|
||||
time.sleep(30)
|
||||
except (FileNotFoundError, PermissionError) as e:
|
||||
logger.error(f"Cannot launch blockchain HTTP service: {type(e).__name__}: {e}")
|
||||
# Fallback
|
||||
import time
|
||||
while True:
|
||||
logger.info("Blockchain HTTP service heartbeat (fallback mode)")
|
||||
time.sleep(30)
|
||||
except Exception as e:
|
||||
logger.error(f"Unexpected error launching blockchain HTTP: {type(e).__name__}: {e}")
|
||||
# Fallback
|
||||
import time
|
||||
while True:
|
||||
logger.info("Blockchain HTTP service heartbeat (fallback mode)")
|
||||
time.sleep(30)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
139
apps/blockchain-node/scripts/blockchain_simple.py
Executable file
139
apps/blockchain-node/scripts/blockchain_simple.py
Executable file
@@ -0,0 +1,139 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Blockchain Node Service for AITBC Production
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
# Add the blockchain app to Python path
|
||||
sys.path.insert(0, '/opt/aitbc/apps/blockchain-node/src')
|
||||
sys.path.insert(0, '/opt/aitbc/apps/blockchain-node/scripts')
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
||||
)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def main():
|
||||
"""Main blockchain service function"""
|
||||
logger.info("Starting AITBC Blockchain Node Service")
|
||||
|
||||
try:
|
||||
# Set environment variables
|
||||
os.environ.setdefault('PYTHONPATH', '/opt/aitbc/apps/blockchain-node/src')
|
||||
os.environ.setdefault('BLOCKCHAIN_DATA_DIR', '/var/lib/aitbc/data/blockchain')
|
||||
os.environ.setdefault('BLOCKCHAIN_CONFIG_DIR', '/etc/aitbc')
|
||||
os.environ.setdefault('BLOCKCHAIN_LOG_DIR', '/var/log/aitbc/production/blockchain')
|
||||
|
||||
# Try to import and run the actual blockchain node
|
||||
logger.info("Attempting to start blockchain node...")
|
||||
|
||||
# Check if we can import the blockchain app
|
||||
try:
|
||||
from aitbc_chain.app import app
|
||||
logger.info("Successfully imported blockchain app")
|
||||
|
||||
# Run the blockchain FastAPI app
|
||||
import uvicorn
|
||||
logger.info("Starting blockchain FastAPI app on port 8545")
|
||||
uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("BLOCKCHAIN_PORT", 8545)))
|
||||
|
||||
except ImportError as e:
|
||||
logger.error(f"Failed to import blockchain app: {e}")
|
||||
|
||||
# Try to run the main blockchain function
|
||||
try:
|
||||
from aitbc_chain.main import main as blockchain_main
|
||||
logger.info("Successfully imported blockchain main")
|
||||
blockchain_main()
|
||||
|
||||
except ImportError as e2:
|
||||
logger.error(f"Failed to import blockchain main: {e2}")
|
||||
logger.info("Starting blockchain node with basic functionality")
|
||||
basic_blockchain_node()
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error starting blockchain service: {e}")
|
||||
logger.info("Starting fallback blockchain node")
|
||||
basic_blockchain_node()
|
||||
|
||||
def basic_blockchain_node():
|
||||
"""Basic blockchain node functionality"""
|
||||
logger.info("Starting basic blockchain node")
|
||||
|
||||
try:
|
||||
# Create a simple FastAPI app for blockchain node
|
||||
from fastapi import FastAPI
|
||||
import uvicorn
|
||||
import time
|
||||
import threading
|
||||
|
||||
app = FastAPI(title="AITBC Blockchain Node")
|
||||
|
||||
# Blockchain state
|
||||
blockchain_state = {
|
||||
"status": "running",
|
||||
"block_height": 0,
|
||||
"last_block": None,
|
||||
"peers": [],
|
||||
"start_time": time.time()
|
||||
}
|
||||
|
||||
@app.get("/health")
|
||||
async def health():
|
||||
return {
|
||||
"status": "healthy",
|
||||
"service": "blockchain-node",
|
||||
"block_height": blockchain_state["block_height"],
|
||||
"uptime": time.time() - blockchain_state["start_time"]
|
||||
}
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
return {
|
||||
"service": "blockchain-node",
|
||||
"status": "running",
|
||||
"endpoints": ["/health", "/", "/blocks", "/status"]
|
||||
}
|
||||
|
||||
@app.get("/blocks")
|
||||
async def get_blocks():
|
||||
return {
|
||||
"blocks": [],
|
||||
"count": 0,
|
||||
"latest_height": blockchain_state["block_height"]
|
||||
}
|
||||
|
||||
@app.get("/status")
|
||||
async def get_status():
|
||||
return blockchain_state
|
||||
|
||||
# Simulate blockchain activity
|
||||
def blockchain_activity():
|
||||
while True:
|
||||
time.sleep(30) # Simulate block generation every 30 seconds
|
||||
blockchain_state["block_height"] += 1
|
||||
blockchain_state["last_block"] = f"block_{blockchain_state['block_height']}"
|
||||
logger.info(f"Generated block {blockchain_state['block_height']}")
|
||||
|
||||
# Start blockchain activity in background
|
||||
activity_thread = threading.Thread(target=blockchain_activity, daemon=True)
|
||||
activity_thread.start()
|
||||
|
||||
logger.info("Starting basic blockchain API on port 8545")
|
||||
uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("BLOCKCHAIN_PORT", 8545)))
|
||||
|
||||
except ImportError:
|
||||
# Fallback to simple heartbeat
|
||||
logger.info("FastAPI not available, using simple blockchain node")
|
||||
while True:
|
||||
logger.info("Blockchain node heartbeat - active")
|
||||
time.sleep(30)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user