CLI Usage
CLI Usage
Section titled “CLI Usage”Faber provides a comprehensive command-line interface built with Clap for managing the service, executing tasks, and configuring the application.
Basic Commands
Section titled “Basic Commands”Starting the Server
Section titled “Starting the Server”# Start the server with default configurationfaber serve
# Start with custom host and portfaber serve --host 0.0.0.0 --port 9000
# Start with graceful shutdownfaber serve --graceful-shutdown
# Start in debug modefaber serve --debug --log-level debug
Configuration Management
Section titled “Configuration Management”# Show current configurationfaber config
# Show default configurationfaber config --default
# Validate configurationfaber validate
# Validate specific configuration filefaber validate /path/to/config.yaml
Task Execution
Section titled “Task Execution”# Execute a simple commandfaber execute "echo hello world"
# Execute with argumentsfaber execute "ls -la"
# Execute Python scriptfaber execute "python -c 'print(\"Hello from Python\")'"
# Execute with environment variablesfaber execute "env" --env DEBUG=true --env CUSTOM_VAR=value
Command Reference
Section titled “Command Reference”faber serve
Section titled “faber serve”Start the Faber HTTP server.
Options:
--host <HOST>
: Server host (default: 127.0.0.1)--port <PORT>
: Server port (default: 8080)--config <CONFIG>
: Configuration file path--api-key <API_KEY>
: API key for authentication--open-mode
: Enable open mode (no authentication required)--graceful-shutdown
: Enable graceful shutdown--debug
: Enable debug mode--log-level <LOG_LEVEL>
: Log level (debug, info, warn, error)--log-file <LOG_FILE>
: Log file path
Examples:
# Basic server startfaber serve
# Production serverfaber serve --host 0.0.0.0 --port 8080 --config /etc/faber/config.yaml
# Development serverfaber serve --debug --log-level debug --open-mode
# Server with custom API keyfaber serve --api-key your-secret-key
faber config
Section titled “faber config”Display configuration information.
Options:
--default
: Show default configuration instead of current--config <CONFIG>
: Configuration file path
Examples:
# Show current configurationfaber config
# Show default configurationfaber config --default
# Show configuration from specific filefaber config --config /path/to/config.yaml
faber validate
Section titled “faber validate”Validate configuration files.
Options:
--config <CONFIG>
: Configuration file to validate
Examples:
# Validate default configurationfaber validate
# Validate specific configuration filefaber validate /path/to/config.yaml
# Validate and show errorsfaber validate --config production.yaml
faber execute
Section titled “faber execute”Execute tasks directly via CLI (if implemented).
Options:
--env <KEY=VALUE>
: Set environment variables--timeout <TIMEOUT>
: Task timeout in seconds--memory <MEMORY>
: Memory limit in MB--cpu <CPU>
: CPU time limit in seconds
Examples:
# Simple command executionfaber execute "echo hello world"
# Execute with environment variablesfaber execute "python script.py" --env DEBUG=true --env API_KEY=secret
# Execute with resource limitsfaber execute "python heavy_script.py" --timeout 30 --memory 512 --cpu 60
Global Options
Section titled “Global Options”All commands support these global options:
--config <CONFIG>
: Configuration file path--debug
: Enable debug mode--log-level <LOG_LEVEL>
: Log level--log-file <LOG_FILE>
: Log file path--help
: Show help information--version
: Show version information
Configuration File
Section titled “Configuration File”The CLI uses the same configuration system as the API. Configuration files can be in YAML format:
server: host: '127.0.0.1' port: 8080 enable_swagger: true
auth: api_key: 'your-secret-key' open_mode: false
logging: level: 'info' format: 'json' file: null debug: false
Environment Variables
Section titled “Environment Variables”Configuration can also be set via environment variables:
# Server configurationexport FABER_SERVER_HOST=0.0.0.0export FABER_SERVER_PORT=9000
# Authenticationexport FABER_AUTH_API_KEY=your-secret-keyexport FABER_AUTH_OPEN_MODE=false
# Loggingexport FABER_LOGGING_LEVEL=debugexport FABER_LOGGING_FORMAT=json
Examples
Section titled “Examples”Development Workflow
Section titled “Development Workflow”# 1. Validate configurationfaber validate
# 2. Start development serverfaber serve --debug --log-level debug --open-mode
# 3. Test task executionfaber execute "echo 'Hello from Faber'"
# 4. Test Python executionfaber execute "python -c 'import sys; print(f\"Python {sys.version}\")'"
Production Deployment
Section titled “Production Deployment”# 1. Validate production configurationfaber validate /etc/faber/production.yaml
# 2. Start production serverfaber serve \ --config /etc/faber/production.yaml \ --host 0.0.0.0 \ --port 8080 \ --graceful-shutdown
# 3. Monitor logstail -f /var/log/faber.log
Testing and Debugging
Section titled “Testing and Debugging”# Test configurationfaber config --default
# Validate configurationfaber validate
# Start with verbose loggingfaber serve --debug --log-level debug
# Test API endpointscurl http://localhost:8080/healthcurl -X POST http://localhost:8080/execute \ -H "Content-Type: application/json" \ -d '{"tasks":[{"command":"echo","args":["test"]}]}'
Error Handling
Section titled “Error Handling”The CLI provides clear error messages and exit codes:
- Exit code 0: Success
- Exit code 1: General error
- Exit code 2: Configuration error
- Exit code 3: Validation error
Common Error Scenarios
Section titled “Common Error Scenarios”-
Configuration not found:
Error: Configuration file not found: /path/to/config.yaml -
Invalid configuration:
Error: Invalid configuration: server.port must be between 1 and 65535 -
Permission denied:
Error: Permission denied: root privileges required for sandboxing -
Port already in use:
Error: Address already in use: 127.0.0.1:8080
Integration with System Services
Section titled “Integration with System Services”systemd Service
Section titled “systemd Service”Create a systemd service file /etc/systemd/system/faber.service
:
[Unit]Description=Faber Secure Task Execution ServiceAfter=network.target
[Service]Type=simpleUser=rootExecStart=/usr/local/bin/faber serve --config /etc/faber/config.yamlRestart=alwaysRestartSec=5
[Install]WantedBy=multi-user.target
Enable and start the service:
sudo systemctl daemon-reloadsudo systemctl enable fabersudo systemctl start fabersudo systemctl status faber
Docker Integration
Section titled “Docker Integration”# Build Docker imagedocker build -f docker/Dockerfile.prod -t faber:latest .
# Run with configurationdocker run --privileged \ -p 8080:8080 \ -v /etc/faber:/etc/faber \ -v /var/log/faber:/var/log \ faber:latest serve --config /etc/faber/config.yaml
Best Practices
Section titled “Best Practices”- Use configuration files: Store configuration in files rather than command-line arguments
- Validate before deployment: Always validate configuration before starting the server
- Use appropriate log levels: Use debug level for development, info for production
- Secure API keys: Store API keys in environment variables or secure configuration files
- Monitor logs: Set up log rotation and monitoring for production deployments
- Graceful shutdown: Use graceful shutdown for production deployments
- Resource limits: Set appropriate resource limits for your use case