Ubuntu 26.04 Tutorial / Change Service Configuration with Validation and Drop-ins

Change service configuration by recording the original and effective state, introducing a separate override, validating it, and checking real behavior. Reloading systemd units, reloading application configuration, and restarting a process are different operations.

Locate the original unit and drop-ins

Identify the real unit and inspect it with systemctl cat and systemctl show -p FragmentPath -p DropInPaths. Direct edits to packaged units under /usr/lib/systemd/system can be replaced during updates; separate local changes under /etc/systemd/system.

Create an independent lab service

This dedicated-VM lab leaves real server applications alone. If ubuntu-course-lab.service exists, choose a different name consistently. Noclobber prevents overwriting the existing file; stop if creation fails.

(
set -eu
sudo sh -c 'set -C; cat > /etc/systemd/system/ubuntu-course-lab.service' <<'EOF'
[Unit]
Description=Ubuntu course configuration lab

[Service]
Type=oneshot
Environment=LAB_MODE=baseline
ExecStart=/usr/bin/printenv LAB_MODE
EOF
sudo systemd-analyze verify /etc/systemd/system/ubuntu-course-lab.service
sudo systemctl daemon-reload
sudo systemctl start ubuntu-course-lab.service
journalctl -u ubuntu-course-lab.service --since '5 minutes ago' --no-pager
)

Check for baseline in the journal and a successful result. A Type=oneshot unit may become inactive after successful completion; inactive alone is not a failure. Inspect systemctl show ubuntu-course-lab.service -p Result as well.

Change one value through a drop-in

(
set -eu
sudo mkdir -p /etc/systemd/system/ubuntu-course-lab.service.d
sudo sh -c 'set -C; cat > /etc/systemd/system/ubuntu-course-lab.service.d/10-lab.conf' <<'EOF'
[Service]
Environment=LAB_MODE=changed
EOF
sudo systemd-analyze verify /etc/systemd/system/ubuntu-course-lab.service
sudo systemctl daemon-reload
sudo systemctl start ubuntu-course-lab.service
journalctl -u ubuntu-course-lab.service --since '5 minutes ago' --no-pager
)

Leave the original unit value intact and override it with changed. Compare merged configuration and the new execution log. Unit verification does not validate every application-specific setting, file access, or network response.

Distinguish three reload operations

Command Role
systemctl daemon-reload Reloads systemd unit and dependency definitions
systemctl reload unit Invokes the application’s supported reload operation
systemctl restart unit Stops and starts the process

For example, validate Nginx configuration with nginx -t before its supported reload. Reloading systemd alone does not change an existing process’s environment. Choose the application operation after reviewing downtime and fresh-connection tests.

The systemd.unit reference explains unit lookup paths and drop-in precedence.

Reverse only this change

(
set -eu
sudo rm -- /etc/systemd/system/ubuntu-course-lab.service.d/10-lab.conf
sudo systemctl daemon-reload
sudo systemctl start ubuntu-course-lab.service
journalctl -u ubuntu-course-lab.service --since '5 minutes ago' --no-pager
)

Confirm baseline appears again. This rm removes only the dedicated drop-in created for the exercise. Avoid a broad systemctl revert that also removes another administrator’s changes. To clean up the unit itself, verify its ownership and inactive state, remove only that lab file, and reload systemd.