diff --git a/cli/aitbc_cli.py b/cli/aitbc_cli.py index e68b0e73..9163b935 100755 --- a/cli/aitbc_cli.py +++ b/cli/aitbc_cli.py @@ -700,17 +700,17 @@ def get_balance(wallet_name: str, keystore_dir: Path = DEFAULT_KEYSTORE_DIR, address = wallet_data['address'] # Get balance from RPC - response = requests.get(f"{rpc_url}/rpc/getBalance/{address}") - if response.status_code == 200: - balance_data = response.json() + try: + http_client = AITBCHTTPClient(base_url=rpc_url, timeout=30) + balance_data = http_client.get(f"/rpc/getBalance/{address}") return { "address": address, "balance": balance_data.get("balance", 0), "nonce": balance_data.get("nonce", 0), "wallet_name": wallet_name } - else: - print(f"Error getting balance: {response.text}") + except NetworkError as e: + print(f"Error getting balance: {e}") return None except Exception as e: print(f"Error: {e}") @@ -732,16 +732,16 @@ def get_transactions(wallet_name: str, keystore_dir: Path = DEFAULT_KEYSTORE_DIR address = wallet_data['address'] # Get transactions from RPC - response = requests.get(f"{rpc_url}/rpc/transactions?address={address}&limit={limit}") - if response.status_code == 200: - tx_data = response.json() + try: + http_client = AITBCHTTPClient(base_url=rpc_url, timeout=30) + tx_data = http_client.get(f"/rpc/transactions?address={address}&limit={limit}") return tx_data.get("transactions", []) - else: - print(f"Error getting transactions: {response.text}") + except NetworkError as e: + print(f"Error getting transactions: {e}") + return [] + except Exception as e: + print(f"Error: {e}") return [] - except Exception as e: - print(f"Error: {e}") - return [] def get_balance(wallet_name: str, rpc_url: str = DEFAULT_RPC_URL) -> Optional[Dict]: @@ -758,17 +758,20 @@ def get_balance(wallet_name: str, rpc_url: str = DEFAULT_RPC_URL) -> Optional[Di address = wallet_data["address"] # Get account info from RPC - response = requests.get(f"{rpc_url}/rpc/account/{address}?chain_id=ait-testnet") - if response.status_code == 200: - account_info = response.json() + try: + http_client = AITBCHTTPClient(base_url=rpc_url, timeout=30) + account_info = http_client.get(f"/rpc/account/{address}?chain_id=ait-testnet") return { "wallet_name": wallet_name, "address": address, "balance": account_info["balance"], "nonce": account_info["nonce"] } - else: - print(f"Error getting balance: {response.text}") + except NetworkError as e: + print(f"Error getting balance: {e}") + return None + except Exception as e: + print(f"Error: {e}") return None except Exception as e: print(f"Error: {e}") @@ -780,22 +783,22 @@ def get_chain_info(rpc_url: str = DEFAULT_RPC_URL) -> Optional[Dict]: try: result = {} # Get chain metadata from health endpoint - health_response = requests.get(f"{rpc_url}/health") - if health_response.status_code == 200: - health = health_response.json() - chains = health.get('supported_chains', []) - result['chain_id'] = chains[0] if chains else 'ait-mainnet' - result['supported_chains'] = ', '.join(chains) if chains else 'ait-mainnet' - result['proposer_id'] = health.get('proposer_id', '') + http_client = AITBCHTTPClient(base_url=rpc_url, timeout=30) + health = http_client.get("/health") + chains = health.get('supported_chains', []) + result['chain_id'] = chains[0] if chains else 'ait-mainnet' + result['supported_chains'] = ', '.join(chains) if chains else 'ait-mainnet' + result['proposer_id'] = health.get('proposer_id', '') # Get head block for height - head_response = requests.get(f"{rpc_url}/rpc/head") - if head_response.status_code == 200: - head = head_response.json() - result['height'] = head.get('height', 0) - result['hash'] = head.get('hash', "") - result['timestamp'] = head.get('timestamp', 'N/A') - result['tx_count'] = head.get('tx_count', 0) + head = http_client.get("/rpc/head") + result['height'] = head.get('height', 0) + result['hash'] = head.get('hash', "") + result['timestamp'] = head.get('timestamp', 'N/A') + result['tx_count'] = head.get('tx_count', 0) return result if result else None + except NetworkError as e: + print(f"Error: {e}") + return None except Exception as e: print(f"Error: {e}") return None @@ -1413,22 +1416,22 @@ def get_chain_info(rpc_url: str = DEFAULT_RPC_URL) -> Optional[Dict]: try: result = {} # Get chain metadata from health endpoint - health_response = requests.get(f"{rpc_url}/health") - if health_response.status_code == 200: - health = health_response.json() - chains = health.get('supported_chains', []) - result['chain_id'] = chains[0] if chains else 'ait-mainnet' - result['supported_chains'] = ', '.join(chains) if chains else 'ait-mainnet' - result['proposer_id'] = health.get('proposer_id', '') + http_client = AITBCHTTPClient(base_url=rpc_url, timeout=30) + health = http_client.get("/health") + chains = health.get('supported_chains', []) + result['chain_id'] = chains[0] if chains else 'ait-mainnet' + result['supported_chains'] = ', '.join(chains) if chains else 'ait-mainnet' + result['proposer_id'] = health.get('proposer_id', '') # Get head block for height - head_response = requests.get(f"{rpc_url}/rpc/head") - if head_response.status_code == 200: - head = head_response.json() - result['height'] = head.get('height', 0) - result['hash'] = head.get('hash', "") - result['timestamp'] = head.get('timestamp', 'N/A') - result['tx_count'] = head.get('tx_count', 0) + head = http_client.get("/rpc/head") + result['height'] = head.get('height', 0) + result['hash'] = head.get('hash', "") + result['timestamp'] = head.get('timestamp', 'N/A') + result['tx_count'] = head.get('tx_count', 0) return result if result else None + except NetworkError as e: + print(f"Error: {e}") + return None except Exception as e: print(f"Error: {e}") return None diff --git a/scripts/wrappers/aitbc-agent-coordinator-wrapper.py b/scripts/wrappers/aitbc-agent-coordinator-wrapper.py new file mode 100755 index 00000000..83ef3d11 --- /dev/null +++ b/scripts/wrappers/aitbc-agent-coordinator-wrapper.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +""" +Wrapper script for aitbc-agent-coordinator service +Uses centralized aitbc utilities for path configuration +""" + +import sys +import os +from pathlib import Path + +# Add aitbc to path +sys.path.insert(0, str(Path("/opt/aitbc/aitbc"))) + +from aitbc import ENV_FILE, NODE_ENV_FILE, REPO_DIR, DATA_DIR, LOG_DIR + +# Set up environment using aitbc constants +os.environ["AITBC_ENV_FILE"] = str(ENV_FILE) +os.environ["AITBC_NODE_ENV_FILE"] = str(NODE_ENV_FILE) +os.environ["PYTHONPATH"] = f"{REPO_DIR}/apps/agent-coordinator/src" +os.environ["DATA_DIR"] = str(DATA_DIR) +os.environ["LOG_DIR"] = str(LOG_DIR) + +# Create required directories +from aitbc.paths import ensure_dir +ensure_dir(DATA_DIR / "agent-coordinator") +ensure_dir(LOG_DIR / "agent-coordinator") + +# Execute the actual service +exec_cmd = [ + "/opt/aitbc/venv/bin/python", + "-m", + "uvicorn", + "src.app.main:app", + "--host", + "0.0.0.0", + "--port", + "9001" +] +os.execvp(exec_cmd[0], exec_cmd) diff --git a/scripts/wrappers/aitbc-agent-daemon-wrapper.py b/scripts/wrappers/aitbc-agent-daemon-wrapper.py new file mode 100755 index 00000000..53492035 --- /dev/null +++ b/scripts/wrappers/aitbc-agent-daemon-wrapper.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +""" +Wrapper script for aitbc-agent-daemon service +Uses centralized aitbc utilities for path configuration +""" + +import sys +import os +from pathlib import Path + +# Add aitbc to path +sys.path.insert(0, str(Path("/opt/aitbc"))) +sys.path.insert(0, str(Path("/opt/aitbc/aitbc"))) + +from aitbc import ENV_FILE, NODE_ENV_FILE, REPO_DIR, DATA_DIR, LOG_DIR, KEYSTORE_DIR + +# Set up environment using aitbc constants +os.environ["AITBC_ENV_FILE"] = str(ENV_FILE) +os.environ["AITBC_NODE_ENV_FILE"] = str(NODE_ENV_FILE) +os.environ["PYTHONPATH"] = f"{REPO_DIR}/apps/agent-coordinator/scripts:{REPO_DIR}" +os.environ["DATA_DIR"] = str(DATA_DIR) +os.environ["LOG_DIR"] = str(LOG_DIR) + +# Execute the actual service +exec_cmd = [ + "/opt/aitbc/venv/bin/python", + f"{REPO_DIR}/apps/agent-coordinator/scripts/agent_daemon.py", + "--wallet", "temp-agent", + "--address", "ait1d18e286fc0c12888aca94732b5507c8787af71a5", + "--password-file", str(KEYSTORE_DIR / ".agent_daemon_password"), + "--keystore-dir", str(KEYSTORE_DIR), + "--db-path", str(DATA_DIR / "chain.db"), + "--rpc-url", "http://localhost:8006", + "--poll-interval", "2", + "--reply-message", "pong", + "--trigger-message", "ping" +] +os.execvp(exec_cmd[0], exec_cmd) diff --git a/scripts/wrappers/aitbc-agent-registry-wrapper.py b/scripts/wrappers/aitbc-agent-registry-wrapper.py new file mode 100755 index 00000000..a6116335 --- /dev/null +++ b/scripts/wrappers/aitbc-agent-registry-wrapper.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +""" +Wrapper script for aitbc-agent-registry service +Uses centralized aitbc utilities for path configuration +""" + +import sys +import os +from pathlib import Path + +# Add aitbc to path +sys.path.insert(0, str(Path("/opt/aitbc"))) +sys.path.insert(0, str(Path("/opt/aitbc/aitbc"))) + +from aitbc import ENV_FILE, NODE_ENV_FILE, REPO_DIR, DATA_DIR, LOG_DIR + +# Set up environment using aitbc constants +os.environ["AITBC_ENV_FILE"] = str(ENV_FILE) +os.environ["AITBC_NODE_ENV_FILE"] = str(NODE_ENV_FILE) +os.environ["PYTHONPATH"] = f"{REPO_DIR}" +os.environ["DATA_DIR"] = str(DATA_DIR) +os.environ["LOG_DIR"] = str(LOG_DIR) + +# Execute the actual service +exec_cmd = [ + "/opt/aitbc/venv/bin/python", + f"{REPO_DIR}/apps/agent-services/agent-registry/src/app.py" +] +os.execvp(exec_cmd[0], exec_cmd) diff --git a/scripts/wrappers/aitbc-blockchain-event-bridge-wrapper.py b/scripts/wrappers/aitbc-blockchain-event-bridge-wrapper.py new file mode 100755 index 00000000..b7372286 --- /dev/null +++ b/scripts/wrappers/aitbc-blockchain-event-bridge-wrapper.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +""" +Wrapper script for aitbc-blockchain-event-bridge service +Uses centralized aitbc utilities for path configuration +""" + +import sys +import os +from pathlib import Path + +# Add aitbc to path +sys.path.insert(0, str(Path("/opt/aitbc"))) +sys.path.insert(0, str(Path("/opt/aitbc/aitbc"))) + +from aitbc import ENV_FILE, NODE_ENV_FILE, REPO_DIR, DATA_DIR, LOG_DIR + +# Set up environment using aitbc constants +os.environ["AITBC_ENV_FILE"] = str(ENV_FILE) +os.environ["AITBC_NODE_ENV_FILE"] = str(NODE_ENV_FILE) +os.environ["PYTHONPATH"] = f"{REPO_DIR}/apps/blockchain-event-bridge/src:{REPO_DIR}" +os.environ["DATA_DIR"] = str(DATA_DIR) +os.environ["LOG_DIR"] = str(LOG_DIR) + +# Execute the actual service +exec_cmd = [ + "/opt/aitbc/venv/bin/python", + "-m", + "app.main" +] +os.execvp(exec_cmd[0], exec_cmd) diff --git a/scripts/wrappers/aitbc-blockchain-node-wrapper.py b/scripts/wrappers/aitbc-blockchain-node-wrapper.py new file mode 100755 index 00000000..cd1054ce --- /dev/null +++ b/scripts/wrappers/aitbc-blockchain-node-wrapper.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +""" +Wrapper script for aitbc-blockchain-node service +Uses centralized aitbc utilities for path configuration +""" + +import sys +import os +from pathlib import Path + +# Add aitbc to path +sys.path.insert(0, str(Path("/opt/aitbc"))) +sys.path.insert(0, str(Path("/opt/aitbc/aitbc"))) + +from aitbc import ENV_FILE, NODE_ENV_FILE, REPO_DIR, DATA_DIR, LOG_DIR + +# Set up environment using aitbc constants +os.environ["AITBC_ENV_FILE"] = str(ENV_FILE) +os.environ["AITBC_NODE_ENV_FILE"] = str(NODE_ENV_FILE) +os.environ["PYTHONPATH"] = f"{REPO_DIR}/apps/blockchain-node/src" +os.environ["DATA_DIR"] = str(DATA_DIR) +os.environ["LOG_DIR"] = str(LOG_DIR) + +# Execute the actual service +exec_cmd = [ + "/opt/aitbc/venv/bin/python", + "-m", + "aitbc_chain.combined_main" +] +os.execvp(exec_cmd[0], exec_cmd) diff --git a/scripts/wrappers/aitbc-blockchain-p2p-wrapper.py b/scripts/wrappers/aitbc-blockchain-p2p-wrapper.py new file mode 100755 index 00000000..040988f2 --- /dev/null +++ b/scripts/wrappers/aitbc-blockchain-p2p-wrapper.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +""" +Wrapper script for aitbc-blockchain-p2p service +Uses centralized aitbc utilities for path configuration +""" + +import sys +import os +from pathlib import Path + +# Add aitbc to path +sys.path.insert(0, str(Path("/opt/aitbc"))) +sys.path.insert(0, str(Path("/opt/aitbc/aitbc"))) + +from aitbc import ENV_FILE, NODE_ENV_FILE, REPO_DIR, DATA_DIR, LOG_DIR + +# Set up environment using aitbc constants +os.environ["AITBC_ENV_FILE"] = str(ENV_FILE) +os.environ["AITBC_NODE_ENV_FILE"] = str(NODE_ENV_FILE) +os.environ["PYTHONPATH"] = f"{REPO_DIR}/apps/blockchain-node/src:{REPO_DIR}/apps/blockchain-node/scripts" +os.environ["DATA_DIR"] = str(DATA_DIR) +os.environ["LOG_DIR"] = str(LOG_DIR) + +# Get P2P configuration from environment +p2p_host = os.getenv("p2p_bind_host", "0.0.0.0") +p2p_port = os.getenv("p2p_bind_port", "7000") +p2p_peers = os.getenv("p2p_peers", "") +p2p_node_id = os.getenv("p2p_node_id", "") + +# Execute the actual service +exec_cmd = [ + "/opt/aitbc/venv/bin/python", + "-m", + "aitbc_chain.p2p_network", + "--host", p2p_host, + "--port", p2p_port, + "--peers", p2p_peers, + "--node-id", p2p_node_id +] +os.execvp(exec_cmd[0], exec_cmd) diff --git a/scripts/wrappers/aitbc-blockchain-rpc-wrapper.py b/scripts/wrappers/aitbc-blockchain-rpc-wrapper.py new file mode 100755 index 00000000..d8df2e40 --- /dev/null +++ b/scripts/wrappers/aitbc-blockchain-rpc-wrapper.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +""" +Wrapper script for aitbc-blockchain-rpc service +Uses centralized aitbc utilities for path configuration +""" + +import sys +import os +from pathlib import Path + +# Add aitbc to path +sys.path.insert(0, str(Path("/opt/aitbc"))) +sys.path.insert(0, str(Path("/opt/aitbc/aitbc"))) + +from aitbc import ENV_FILE, NODE_ENV_FILE, REPO_DIR, DATA_DIR, LOG_DIR + +# Set up environment using aitbc constants +os.environ["AITBC_ENV_FILE"] = str(ENV_FILE) +os.environ["AITBC_NODE_ENV_FILE"] = str(NODE_ENV_FILE) +os.environ["PYTHONPATH"] = f"{REPO_DIR}/apps/blockchain-node/src:{REPO_DIR}/apps/blockchain-node/scripts" +os.environ["DATA_DIR"] = str(DATA_DIR) +os.environ["LOG_DIR"] = str(LOG_DIR) + +# Get RPC configuration from environment or use defaults +rpc_host = os.getenv("rpc_bind_host", "0.0.0.0") +rpc_port = os.getenv("rpc_bind_port", "8006") + +# Execute the actual service +exec_cmd = [ + "/opt/aitbc/venv/bin/python", + "-m", + "uvicorn", + "aitbc_chain.app:app", + "--host", + rpc_host, + "--port", + rpc_port +] +os.execvp(exec_cmd[0], exec_cmd) diff --git a/scripts/wrappers/aitbc-blockchain-sync-wrapper.py b/scripts/wrappers/aitbc-blockchain-sync-wrapper.py new file mode 100755 index 00000000..bf465b87 --- /dev/null +++ b/scripts/wrappers/aitbc-blockchain-sync-wrapper.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 +""" +Wrapper script for aitbc-blockchain-sync service +Uses centralized aitbc utilities for path configuration +""" + +import sys +import os +from pathlib import Path + +# Add aitbc to path +sys.path.insert(0, str(Path("/opt/aitbc"))) +sys.path.insert(0, str(Path("/opt/aitbc/aitbc"))) + +from aitbc import ENV_FILE, NODE_ENV_FILE, REPO_DIR, DATA_DIR, LOG_DIR + +# Set up environment using aitbc constants +os.environ["AITBC_ENV_FILE"] = str(ENV_FILE) +os.environ["AITBC_NODE_ENV_FILE"] = str(NODE_ENV_FILE) +os.environ["PYTHONPATH"] = f"{REPO_DIR}/apps/blockchain-node/src:{REPO_DIR}/apps/blockchain-node/scripts" +os.environ["DATA_DIR"] = str(DATA_DIR) +os.environ["LOG_DIR"] = str(LOG_DIR) + +# Get sync configuration from environment +redis_url = os.getenv("SYNC_REDIS_URL", "redis://localhost:6379") +node_id = os.getenv("SYNC_NODE_ID", "ait18yefwwclgmyu2a74zvv0hj3a3xw6gxsn4akrj963kp069j9xy5ns3kurun") +rpc_port = os.getenv("SYNC_RPC_PORT", "8006") +leader_host = os.getenv("SYNC_LEADER_HOST", "10.1.223.40") +source_host = os.getenv("SYNC_SOURCE_HOST", "10.1.223.40") +source_port = os.getenv("SYNC_SOURCE_PORT", "8006") +import_host = os.getenv("SYNC_IMPORT_HOST", "10.1.223.40") +import_port = os.getenv("SYNC_IMPORT_PORT", "8006") + +# Execute the actual service +exec_cmd = [ + "/opt/aitbc/venv/bin/python", + "-m", + "aitbc_chain.chain_sync", + "--redis", redis_url, + "--node-id", node_id, + "--rpc-port", rpc_port, + "--leader-host", leader_host, + "--source-host", source_host, + "--source-port", source_port, + "--import-host", import_host, + "--import-port", import_port +] +os.execvp(exec_cmd[0], exec_cmd) diff --git a/scripts/wrappers/aitbc-coordinator-api-wrapper.py b/scripts/wrappers/aitbc-coordinator-api-wrapper.py new file mode 100755 index 00000000..82a6b898 --- /dev/null +++ b/scripts/wrappers/aitbc-coordinator-api-wrapper.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +""" +Wrapper script for aitbc-coordinator-api service +Uses centralized aitbc utilities for path configuration +""" + +import sys +import os +from pathlib import Path + +# Add aitbc to path +sys.path.insert(0, str(Path("/opt/aitbc"))) +sys.path.insert(0, str(Path("/opt/aitbc/aitbc"))) + +from aitbc import ENV_FILE, NODE_ENV_FILE, REPO_DIR, DATA_DIR, LOG_DIR + +# Set up environment using aitbc constants +os.environ["AITBC_ENV_FILE"] = str(ENV_FILE) +os.environ["AITBC_NODE_ENV_FILE"] = str(NODE_ENV_FILE) +os.environ["PYTHONPATH"] = f"{REPO_DIR}/apps/coordinator-api/src" +os.environ["DATA_DIR"] = str(DATA_DIR) +os.environ["LOG_DIR"] = str(LOG_DIR) + +# Execute the actual service +exec_cmd = [ + "/opt/aitbc/venv/bin/python", + "-m", + "uvicorn", + "app.main:app", + "--host", + "0.0.0.0", + "--port", + "8000" +] +os.execvp(exec_cmd[0], exec_cmd) diff --git a/scripts/wrappers/aitbc-exchange-api-wrapper.py b/scripts/wrappers/aitbc-exchange-api-wrapper.py new file mode 100644 index 00000000..d4b05bb1 --- /dev/null +++ b/scripts/wrappers/aitbc-exchange-api-wrapper.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 +""" +Wrapper script for aitbc-exchange-api service +Uses centralized aitbc utilities for path configuration +""" + +import sys +import os +from pathlib import Path + +# Add aitbc to path +sys.path.insert(0, str(Path("/opt/aitbc"))) +sys.path.insert(0, str(Path("/opt/aitbc/aitbc"))) + +from aitbc import ENV_FILE, NODE_ENV_FILE, REPO_DIR, DATA_DIR, LOG_DIR + +# Set up environment using aitbc constants +os.environ["AITBC_ENV_FILE"] = str(ENV_FILE) +os.environ["AITBC_NODE_ENV_FILE"] = str(NODE_ENV_FILE) +os.environ["PYTHONPATH"] = f"{REPO_DIR}/apps/exchange" +os.environ["DATA_DIR"] = str(DATA_DIR) +os.environ["LOG_DIR"] = str(LOG_DIR) + +# Execute the actual service +exec_cmd = [ + "/opt/aitbc/venv/bin/python", + f"{REPO_DIR}/apps/exchange/simple_exchange_api.py", + "--port", + "8001" +] +os.execvp(exec_cmd[0], exec_cmd) diff --git a/scripts/wrappers/aitbc-explorer-wrapper.py b/scripts/wrappers/aitbc-explorer-wrapper.py new file mode 100755 index 00000000..815133c5 --- /dev/null +++ b/scripts/wrappers/aitbc-explorer-wrapper.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 +""" +Wrapper script for aitbc-explorer service +Uses centralized aitbc utilities for path configuration +""" + +import sys +import os +from pathlib import Path + +# Add aitbc to path +sys.path.insert(0, str(Path("/opt/aitbc"))) +sys.path.insert(0, str(Path("/opt/aitbc/aitbc"))) + +from aitbc import ENV_FILE, NODE_ENV_FILE, REPO_DIR, DATA_DIR, LOG_DIR + +# Set up environment using aitbc constants +os.environ["AITBC_ENV_FILE"] = str(ENV_FILE) +os.environ["AITBC_NODE_ENV_FILE"] = str(NODE_ENV_FILE) +os.environ["PYTHONPATH"] = f"{REPO_DIR}/apps/blockchain-explorer" +os.environ["DATA_DIR"] = str(DATA_DIR) +os.environ["LOG_DIR"] = str(LOG_DIR) + +# Change to explorer directory +os.chdir(f"{REPO_DIR}/apps/blockchain-explorer") + +# Execute the actual service +exec_cmd = [ + "/opt/aitbc/venv/bin/python", + "main.py" +] +os.execvp(exec_cmd[0], exec_cmd) diff --git a/scripts/wrappers/aitbc-marketplace-wrapper.py b/scripts/wrappers/aitbc-marketplace-wrapper.py new file mode 100755 index 00000000..4a90949d --- /dev/null +++ b/scripts/wrappers/aitbc-marketplace-wrapper.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +""" +Wrapper script for aitbc-marketplace service +Uses centralized aitbc utilities for path configuration +""" + +import sys +import os +from pathlib import Path + +# Add aitbc to path +sys.path.insert(0, str(Path("/opt/aitbc"))) +sys.path.insert(0, str(Path("/opt/aitbc/aitbc"))) + +from aitbc import ENV_FILE, NODE_ENV_FILE, REPO_DIR, DATA_DIR, LOG_DIR + +# Set up environment using aitbc constants +os.environ["AITBC_ENV_FILE"] = str(ENV_FILE) +os.environ["AITBC_NODE_ENV_FILE"] = str(NODE_ENV_FILE) +os.environ["PYTHONPATH"] = f"{REPO_DIR}/apps/marketplace/scripts:{REPO_DIR}/apps/marketplace/src:{REPO_DIR}/apps/coordinator-api/src" +os.environ["DATA_DIR"] = str(DATA_DIR) +os.environ["LOG_DIR"] = str(LOG_DIR) + +# Execute the actual service +exec_cmd = [ + "/opt/aitbc/venv/bin/python", + f"{REPO_DIR}/apps/marketplace/scripts/marketplace.py" +] +os.execvp(exec_cmd[0], exec_cmd) diff --git a/scripts/wrappers/aitbc-wallet-wrapper.py b/scripts/wrappers/aitbc-wallet-wrapper.py new file mode 100755 index 00000000..671e31b0 --- /dev/null +++ b/scripts/wrappers/aitbc-wallet-wrapper.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +""" +Wrapper script for aitbc-wallet service +Uses centralized aitbc utilities for path configuration +""" + +import sys +import os +from pathlib import Path + +# Add aitbc to path +sys.path.insert(0, str(Path("/opt/aitbc"))) +sys.path.insert(0, str(Path("/opt/aitbc/aitbc"))) + +from aitbc import ENV_FILE, NODE_ENV_FILE, REPO_DIR, DATA_DIR, LOG_DIR + +# Set up environment using aitbc constants +os.environ["AITBC_ENV_FILE"] = str(ENV_FILE) +os.environ["AITBC_NODE_ENV_FILE"] = str(NODE_ENV_FILE) +os.environ["PYTHONPATH"] = f"{REPO_DIR}/apps/wallet/src:{REPO_DIR}/packages/py/aitbc-crypto/src:{REPO_DIR}/packages/py/aitbc-sdk/src" +os.environ["DATA_DIR"] = str(DATA_DIR) +os.environ["LOG_DIR"] = str(LOG_DIR) + +# Execute the actual service +exec_cmd = [ + "/opt/aitbc/venv/bin/python", + f"{REPO_DIR}/apps/wallet/simple_daemon.py" +] +os.execvp(exec_cmd[0], exec_cmd) diff --git a/systemd/aitbc-agent-coordinator.service b/systemd/aitbc-agent-coordinator.service index ab28cfd0..e1495b13 100644 --- a/systemd/aitbc-agent-coordinator.service +++ b/systemd/aitbc-agent-coordinator.service @@ -6,15 +6,13 @@ After=network.target redis.service Type=simple User=root Group=root -WorkingDirectory=/opt/aitbc/apps/agent-coordinator +WorkingDirectory=/opt/aitbc Environment=PATH=/usr/bin:/usr/local/bin:/usr/bin:/bin -Environment=PYTHONPATH=/opt/aitbc/apps/agent-coordinator/src EnvironmentFile=/etc/aitbc/.env EnvironmentFile=/etc/aitbc/node.env # Agent coordinator execution -ExecStartPre=/bin/mkdir -p /var/lib/aitbc/data/agent-coordinator /var/log/aitbc/agent-coordinator -ExecStart=/opt/aitbc/venv/bin/python -m uvicorn src.app.main:app --host 0.0.0.0 --port 9001 +ExecStart=/opt/aitbc/venv/bin/python /opt/aitbc/scripts/wrappers/aitbc-agent-coordinator-wrapper.py ExecReload=/bin/kill -HUP $MAINPID KillMode=mixed TimeoutStopSec=10 diff --git a/systemd/aitbc-agent-daemon.service b/systemd/aitbc-agent-daemon.service index 218222bc..483b0ebb 100644 --- a/systemd/aitbc-agent-daemon.service +++ b/systemd/aitbc-agent-daemon.service @@ -12,16 +12,7 @@ WorkingDirectory=/opt/aitbc EnvironmentFile=/etc/aitbc/.env EnvironmentFile=/etc/aitbc/node.env Environment="PATH=/opt/aitbc/venv/bin:/usr/local/bin:/usr/bin:/bin" -ExecStart=/opt/aitbc/venv/bin/python /opt/aitbc/apps/agent-coordinator/scripts/agent_daemon.py \ - --wallet temp-agent \ - --address ait1d18e286fc0c12888aca94732b5507c8787af71a5 \ - --password-file /var/lib/aitbc/keystore/.agent_daemon_password \ - --keystore-dir /var/lib/aitbc/keystore \ - --db-path /var/lib/aitbc/data/chain.db \ - --rpc-url http://localhost:8006 \ - --poll-interval 2 \ - --reply-message pong \ - --trigger-message ping +ExecStart=/opt/aitbc/venv/bin/python /opt/aitbc/scripts/wrappers/aitbc-agent-daemon-wrapper.py Restart=always RestartSec=10 diff --git a/systemd/aitbc-agent-registry.service b/systemd/aitbc-agent-registry.service index 7071e33a..9556689d 100644 --- a/systemd/aitbc-agent-registry.service +++ b/systemd/aitbc-agent-registry.service @@ -6,11 +6,10 @@ After=network.target Type=simple User=root Group=root -WorkingDirectory=/opt/aitbc/apps/agent-services/agent-registry/src -Environment=PYTHONPATH=/opt/aitbc +WorkingDirectory=/opt/aitbc EnvironmentFile=/etc/aitbc/.env EnvironmentFile=/etc/aitbc/node.env -ExecStart=/opt/aitbc/venv/bin/python app.py +ExecStart=/opt/aitbc/venv/bin/python /opt/aitbc/scripts/wrappers/aitbc-agent-registry-wrapper.py Restart=always RestartSec=10 diff --git a/systemd/aitbc-blockchain-event-bridge.service b/systemd/aitbc-blockchain-event-bridge.service index 4386a623..c0b998b2 100644 --- a/systemd/aitbc-blockchain-event-bridge.service +++ b/systemd/aitbc-blockchain-event-bridge.service @@ -1,24 +1,19 @@ [Unit] Description=AITBC Blockchain Event Bridge Service After=network.target aitbc-blockchain-node.service -Wants=aitbc-blockchain-node.service [Service] Type=simple -User=aitbc -Group=aitbc -WorkingDirectory=/opt/aitbc/apps/blockchain-event-bridge -Environment="PATH=/opt/aitbc/apps/blockchain-event-bridge/.venv/bin:/usr/local/bin:/usr/bin:/bin" -EnvironmentFile=/etc/aitbc/blockchain-event-bridge.env - -# Poetry virtualenv -ExecStart=/opt/aitbc/apps/blockchain-event-bridge/.venv/bin/uvicorn blockchain_event_bridge.main:app --host 127.0.0.1 --port 8204 - -# Restart policy +User=root +Group=root +WorkingDirectory=/opt/aitbc +EnvironmentFile=/etc/aitbc/.env +EnvironmentFile=/etc/aitbc/node.env +ExecStart=/opt/aitbc/venv/bin/python /opt/aitbc/scripts/wrappers/aitbc-blockchain-event-bridge-wrapper.py Restart=always -RestartSec=10 - -# Security +RestartSec=5 +StandardOutput=journal +StandardError=journal NoNewPrivileges=true PrivateTmp=true ProtectSystem=strict diff --git a/systemd/aitbc-blockchain-node.service b/systemd/aitbc-blockchain-node.service index d1a22bd1..6b0d83aa 100644 --- a/systemd/aitbc-blockchain-node.service +++ b/systemd/aitbc-blockchain-node.service @@ -9,12 +9,9 @@ User=root Group=root WorkingDirectory=/opt/aitbc Environment=PATH=/usr/bin:/usr/local/bin:/usr/bin:/bin -Environment=PYTHONPATH=/opt/aitbc/apps/blockchain-node/src EnvironmentFile=/etc/aitbc/.env EnvironmentFile=/etc/aitbc/node.env - -# Production execution -ExecStart=/opt/aitbc/venv/bin/python -m aitbc_chain.combined_main +ExecStart=/opt/aitbc/venv/bin/python /opt/aitbc/scripts/wrappers/aitbc-blockchain-node-wrapper.py ExecReload=/bin/kill -HUP $MAINPID KillMode=mixed TimeoutStopSec=10 diff --git a/systemd/aitbc-blockchain-p2p.service b/systemd/aitbc-blockchain-p2p.service index 60329be1..22b87c93 100644 --- a/systemd/aitbc-blockchain-p2p.service +++ b/systemd/aitbc-blockchain-p2p.service @@ -6,12 +6,11 @@ After=network.target Type=simple User=root Group=root -WorkingDirectory=/opt/aitbc/apps/blockchain-node +WorkingDirectory=/opt/aitbc Environment=PATH=/usr/bin:/usr/local/bin:/usr/bin:/bin -Environment=PYTHONPATH=/opt/aitbc/apps/blockchain-node/src:/opt/aitbc/apps/blockchain-node/scripts EnvironmentFile=/etc/aitbc/.env EnvironmentFile=/etc/aitbc/node.env -ExecStart=/opt/aitbc/venv/bin/python -m aitbc_chain.p2p_network --host ${p2p_bind_host} --port ${p2p_bind_port} --peers ${p2p_peers} --node-id ${p2p_node_id} +ExecStart=/opt/aitbc/venv/bin/python /opt/aitbc/scripts/wrappers/aitbc-blockchain-p2p-wrapper.py Restart=always RestartSec=5 StandardOutput=journal diff --git a/systemd/aitbc-blockchain-rpc.service b/systemd/aitbc-blockchain-rpc.service index 68a933a3..4d23427a 100644 --- a/systemd/aitbc-blockchain-rpc.service +++ b/systemd/aitbc-blockchain-rpc.service @@ -6,13 +6,12 @@ After=network.target aitbc-blockchain-node.service Type=simple User=root Group=root -WorkingDirectory=/opt/aitbc/apps/blockchain-node +WorkingDirectory=/opt/aitbc +Environment=PATH=/usr/bin:/usr/local/bin:/usr/bin:/bin EnvironmentFile=/etc/aitbc/.env EnvironmentFile=/etc/aitbc/node.env -Environment=PATH=/usr/bin:/usr/local/bin:/usr/bin:/bin -Environment=PYTHONPATH=/opt/aitbc/apps/blockchain-node/src:/opt/aitbc/apps/blockchain-node/scripts UnsetEnvironment=enable_block_production ENABLE_BLOCK_PRODUCTION -ExecStart=/usr/bin/env enable_block_production=false /opt/aitbc/venv/bin/python -m uvicorn aitbc_chain.app:app --host ${rpc_bind_host} --port ${rpc_bind_port} +ExecStart=/opt/aitbc/venv/bin/python /opt/aitbc/scripts/wrappers/aitbc-blockchain-rpc-wrapper.py Restart=always RestartSec=5 StandardOutput=journal diff --git a/systemd/aitbc-blockchain-sync.service b/systemd/aitbc-blockchain-sync.service index 7871b0b4..27b26069 100644 --- a/systemd/aitbc-blockchain-sync.service +++ b/systemd/aitbc-blockchain-sync.service @@ -6,12 +6,11 @@ After=network.target redis.service aitbc-blockchain-node.service aitbc-blockchai Type=simple User=root Group=root -WorkingDirectory=/opt/aitbc/apps/blockchain-node +WorkingDirectory=/opt/aitbc EnvironmentFile=/etc/aitbc/.env EnvironmentFile=/etc/aitbc/node.env Environment=PATH=/usr/bin:/usr/local/bin:/usr/bin:/bin -Environment=PYTHONPATH=/opt/aitbc/apps/blockchain-node/src:/opt/aitbc/apps/blockchain-node/scripts -ExecStart=/opt/aitbc/venv/bin/python -m aitbc_chain.chain_sync --redis redis://localhost:6379 --node-id ait18yefwwclgmyu2a74zvv0hj3a3xw6gxsn4akrj963kp069j9xy5ns3kurun --rpc-port 8006 --leader-host 10.1.223.40 --source-host 10.1.223.40 --source-port 8006 --import-host 10.1.223.40 --import-port 8006 +ExecStart=/opt/aitbc/venv/bin/python /opt/aitbc/scripts/wrappers/aitbc-blockchain-sync-wrapper.py Restart=always RestartSec=5 StandardOutput=journal diff --git a/systemd/aitbc-coordinator-api.service b/systemd/aitbc-coordinator-api.service index dc2b2bbe..95b438bc 100644 --- a/systemd/aitbc-coordinator-api.service +++ b/systemd/aitbc-coordinator-api.service @@ -9,7 +9,7 @@ WorkingDirectory=/opt/aitbc/apps/coordinator-api/src Environment=PYTHONPATH=/opt/aitbc/apps/coordinator-api/src:/opt/aitbc/packages/py/aitbc-sdk/src:/opt/aitbc/packages/py/aitbc-crypto/src EnvironmentFile=/etc/aitbc/.env EnvironmentFile=/etc/aitbc/node.env -ExecStart=/opt/aitbc/venv/bin/python -m uvicorn app.main:app --host 0.0.0.0 --port 8000 +ExecStart=/opt/aitbc/venv/bin/python /opt/aitbc/scripts/wrappers/aitbc-coordinator-api-wrapper.py Restart=always RestartSec=5 StandardOutput=journal diff --git a/systemd/aitbc-explorer.service b/systemd/aitbc-explorer.service index 8f5972e4..9bb9ddc7 100644 --- a/systemd/aitbc-explorer.service +++ b/systemd/aitbc-explorer.service @@ -5,12 +5,11 @@ After=network.target aitbc-blockchain-rpc-1.service aitbc-blockchain-rpc-2.servi [Service] Type=simple User=root -WorkingDirectory=/opt/aitbc/apps/blockchain-explorer -# Using the blockchain node venv since the coordinator one is broken +WorkingDirectory=/opt/aitbc Environment=PATH=/usr/bin:/usr/local/bin:/usr/bin:/bin EnvironmentFile=/etc/aitbc/.env EnvironmentFile=/etc/aitbc/node.env -ExecStart=/opt/aitbc/venv/bin/python main.py +ExecStart=/opt/aitbc/venv/bin/python /opt/aitbc/scripts/wrappers/aitbc-explorer-wrapper.py Restart=always RestartSec=5 StandardOutput=journal diff --git a/systemd/aitbc-marketplace.service b/systemd/aitbc-marketplace.service index 3f34cecb..ca47ff5d 100644 --- a/systemd/aitbc-marketplace.service +++ b/systemd/aitbc-marketplace.service @@ -14,7 +14,7 @@ EnvironmentFile=/etc/aitbc/.env EnvironmentFile=/etc/aitbc/node.env # Production execution -ExecStart=/opt/aitbc/venv/bin/python /opt/aitbc/apps/marketplace/scripts/marketplace.py +ExecStart=/opt/aitbc/venv/bin/python /opt/aitbc/scripts/wrappers/aitbc-marketplace-wrapper.py ExecReload=/bin/kill -HUP $MAINPID KillMode=mixed TimeoutStopSec=10 diff --git a/systemd/aitbc-wallet.service b/systemd/aitbc-wallet.service index 99c4d4ed..851425bf 100644 --- a/systemd/aitbc-wallet.service +++ b/systemd/aitbc-wallet.service @@ -7,11 +7,10 @@ Wants=network.target Type=simple User=root Group=root -WorkingDirectory=/opt/aitbc/apps/wallet -Environment=PYTHONPATH=/opt/aitbc/apps/wallet/src:/opt/aitbc/packages/py/aitbc-crypto/src:/opt/aitbc/packages/py/aitbc-sdk/src +WorkingDirectory=/opt/aitbc EnvironmentFile=/etc/aitbc/.env EnvironmentFile=/etc/aitbc/node.env -ExecStart=/opt/aitbc/venv/bin/python /opt/aitbc/apps/wallet/simple_daemon.py +ExecStart=/opt/aitbc/venv/bin/python /opt/aitbc/scripts/wrappers/aitbc-wallet-wrapper.py KillMode=mixed TimeoutStopSec=5 PrivateTmp=false