systemd & process supervision for Django in production
Keeping Gunicorn, Celery, and scheduled jobs running: systemd units, environment files, timers, and Supervisor.
Something has to start Gunicorn and Celery at boot, restart them when they crash, and give them their environment. On most Linux servers that is systemd; Supervisor is the older alternative.
The guides cover writing units, loading environment files, scheduling commands with timers, and fixing services that fail to start.
Set it up
Guides that take this from nothing to running in production.
- How to Configure systemd for Gunicorn and Django
Running Gunicorn manually for a Django app is fragile. If your SSH session closes, the process can stop.
- Schedule Django Management Commands with Cron or systemd Timers
Run Django management commands on a schedule with systemd timers or cron: environment loading, overlap locks, logging, and failure alerts.
- Run Django and Celery with Supervisor
Supervise Gunicorn and Celery for Django with Supervisor: program configs, environment variables, stop signals and timeouts, log rotation, group restarts, and when to prefer systemd.
- Run Celery Workers with systemd for Django
Running Celery workers manually in production is fragile. If you start a worker from a shell and disconnect, the process may stop.
- Deploy Django with Podman and Quadlet
Run Django in rootless Podman containers managed by systemd with Quadlet: container, network, and volume units, Podman secrets, health checks, and auto-updates.
- Run Django Scheduled Jobs as Kubernetes CronJobs
Schedule Django management commands on Kubernetes with CronJobs: concurrencyPolicy Forbid, time zones, startingDeadlineSeconds, history limits, resource requests, secrets, and monitoring missed or failed runs, compared with Celery Beat.
Run it well
Tuning, reliability, and operations once it works.
- Monitor Django Scheduled Jobs With Heartbeat Checks
Detect Django scheduled jobs that fail or silently stop running: heartbeat (dead man's switch) monitoring with Healthchecks.io, Cronitor, or your own endpoint, pinging start and success from management commands, Celery Beat, and Kubernetes CronJobs.
Fix it
Errors and symptoms, each traced to a cause and a fix.
- Fix a Gunicorn systemd Service That Fails to Start
Fix a Gunicorn service for Django that systemd cannot start: status codes 203/EXEC, 200/CHDIR, 217/USER, environment files, socket directories, and restart loops.
- Fix systemd EnvironmentFile Variables Not Reaching Django
Fix Django settings that miss variables from a systemd EnvironmentFile: file syntax rules, the '-' prefix, quoting, no variable expansion, daemon-reload versus restart, and checking a running process.
- Fix a Django Management Command That Fails in Cron
Fix Django management commands that work in your shell but fail or do nothing in cron: use the virtualenv Python with full paths, load environment variables and settings, set the working directory, and capture output and errors.
- Fix Nginx "connect() to unix:/run/gunicorn.sock Failed (2: No Such File or Directory)"
Fix the Nginx 502 error connect() to unix:/run/gunicorn.sock failed (2: No such file or directory): start the Gunicorn socket or service, match the socket path in Nginx and systemd, and stop PrivateTmp and RuntimeDirectory from hiding the file.
Learning paths through this topic
- Your first production deployment on a VPSFrom a fresh Ubuntu server to a Django site on HTTPS, with the settings and checks that keep it safe.
- Background jobs with CelerySet up workers and Beat, keep them supervised, route and tune them, and make tasks safe to retry.
- Django on KubernetesRun Django on a cluster with config, ingress, probes, jobs, graceful shutdown, and autoscaling, then package it with Helm and GitOps.