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 →
- In the app unit:
[Unit]
Requires=postgresql.service
After=postgresql.service
- If "started" isn't the same as "accepting connections", add a readiness check:
ExecStartPre=/usr/bin/pg_isready -h localhost -t 30
- 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).
More on Processes, services and systemd
Your team has a Python API that someone starts with `nohup python app.py &`. Make it a proper service running as a non-root user.BeginnerThe service you created must bind to port 443, but it runs as a non-root user. How?BeginnerYou need to change one setting (memory limit) in a vendor-supplied unit file without editing it. How?BeginnerA service keeps crashing and systemd stops restarting it after a few attempts. How do you tune this?IntermediateA long-running app must reload its config without dropping connections. How do you wire this into systemd?IntermediateA script needs to run once at boot after networking, then exit. How do you do it with systemd?Beginner