A system administrator needs to create a new `systemd` target named `app-maintenance.target` that should be reached after the `multi-user.target` but before any graphical desktop environment. This target should depend on a custom service `app-setup.service` to ensure it runs before any maintenance scripts. Which `systemd` unit file configuration snippet is most appropriate for `app-maintenance.target`?
- A[Unit] Description=Application Maintenance Target Before=multi-user.target After=graphical.target Requires=app-setup.service
- B[Unit] Description=Application Maintenance Target After=multi-user.target Before=graphical.target Wants=app-setup.service
- C[Unit] Description=Application Maintenance Target Requires=multi-user.target After=graphical.target BindsTo=app-setup.service
- D[Unit] Description=Application Maintenance Target After=graphical.target Requires=app-setup.service
Show answer & explanationAnswer & explanation
Correct answer: B. [Unit] Description=Application Maintenance Target After=multi-user.target Before=graphical.target Wants=app-setup.service
To achieve the desired order: `After=multi-user.target` ensures it starts after the basic multi-user environment. `Before=graphical.target` ensures it runs before any desktop environment. `Wants=app-setup.service` creates a weak dependency, meaning systemd will try to start `app-setup.service` when `app-maintenance.target` is activated, but it won't fail the target if the service doesn't start (a stronger `Requires=` could also be used, but `Wants=` is often sufficient for custom services that are prerequisites).
Why the other options are wrong
- A. `Before=multi-user.target` is incorrect as the target needs to run *after* `multi-user.target`. `After=graphical.target` is also incorrect.
- C. `After=graphical.target` is incorrect as the target needs to run *before* the graphical environment. `BindsTo=` creates a strong dependency that stops the target if the service stops, which is usually too strong for a simple prerequisite.
- D. `After=graphical.target` is incorrect, and while `Requires=` establishes a dependency, the ordering is wrong.
systemd Target Unit Dependencies
`systemd` targets are used to group units and define synchronization points during boot or system state changes. Dependencies control their activation order.
- `After=` and `Before=` define ordering, not strict dependencies.
- `Wants=` defines a weak dependency: unit will be started, but target won't fail if it doesn't.
- `Requires=` defines a strong dependency: unit will be started, and target will fail if it doesn't.
Memory trick: ORDER (After/Before) your WANTS and REQUIRES for a perfect target!