systemd: A dependency job failed

Fix the systemd dependency job failure when a required or wanted unit fails to start.

systemd: A dependency job failed

systemd produces "A dependency job for {service} failed" when a unit listed in Requires= or BindsTo= cannot start.

When systemd Produces This Error

systemd reports this error when a hard dependency (specified with Requires= or BindsTo=) fails to start. systemd cancels the dependent service and surfaces the dependency failure.

What Causes "A dependency job failed" in systemd

A service configured with Requires=postgresql.service fails if PostgreSQL cannot start. systemd propagates the failure — if the required unit fails, the requesting unit fails too. This differs from Wants=, which allows the requesting unit to start even if the wanted unit fails.

How to Fix "A dependency job failed" in systemd

  1. Identify which dependency failed:

    sudo systemctl status myapp.service
    sudo journalctl -u myapp.service --no-pager | grep -i "depend"
  2. Check and fix the failing dependency:

    sudo systemctl status postgresql.service
    sudo journalctl -u postgresql.service -b
  3. If the dependency is optional, change Requires= to Wants= in the unit file. Wants= starts the dependency but does not fail the main service if the dependency fails.

  4. Restart both services after fixing the dependency:

    sudo systemctl daemon-reload
    sudo systemctl restart postgresql.service
    sudo systemctl restart myapp.service

How to Verify the Fix

Both services should show Active: active (running) in systemctl status.