This guide covers deploying Smartbotic Microbit in production environments.
Minimum:
Recommended:
Operating System:
System Packages:
This is the easiest method for production deployment.
Download the latest release packages:
smartbotic-database-*.tar.gzsmartbotic-microbit-*.tar.gz
# Example download (replace with actual URLs)
wget https://releases.smartbotics.ai/smartbotic-database-0.1.0-debian12.tar.gz
wget https://releases.smartbotics.ai/smartbotic-microbit-0.1.0-debian12.tar.gz
# Install both packages
sudo ./packaging/scripts/install.sh smartbotic-*.tar.gz
# Or for verbose output
sudo ./packaging/scripts/install.sh -v smartbotic-*.tar.gz
Installer Options:
--prefix DIR: Install location (default: /opt/smartbotic)--confdir DIR: Config directory (default: /etc/smartbotic)--user USER: Service user (default: smartbotic)--no-systemd: Skip systemd service installation--dry-run: Show what would be done without making changes-v, --verbose: Show detailed outputAfter installation:
/opt/smartbotic/
├── bin/
│ ├── smartbotic-database
│ └── smartbotic-microbit
└── share/smartbotic/
└── nginx/
/etc/smartbotic/
├── database.json
├── microbit.json
└── smartbotic.env.default
/var/lib/smartbotic/
├── database/
│ ├── storage/
│ └── migrations/
└── microbit/
└── webui/
/var/log/smartbotic/
├── database.log
└── microbit.log
For custom builds or development deployment, see DEVELOPMENT.md.
Create the main environment file:
sudo cp /etc/smartbotic/smartbotic.env.default /etc/smartbotic/smartbotic.env
sudo chmod 640 /etc/smartbotic/smartbotic.env
sudo chown root:smartbotic /etc/smartbotic/smartbotic.env
sudo nano /etc/smartbotic/smartbotic.env
Required settings in /etc/smartbotic/smartbotic.env:
# JWT Secret (REQUIRED - generate a strong random secret)
JWT_SECRET="your-secret-key-change-this-to-random-string"
# Database connection
DB_ADDRESS="localhost:9004"
# SMTP Settings (for email notifications)
SMTP_HOST="smtp.example.com"
SMTP_PORT="587"
SMTP_USER="noreply@example.com"
SMTP_PASSWORD="smtp-password"
SMTP_FROM="noreply@example.com"
# CallerAI Integration (for AI assistants)
CALLERAI_API_URL="https://api.caller.ai"
CALLERAI_API_KEY="your-callerai-api-key"
# WebUI Path
WEBUI_PATH="/var/lib/smartbotic/microbit/webui"
Generating a secure JWT secret:
# Generate a random 64-character secret
openssl rand -hex 32
Edit /etc/smartbotic/database.json if needed:
{
"log_level": "info",
"grpc": {
"bind_address": "127.0.0.1",
"port": 9004
},
"storage": {
"path": "/var/lib/smartbotic/database/storage",
"migrations_path": "/var/lib/smartbotic/database/migrations"
}
}
Important:
bind_address as 127.0.0.1 for security (database should not be exposed)smartbotic userEdit /etc/smartbotic/microbit.json:
{
"log_level": "info",
"database": {
"rpc_address": "${DB_ADDRESS:localhost:9004}",
"timeout_ms": 5000,
"max_retries": 3
},
"http": {
"bind_address": "127.0.0.1",
"port": 8090,
"static_files": {
"enabled": true,
"path": "${WEBUI_PATH:/var/lib/smartbotic/microbit/webui}"
}
},
"auth": {
"enabled": true,
"jwt_secret": "${JWT_SECRET:change-me-in-production}",
"access_token_lifetime_sec": 900,
"refresh_token_lifetime_sec": 604800,
"password_policy": {
"min_length": 8,
"require_number": true,
"require_special": false
}
},
"smtp": {
"host": "${SMTP_HOST:}",
"port": "${SMTP_PORT:587}",
"username": "${SMTP_USER:}",
"password": "${SMTP_PASSWORD:}",
"from_address": "${SMTP_FROM:noreply@smartbotics.ai}",
"from_name": "Smartbotic",
"use_tls": true
},
"callerai": {
"api_url": "${CALLERAI_API_URL:http://localhost:8080}",
"api_key": "${CALLERAI_API_KEY:}",
"timeout_sec": 30
},
"cors": {
"enabled": true,
"origins": ["*"],
"methods": ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
"headers": ["Authorization", "Content-Type", "X-Requested-With"]
},
"rate_limit": {
"enabled": true,
"requests_per_minute": 200
}
}
Production Settings:
http.bind_address to 127.0.0.1 (use Nginx for external access)rate_limit.requests_per_minute based on expected trafficcors.origins to specific domains for securityTwo systemd services are installed:
# Enable services to start on boot
sudo systemctl enable smartbotic-database
sudo systemctl enable smartbotic-microbit
# Start database first
sudo systemctl start smartbotic-database
# Wait a moment, then start microbit
sleep 2
sudo systemctl start smartbotic-microbit
Or start both:
sudo systemctl start smartbotic-database smartbotic-microbit
# Check service status
sudo systemctl status smartbotic-database
sudo systemctl status smartbotic-microbit
# View recent logs
sudo journalctl -u smartbotic-database -n 50 --no-pager
sudo journalctl -u smartbotic-microbit -n 50 --no-pager
# Follow logs in real-time
sudo journalctl -u smartbotic-microbit -f
sudo systemctl stop smartbotic-microbit
sudo systemctl stop smartbotic-database
# After configuration changes
sudo systemctl restart smartbotic-microbit
# Or restart both
sudo systemctl restart smartbotic-database smartbotic-microbit
Service files are located at:
/etc/systemd/system/smartbotic-database.service/etc/systemd/system/smartbotic-microbit.serviceExample microbit service file:
[Unit]
Description=Smartbotic Microbit Service
After=network.target smartbotic-database.service
Requires=smartbotic-database.service
[Service]
Type=simple
User=smartbotic
Group=smartbotic
WorkingDirectory=/var/lib/smartbotic/microbit
EnvironmentFile=/etc/smartbotic/smartbotic.env
ExecStart=/opt/smartbotic/bin/smartbotic-microbit --config /etc/smartbotic/microbit.json
Restart=on-failure
RestartSec=5
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
Use the provided setup script:
# Install Nginx if not already installed
sudo apt install nginx certbot python3-certbot-nginx
# Run the setup script
sudo /opt/smartbotic/bin/smartbotic-setup-nginx \
--domain smartbotic.example.com \
--email admin@example.com
This script:
Create /etc/nginx/sites-available/smartbotic:
# Redirect HTTP to HTTPS
server {
listen 80;
listen [::]:80;
server_name smartbotic.example.com;
location /.well-known/acme-challenge/ {
root /var/www/html;
}
location / {
return 301 https://$server_name$request_uri;
}
}
# HTTPS server
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name smartbotic.example.com;
# SSL certificates (use certbot to obtain)
ssl_certificate /etc/letsencrypt/live/smartbotic.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/smartbotic.example.com/privkey.pem;
# SSL configuration
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
# Security headers
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
# Logging
access_log /var/log/nginx/smartbotic_access.log;
error_log /var/log/nginx/smartbotic_error.log;
# Proxy settings
client_max_body_size 10M;
# API endpoints
location /api/ {
proxy_pass http://127.0.0.1:8090;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
}
# Static files (WebUI)
location / {
proxy_pass http://127.0.0.1:8090;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Enable the site:
sudo ln -s /etc/nginx/sites-available/smartbotic /etc/nginx/sites-enabled/
sudo nginx -t # Test configuration
sudo systemctl reload nginx
# Install certbot
sudo apt install certbot python3-certbot-nginx
# Obtain certificate
sudo certbot --nginx -d smartbotic.example.com --email admin@example.com --agree-tos
# Certbot will automatically configure Nginx for HTTPS
# Certificates auto-renew via cron
# Allow SSH, HTTP, and HTTPS
sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow https
# Enable firewall
sudo ufw enable
# Verify rules
sudo ufw status
Do NOT expose these ports:
Ensure proper permissions:
# Configuration files (readable by service user)
sudo chown root:smartbotic /etc/smartbotic/*.json
sudo chmod 640 /etc/smartbotic/*.json
sudo chmod 640 /etc/smartbotic/smartbotic.env
# Data directories (writable by service user)
sudo chown -R smartbotic:smartbotic /var/lib/smartbotic
sudo chmod 750 /var/lib/smartbotic
# Log directories
sudo chown -R smartbotic:smartbotic /var/log/smartbotic
sudo chmod 750 /var/log/smartbotic
Important secrets to protect:
JWT_SECRET: Used for token signingSMTP_PASSWORD: Email server passwordCALLERAI_API_KEY: CallerAI API keyBest practices:
# Application logs
/var/log/smartbotic/database.log
/var/log/smartbotic/microbit.log
# Systemd journal
sudo journalctl -u smartbotic-database
sudo journalctl -u smartbotic-microbit
# Nginx logs
/var/log/nginx/smartbotic_access.log
/var/log/nginx/smartbotic_error.log
Configure log rotation in /etc/logrotate.d/smartbotic:
/var/log/smartbotic/*.log {
daily
rotate 14
compress
delaycompress
missingok
notifempty
create 0640 smartbotic smartbotic
sharedscripts
postrotate
systemctl reload smartbotic-microbit > /dev/null 2>&1 || true
endscript
}
Check service health:
# Check if services are running
sudo systemctl is-active smartbotic-database
sudo systemctl is-active smartbotic-microbit
# Test API endpoint
curl -f http://localhost:8090/api/v1/settings || echo "Service unhealthy"
# Check database connection
sudo journalctl -u smartbotic-microbit | grep "Connected to database"
Consider integrating:
What to backup:
/var/lib/smartbotic/database/storage/etc/smartbotic//etc/smartbotic/smartbotic.envBackup script example:
#!/bin/bash
BACKUP_DIR="/backup/smartbotic"
DATE=$(date +%Y%m%d-%H%M%S)
# Stop services for consistent backup
sudo systemctl stop smartbotic-microbit
sudo systemctl stop smartbotic-database
# Create backup
sudo mkdir -p "$BACKUP_DIR"
sudo tar -czf "$BACKUP_DIR/smartbotic-$DATE.tar.gz" \
/var/lib/smartbotic/database/storage \
/etc/smartbotic/
# Restart services
sudo systemctl start smartbotic-database
sudo systemctl start smartbotic-microbit
# Clean old backups (keep last 30 days)
find "$BACKUP_DIR" -name "smartbotic-*.tar.gz" -mtime +30 -delete
Automated backups with cron:
# Add to crontab: daily backup at 2 AM
0 2 * * * /usr/local/bin/smartbotic-backup.sh
To restore from backup:
# Stop services
sudo systemctl stop smartbotic-microbit smartbotic-database
# Restore files
sudo tar -xzf /backup/smartbotic/smartbotic-YYYYMMDD-HHMMSS.tar.gz -C /
# Fix permissions
sudo chown -R smartbotic:smartbotic /var/lib/smartbotic
# Start services
sudo systemctl start smartbotic-database smartbotic-microbit
Check logs:
sudo journalctl -u smartbotic-microbit -n 100 --no-pager
Common issues:
Database not running:
sudo systemctl start smartbotic-database
Configuration error:
# Validate JSON config
jq . /etc/smartbotic/microbit.json
Port already in use:
sudo netstat -tuln | grep 8090
# Change port in config or stop conflicting service
Permission errors:
sudo chown -R smartbotic:smartbotic /var/lib/smartbotic
Check database service:
sudo systemctl status smartbotic-database
sudo journalctl -u smartbotic-database -n 50
Verify port is listening:
sudo netstat -tuln | grep 9004
Check static files:
ls -la /var/lib/smartbotic/microbit/webui/
Verify Nginx configuration:
sudo nginx -t
sudo systemctl status nginx
Test SMTP configuration:
# Use API endpoint
curl -X POST http://localhost:8090/api/v1/settings/test-smtp \
-H "Authorization: Bearer TOKEN" \
-H "Content-Type: application/json" \
-d '{"to_email":"test@example.com"}'
Check logs for SMTP errors:
sudo journalctl -u smartbotic-microbit | grep -i smtp
Backup current installation:
sudo /usr/local/bin/smartbotic-backup.sh
Download new packages:
wget https://releases.smartbotics.ai/smartbotic-microbit-NEW_VERSION.tar.gz
Stop services:
sudo systemctl stop smartbotic-microbit smartbotic-database
Install new packages:
sudo ./packaging/scripts/install.sh smartbotic-*.tar.gz
Review configuration changes:
# Check for new .new config files
ls -la /etc/smartbotic/*.new
# Merge changes if needed
diff /etc/smartbotic/microbit.json /etc/smartbotic/microbit.json.new
Restart services:
sudo systemctl start smartbotic-database smartbotic-microbit
Verify upgrade:
sudo journalctl -u smartbotic-microbit -n 50
curl -f http://localhost:8090/api/v1/settings
If upgrade fails:
# Stop services
sudo systemctl stop smartbotic-microbit smartbotic-database
# Restore from backup
sudo tar -xzf /backup/smartbotic/smartbotic-YYYYMMDD.tar.gz -C /
# Start services
sudo systemctl start smartbotic-database smartbotic-microbit
Increase file descriptor limits for the service user:
# Edit /etc/security/limits.conf
smartbotic soft nofile 65536
smartbotic hard nofile 65536
For high-traffic deployments, consider:
For high concurrency:
worker_processes auto;
worker_connections 2048;