mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-01 17:17:24 -04:00
refactor: remove duplicate MCP service log files
Remove redundant log file creation for MCP services since output is already captured by Docker logs. This simplifies deployment by removing unnecessary volume mounts and file management. Changes: - Remove logs/ directory creation from Dockerfile - Remove logs/ volume mount from docker-compose.yml - Update start_mcp_services.py to send output to DEVNULL - Update documentation to reflect changes (DOCKER.md, docs/DOCKER.md) - Update .env.example to remove logs/ from volume description Users can still view MCP service output via 'docker logs' or 'docker-compose logs -f'. Trading session logs in data/agent_data/ remain unchanged.
This commit is contained in:
@@ -35,7 +35,7 @@ MAX_SIMULATION_DAYS=30
|
|||||||
AUTO_DOWNLOAD_PRICE_DATA=true
|
AUTO_DOWNLOAD_PRICE_DATA=true
|
||||||
|
|
||||||
# Data Volume Configuration
|
# Data Volume Configuration
|
||||||
# Base directory for all persistent data (will contain data/, logs/, configs/ subdirectories)
|
# Base directory for all persistent data (will contain data/ and configs/ subdirectories)
|
||||||
# Use relative paths (./volumes) or absolute paths (/home/user/ai-trader-volumes)
|
# Use relative paths (./volumes) or absolute paths (/home/user/ai-trader-volumes)
|
||||||
# Defaults to current directory (.) if not set
|
# Defaults to current directory (.) if not set
|
||||||
VOLUME_PATH=.
|
VOLUME_PATH=.
|
||||||
|
|||||||
30
DOCKER.md
30
DOCKER.md
@@ -154,10 +154,9 @@ docker-compose up
|
|||||||
|
|
||||||
### Volume Mounts
|
### Volume Mounts
|
||||||
|
|
||||||
Docker Compose mounts three volumes for persistent data. By default, these are stored in the project directory:
|
Docker Compose mounts two volumes for persistent data. By default, these are stored in the project directory:
|
||||||
|
|
||||||
- `./data:/app/data` - Price data and trading records
|
- `./data:/app/data` - Price data and trading records
|
||||||
- `./logs:/app/logs` - MCP service logs
|
|
||||||
- `./configs:/app/configs` - Configuration files (allows editing configs without rebuilding)
|
- `./configs:/app/configs` - Configuration files (allows editing configs without rebuilding)
|
||||||
|
|
||||||
### Custom Volume Location
|
### Custom Volume Location
|
||||||
@@ -174,7 +173,6 @@ VOLUME_PATH=./volumes
|
|||||||
|
|
||||||
This will store data in:
|
This will store data in:
|
||||||
- `/home/user/trading-data/data/`
|
- `/home/user/trading-data/data/`
|
||||||
- `/home/user/trading-data/logs/`
|
|
||||||
- `/home/user/trading-data/configs/`
|
- `/home/user/trading-data/configs/`
|
||||||
|
|
||||||
**Note:** The directory structure is automatically created. You'll need to copy your existing configs:
|
**Note:** The directory structure is automatically created. You'll need to copy your existing configs:
|
||||||
@@ -190,7 +188,7 @@ To reset all trading data:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker-compose down
|
docker-compose down
|
||||||
rm -rf ${VOLUME_PATH:-.}/data/agent_data/* ${VOLUME_PATH:-.}/logs/*
|
rm -rf ${VOLUME_PATH:-.}/data/agent_data/*
|
||||||
docker-compose up
|
docker-compose up
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -217,8 +215,7 @@ docker pull ghcr.io/xe138/ai-trader-server:latest
|
|||||||
```bash
|
```bash
|
||||||
docker run --env-file .env \
|
docker run --env-file .env \
|
||||||
-v $(pwd)/data:/app/data \
|
-v $(pwd)/data:/app/data \
|
||||||
-v $(pwd)/logs:/app/logs \
|
-p 8080:8080 \
|
||||||
-p 8000-8003:8000-8003 \
|
|
||||||
ghcr.io/xe138/ai-trader-server:latest
|
ghcr.io/xe138/ai-trader-server:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -234,9 +231,9 @@ docker pull ghcr.io/xe138/ai-trader-server:v1.0.0
|
|||||||
**Symptom:** Container exits immediately or errors about ports
|
**Symptom:** Container exits immediately or errors about ports
|
||||||
|
|
||||||
**Solutions:**
|
**Solutions:**
|
||||||
- Check ports 8000-8003 not already in use: `lsof -i :8000-8003`
|
|
||||||
- View container logs: `docker-compose logs`
|
- View container logs: `docker-compose logs`
|
||||||
- Check MCP service logs: `cat logs/math.log`
|
- Check if API port 8080 is already in use: `lsof -i :8080`
|
||||||
|
- Verify MCP services started by checking Docker logs for service startup messages
|
||||||
|
|
||||||
### Missing API Keys
|
### Missing API Keys
|
||||||
|
|
||||||
@@ -258,12 +255,12 @@ docker pull ghcr.io/xe138/ai-trader-server:v1.0.0
|
|||||||
|
|
||||||
### Permission Issues
|
### Permission Issues
|
||||||
|
|
||||||
**Symptom:** Cannot write to data or logs directories
|
**Symptom:** Cannot write to data directory
|
||||||
|
|
||||||
**Solutions:**
|
**Solutions:**
|
||||||
- Ensure directories writable: `chmod -R 755 data logs`
|
- Ensure data directory is writable: `chmod -R 755 data`
|
||||||
- Check volume mount permissions
|
- Check volume mount permissions
|
||||||
- May need to create directories first: `mkdir -p data logs`
|
- May need to create directory first: `mkdir -p data`
|
||||||
|
|
||||||
### Container Keeps Restarting
|
### Container Keeps Restarting
|
||||||
|
|
||||||
@@ -298,13 +295,12 @@ docker buildx build --platform linux/amd64,linux/arm64 -t ai-trader-server .
|
|||||||
docker stats ai-trader-server
|
docker stats ai-trader-server
|
||||||
```
|
```
|
||||||
|
|
||||||
### Access MCP Services Directly
|
### Access API Directly
|
||||||
|
|
||||||
Services exposed on host:
|
API server exposed on host:
|
||||||
- Math: http://localhost:8000
|
- REST API: http://localhost:8080
|
||||||
- Search: http://localhost:8001
|
|
||||||
- Trade: http://localhost:8002
|
MCP services run internally and are not exposed to the host.
|
||||||
- Price: http://localhost:8003
|
|
||||||
|
|
||||||
## Development Workflow
|
## Development Workflow
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ WORKDIR /app
|
|||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Create necessary directories
|
# Create necessary directories
|
||||||
RUN mkdir -p data logs data/agent_data
|
RUN mkdir -p data data/agent_data
|
||||||
|
|
||||||
# Make entrypoint executable
|
# Make entrypoint executable
|
||||||
RUN chmod +x entrypoint.sh
|
RUN chmod +x entrypoint.sh
|
||||||
|
|||||||
@@ -52,10 +52,6 @@ class MCPServiceManager:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create logs directory
|
|
||||||
self.log_dir = Path('logs')
|
|
||||||
self.log_dir.mkdir(exist_ok=True)
|
|
||||||
|
|
||||||
# Set signal handlers
|
# Set signal handlers
|
||||||
signal.signal(signal.SIGINT, self.signal_handler)
|
signal.signal(signal.SIGINT, self.signal_handler)
|
||||||
signal.signal(signal.SIGTERM, self.signal_handler)
|
signal.signal(signal.SIGTERM, self.signal_handler)
|
||||||
@@ -77,27 +73,23 @@ class MCPServiceManager:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Start service process
|
|
||||||
log_file = self.log_dir / f"{service_id}.log"
|
|
||||||
|
|
||||||
# Set PYTHONPATH to /app so services can import from tools module
|
# Set PYTHONPATH to /app so services can import from tools module
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
env['PYTHONPATH'] = str(Path.cwd())
|
env['PYTHONPATH'] = str(Path.cwd())
|
||||||
|
|
||||||
with open(log_file, 'w') as f:
|
# Start service process (output goes to Docker logs)
|
||||||
process = subprocess.Popen(
|
process = subprocess.Popen(
|
||||||
[sys.executable, str(script_path)],
|
[sys.executable, str(script_path)],
|
||||||
stdout=f,
|
stdout=subprocess.DEVNULL,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.DEVNULL,
|
||||||
cwd=Path.cwd(), # Use current working directory (/app)
|
cwd=Path.cwd(), # Use current working directory (/app)
|
||||||
env=env # Pass environment with PYTHONPATH
|
env=env # Pass environment with PYTHONPATH
|
||||||
)
|
)
|
||||||
|
|
||||||
self.services[service_id] = {
|
self.services[service_id] = {
|
||||||
'process': process,
|
'process': process,
|
||||||
'name': service_name,
|
'name': service_name,
|
||||||
'port': port,
|
'port': port
|
||||||
'log_file': log_file
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print(f"✅ {service_name} service started (PID: {process.pid}, Port: {port})")
|
print(f"✅ {service_name} service started (PID: {process.pid}, Port: {port})")
|
||||||
@@ -167,7 +159,7 @@ class MCPServiceManager:
|
|||||||
print(f"✅ {service['name']} service running normally")
|
print(f"✅ {service['name']} service running normally")
|
||||||
else:
|
else:
|
||||||
print(f"❌ {service['name']} service failed to start")
|
print(f"❌ {service['name']} service failed to start")
|
||||||
print(f" Please check logs: {service['log_file']}")
|
print(f" Check Docker logs for details: docker logs ai-trader-server")
|
||||||
|
|
||||||
def print_service_info(self):
|
def print_service_info(self):
|
||||||
"""Print service information"""
|
"""Print service information"""
|
||||||
@@ -175,7 +167,6 @@ class MCPServiceManager:
|
|||||||
for service_id, service in self.services.items():
|
for service_id, service in self.services.items():
|
||||||
print(f" - {service['name']}: http://localhost:{service['port']} (PID: {service['process'].pid})")
|
print(f" - {service['name']}: http://localhost:{service['port']} (PID: {service['process'].pid})")
|
||||||
|
|
||||||
print(f"\n📁 Log files location: {self.log_dir.absolute()}")
|
|
||||||
print("\n🛑 Press Ctrl+C to stop all services")
|
print("\n🛑 Press Ctrl+C to stop all services")
|
||||||
|
|
||||||
def keep_alive(self):
|
def keep_alive(self):
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ services:
|
|||||||
container_name: ai-trader-server
|
container_name: ai-trader-server
|
||||||
volumes:
|
volumes:
|
||||||
- ${VOLUME_PATH:-.}/data:/app/data
|
- ${VOLUME_PATH:-.}/data:/app/data
|
||||||
- ${VOLUME_PATH:-.}/logs:/app/logs
|
|
||||||
# User configs mounted to /app/user-configs (default config baked into image)
|
# User configs mounted to /app/user-configs (default config baked into image)
|
||||||
- ${VOLUME_PATH:-.}/configs:/app/user-configs
|
- ${VOLUME_PATH:-.}/configs:/app/user-configs
|
||||||
environment:
|
environment:
|
||||||
|
|||||||
@@ -112,10 +112,9 @@ docker-compose up
|
|||||||
|
|
||||||
### Volume Mounts
|
### Volume Mounts
|
||||||
|
|
||||||
Docker Compose mounts three volumes for persistent data. By default, these are stored in the project directory:
|
Docker Compose mounts two volumes for persistent data. By default, these are stored in the project directory:
|
||||||
|
|
||||||
- `./data:/app/data` - Price data and trading records
|
- `./data:/app/data` - Price data and trading records
|
||||||
- `./logs:/app/logs` - MCP service logs
|
|
||||||
- `./configs:/app/configs` - Configuration files (allows editing configs without rebuilding)
|
- `./configs:/app/configs` - Configuration files (allows editing configs without rebuilding)
|
||||||
|
|
||||||
### Custom Volume Location
|
### Custom Volume Location
|
||||||
@@ -132,7 +131,6 @@ VOLUME_PATH=./volumes
|
|||||||
|
|
||||||
This will store data in:
|
This will store data in:
|
||||||
- `/home/user/trading-data/data/`
|
- `/home/user/trading-data/data/`
|
||||||
- `/home/user/trading-data/logs/`
|
|
||||||
- `/home/user/trading-data/configs/`
|
- `/home/user/trading-data/configs/`
|
||||||
|
|
||||||
**Note:** The directory structure is automatically created. You'll need to copy your existing configs:
|
**Note:** The directory structure is automatically created. You'll need to copy your existing configs:
|
||||||
@@ -148,7 +146,7 @@ To reset all trading data:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker-compose down
|
docker-compose down
|
||||||
rm -rf ${VOLUME_PATH:-.}/data/agent_data/* ${VOLUME_PATH:-.}/logs/*
|
rm -rf ${VOLUME_PATH:-.}/data/agent_data/*
|
||||||
docker-compose up
|
docker-compose up
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -175,8 +173,7 @@ docker pull ghcr.io/xe138/ai-trader-server:latest
|
|||||||
```bash
|
```bash
|
||||||
docker run --env-file .env \
|
docker run --env-file .env \
|
||||||
-v $(pwd)/data:/app/data \
|
-v $(pwd)/data:/app/data \
|
||||||
-v $(pwd)/logs:/app/logs \
|
-p 8080:8080 \
|
||||||
-p 8000-8003:8000-8003 \
|
|
||||||
ghcr.io/xe138/ai-trader-server:latest
|
ghcr.io/xe138/ai-trader-server:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -192,9 +189,9 @@ docker pull ghcr.io/xe138/ai-trader-server:v1.0.0
|
|||||||
**Symptom:** Container exits immediately or errors about ports
|
**Symptom:** Container exits immediately or errors about ports
|
||||||
|
|
||||||
**Solutions:**
|
**Solutions:**
|
||||||
- Check ports 8000-8003 not already in use: `lsof -i :8000-8003`
|
|
||||||
- View container logs: `docker-compose logs`
|
- View container logs: `docker-compose logs`
|
||||||
- Check MCP service logs: `cat logs/math.log`
|
- Check if API port 8080 is already in use: `lsof -i :8080`
|
||||||
|
- Verify MCP services started by checking Docker logs for service startup messages
|
||||||
|
|
||||||
### Missing API Keys
|
### Missing API Keys
|
||||||
|
|
||||||
@@ -216,12 +213,12 @@ docker pull ghcr.io/xe138/ai-trader-server:v1.0.0
|
|||||||
|
|
||||||
### Permission Issues
|
### Permission Issues
|
||||||
|
|
||||||
**Symptom:** Cannot write to data or logs directories
|
**Symptom:** Cannot write to data directory
|
||||||
|
|
||||||
**Solutions:**
|
**Solutions:**
|
||||||
- Ensure directories writable: `chmod -R 755 data logs`
|
- Ensure data directory is writable: `chmod -R 755 data`
|
||||||
- Check volume mount permissions
|
- Check volume mount permissions
|
||||||
- May need to create directories first: `mkdir -p data logs`
|
- May need to create directory first: `mkdir -p data`
|
||||||
|
|
||||||
### Container Keeps Restarting
|
### Container Keeps Restarting
|
||||||
|
|
||||||
@@ -256,13 +253,12 @@ docker buildx build --platform linux/amd64,linux/arm64 -t ai-trader-server .
|
|||||||
docker stats ai-trader-server
|
docker stats ai-trader-server
|
||||||
```
|
```
|
||||||
|
|
||||||
### Access MCP Services Directly
|
### Access API Directly
|
||||||
|
|
||||||
Services exposed on host:
|
API server exposed on host:
|
||||||
- Math: http://localhost:8000
|
- REST API: http://localhost:8080
|
||||||
- Search: http://localhost:8001
|
|
||||||
- Trade: http://localhost:8002
|
MCP services run internally and are not exposed to the host.
|
||||||
- Price: http://localhost:8003
|
|
||||||
|
|
||||||
## Development Workflow
|
## Development Workflow
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user