Interview Prep/Linux/Processes, services and systemd

A service depends on a database on the same host and fails at boot because the DB isn't ready. How do you fix the ordering?

IntermediateScenarioProcesses, services and systemd
Answer

Situation read → Ordering vs requirement vs readiness.

What I'd do →

  1. In the app unit:
[Unit]
Requires=postgresql.service
After=postgresql.service
  1. If "started" isn't the same as "accepting connections", add a readiness check:
ExecStartPre=/usr/bin/pg_isready -h localhost -t 30
  1. Make the app itself retry connections; that's the real fix.

Why → After= only orders; Requires=/Wants= pulls the unit in. Neither waits for the DB to be ready unless the DB unit uses Type=notify.

Interview tip → Explain the difference between Wants (soft) and Requires (hard).

All Linux questions Roadmap: Linux

More on Processes, services and systemd