Case study, under NDA

The service that refused to start

A production Django service for ran perfectly by hand and failed every time systemd started it.

  • Django
  • PostgreSQL
  • systemd
  • Linux
Service
Backend and APIs
Our part
Diagnosis and fix
Team
team size
Time taken
duration
Result
The service starts on its own, with every setting written down

01

The symptom

The app lived in a Python virtual environment. A developer could activate it, start Django, and everything worked. Under systemd, the same app stopped during startup with a PostgreSQL connection failure.

That pattern is a useful clue. When code works in your shell and fails in a service, the code is rarely the problem. The environment around it is different.

02

How we found it

  1. Step 1Compared the two environments

    We checked what the app could see in a login shell, then what it could see as a service.

  2. Step 2Followed the failed connection

    The database did not run on this machine. It ran on a separate host.

  3. Step 3Found the missing setting

    systemd starts services with a clean environment. The database host set in the shell never reached the app.

03

The fix

The fix was small. The hard part was knowing where to look.

We passed the settings to the service explicitly, instead of relying on anything inherited from a shell.

[Service]
EnvironmentFile=/etc/app/app.env
ExecStart=/srv/app/venv/bin/gunicorn app.wsgi

NDA

What we hid, and what we kept

Hidden

The name, the hosts, the paths

The company name, hostnames, paths and anything that could identify the product. The paths above are examples.

Kept

The problem, the trace, the lesson

The real problem, the way we traced it and the lesson. You can judge how we think without seeing private code.

Got a bug nobody can explain?

Those are our favorite first tasks. They are small, clear and easy to judge.