Production Deployment
This guide covers deploying tenement to production with HTTPS, automatic restarts, and proper security.
Quick Production Setup
Section titled “Quick Production Setup”The fastest path to production on a Linux server:
# Install tenementcargo install tenement-cli
# Create configcat > /etc/tenement/tenement.toml << 'EOF'[settings]data_dir = "/var/lib/tenement"
[service.api]command = "./my-api"socket = "/tmp/tenement/api-{id}.sock"health = "/health"
[instances]api = ["prod"]EOF
# Install as systemd service and generate Caddy configten install --caddy --domain example.comThis creates:
- A systemd service (
tenement.service) - A Caddyfile with automatic HTTPS
- Proper file permissions and security hardening
Option 1: Built-in TLS
Section titled “Option 1: Built-in TLS”tenement can handle TLS directly using Let’s Encrypt.
ten serve --tls --domain example.com --email admin@example.comHow It Works
Section titled “How It Works”- tenement requests certificates from Let’s Encrypt
- HTTP-01 challenge verifies domain ownership
- Certificates auto-renew before expiry
- All traffic is encrypted
TLS Status
Section titled “TLS Status”Check certificate status:
curl https://example.com/api/tls/status{ "enabled": true, "domain": "example.com", "staging": false, "https_port": 443, "http_port": 80, "status": "running"}Wildcard Certificates (DNS-01)
Section titled “Wildcard Certificates (DNS-01)”For wildcard subdomain routing (*.example.com), use Caddy with DNS challenge:
# Generate Caddyfile with DNS provider supportten caddy --domain example.com --dns-provider cloudflare
# Set DNS token via environment for Caddyexport CF_API_TOKEN=$CF_API_TOKENcaddy run --config /etc/caddy/CaddyfileSupported DNS providers (via Caddy):
cloudflare- Cloudflare API tokenroute53- AWS Route53 (uses AWS credentials)digitalocean- DigitalOcean API token
The DNS-01 challenge creates a TXT record to prove domain ownership, enabling wildcard certificates.
Option 2: Caddy Reverse Proxy
Section titled “Option 2: Caddy Reverse Proxy”Use Caddy for TLS termination with tenement handling routing.
Generate Caddyfile
Section titled “Generate Caddyfile”ten caddy --domain example.com --output /etc/caddy/CaddyfileGenerated Caddyfile:
{ email admin@example.com}
example.com { reverse_proxy unix//tmp/tenement/tenement.sock}
*.example.com { reverse_proxy unix//tmp/tenement/tenement.sock}Install Caddy
Section titled “Install Caddy”# Debian/Ubuntuapt install caddy
# Or with ten caddy --installten caddy --domain example.com --installStart Services
Section titled “Start Services”# tenement listens on a port (Caddy will proxy to it)ten serve --port 8080
# Caddy handles TLS and proxies to tenementsystemctl start caddyWhy Caddy?
Section titled “Why Caddy?”- Automatic HTTPS with Let’s Encrypt
- Wildcard certificates with DNS challenge
- Zero-downtime certificate renewals
- Battle-tested TLS configuration
Systemd Service
Section titled “Systemd Service”Install Service
Section titled “Install Service”ten installThis creates /etc/systemd/system/tenement.service:
[Unit]Description=tenement process hypervisorAfter=network.target
[Service]Type=simpleExecStart=/usr/local/bin/ten serveRestart=alwaysRestartSec=5
# Security hardeningNoNewPrivileges=yesProtectSystem=strictProtectHome=yesReadWritePaths=/var/lib/tenement /tmp/tenementPrivateTmp=yes
[Install]WantedBy=multi-user.targetService Commands
Section titled “Service Commands”# Start/stop/restartsystemctl start tenementsystemctl stop tenementsystemctl restart tenement
# View logsjournalctl -u tenement -f
# Enable on bootsystemctl enable tenementUninstall
Section titled “Uninstall”ten uninstallRemoves the systemd service file and disables the service.
All-in-One Setup
Section titled “All-in-One Setup”Install tenement with systemd + Caddy + TLS in one command:
ten install --caddy --domain example.com --dns-provider cloudflareWhat this does:
- Creates systemd service for tenement
- Generates Caddyfile with wildcard support
- Configures DNS-01 challenge for wildcards
- Enables both services on boot
| Flag | Description |
|---|---|
--caddy | Generate Caddyfile |
--domain <domain> | Domain for routing |
--email <email> | Email for Let’s Encrypt |
--dns-provider <provider> | DNS provider for Caddy wildcard certs |
--install | Also install Caddy (apt) |
--systemd | Enable systemd services on boot |
--dry-run | Show what would be done |
File Locations
Section titled “File Locations”| File | Purpose |
|---|---|
/etc/tenement/tenement.toml | Main configuration |
/var/lib/tenement/ | Instance data directories |
/tmp/tenement/ | Unix sockets |
/etc/systemd/system/tenement.service | systemd unit |
/etc/caddy/Caddyfile | Caddy configuration |
Security Considerations
Section titled “Security Considerations”Firewall
Section titled “Firewall”Only expose ports 80 and 443:
ufw allow 80/tcpufw allow 443/tcpufw enableAPI Authentication
Section titled “API Authentication”Generate and use auth tokens:
# Generate tokenten token-gen
# Use token for API callscurl -H "Authorization: Bearer $TOKEN" https://example.com/api/instancesResource Limits
Section titled “Resource Limits”Prevent runaway processes:
[service.api]memory_limit_mb = 256cpu_shares = 100storage_quota_mb = 100Monitoring
Section titled “Monitoring”Prometheus Metrics
Section titled “Prometheus Metrics”Scrape https://example.com/metrics for:
- Instance counts and states
- Request latencies
- Memory/CPU per instance
- Storage usage
Health Endpoint
Section titled “Health Endpoint”curl https://example.com/healthReturns 200 if the server is healthy.
Next Steps
Section titled “Next Steps”- Configuration Reference - Full TOML options
- Deployments - Blue-green and canary patterns
- Troubleshooting - Common issues