# Systemd service for Celery ML model workers. # # Separate from crop-ai-api.service deliberately — see # docs/architecture.md for why web serving and ML compute are split # into independent process groups that scale independently. # # Install: sudo cp this file to /etc/systemd/system/crop-ai-worker.service # then: # sudo systemctl daemon-reload # sudo systemctl enable crop-ai-worker # sudo systemctl start crop-ai-worker # # Logs: journalctl -u crop-ai-worker -f [Unit] Description=AI Crop Decision Support System - Celery ML model workers After=network.target postgresql.service redis-server.service crop-ai-api.service Wants=postgresql.service redis-server.service [Service] Type=simple User=cropai Group=cropai WorkingDirectory=/opt/crop-ai-system EnvironmentFile=/opt/crop-ai-system/.env # --concurrency controls how many tasks run in parallel per worker # process. Each loaded model set (6 models, ~tens of MB combined for # the tree-based models, SARIMAX dicts scale with district/crop-pair # count) lives once per process — concurrency=2 is a safe starting # point for a modest VPS; raise it once you've measured actual memory # headroom under load. ExecStart=/opt/crop-ai-system/venv/bin/celery -A app.workers.celery_app worker \ --loglevel=info \ --concurrency=2 \ --max-tasks-per-child=200 \ --logfile=/opt/crop-ai-system/logs/celery-worker.log Restart=on-failure RestartSec=5 NoNewPrivileges=true PrivateTmp=true ProtectSystem=strict ReadWritePaths=/opt/crop-ai-system/logs [Install] WantedBy=multi-user.target