Courseiva
Service Configuration →easyMultiple Choice

LFCS Service Configuration Practice Question

A system administrator is managing a web application running as a systemd service on a new Linux server. The application requires a specific environment variable, DATABASE_URL, to be set before starting. The administrator has created a custom service unit file at /etc/systemd/system/webapp.service with the following content:

[Unit]

Description=Web Application Service

[Service]

ExecStart=/usr/local/bin/webapp Restart=on-failure

The administrator prefers to keep configuration separate from the unit file for easier updates. The service fails to start. Upon investigation, the administrator notices that the DATABASE_URL variable is not being passed to the process. What is the most appropriate course of action to ensure the environment variable is correctly set?

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

Add EnvironmentFile=/etc/webapp.env in the [Service] section and place the variable in that file

Using EnvironmentFile allows the administrator to keep the DATABASE_URL variable in a separate file, which can be updated without modifying the unit file. Option A hardcodes the variable in the unit file, reducing flexibility. Option C only sets the variable in the current shell session and does not persist for the service. Option D modifies ExecStart but is less standard and less maintainable than using EnvironmentFile.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    Add an Environment directive in the [Service] section: Environment=DATABASE_URL=value

    Why it's wrong here

    Placing the value directly in the unit file contradicts the stated requirement to keep configuration separate, so updates would force unit edits and a daemon-reload. The Environment directive suits fixed, non-sensitive values shared by all instances; here an EnvironmentFile pointing at an external file supplies DATABASE_URL while preserving separation.

  • ✓

    Add EnvironmentFile=/etc/webapp.env in the [Service] section and place the variable in that file

    Why this is correct

    EnvironmentFile= satisfies the requirement to keep configuration outside the unit file, letting systemd read DATABASE_URL from /etc/webapp.env and inject it into the process environment at start. This is the native mechanism for separating variables from unit definitions.

  • ✗

    Export the DATABASE_URL variable in the shell before running systemctl start webapp

    Why it's wrong here

    systemd does not inherit variables exported in an interactive shell; the manager reads its own environment, so the service still starts without DATABASE_URL. It is tempting because exporting before launching a process works for foreground commands, and it would succeed if the service were started manually from that same shell session.

  • ✗

    Modify the ExecStart line to: ExecStart=/usr/bin/env DATABASE_URL=value /usr/local/bin/webapp

    Why it's wrong here

    Wrapping ExecStart in /usr/bin/env hardcodes the value into the unit file, defeating the stated goal of separating configuration from the unit. It is tempting because env is a familiar shell idiom for injecting variables, and it would work for a one-off command where no external configuration file is wanted.

About these practice questions

One of 406 original LFCS practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This LFCS practice question is part of Courseiva's free Linux Foundation certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the LFCS exam.