Debian 13 Tutorial / Manage systemd Services and Apply Drop-in Changes

In Debian 13, active indicates the current activation state of a systemd service, and enabled shows whether it is enabled to start at boot. If you have modified the configuration file or drop-in, use daemon-reload to make the systemd manager reread unit definitions, and any changed execution commands must be followed by a service restart and verification of the actual response.

Distinguish Runtime State from Startup Configuration

systemd manages tasks like services, timers, and mounts as units. This tutorial creates a loopback-only Python HTTP service in a Debian 13 systemd 257 environment, displaying its status and comparing processes, ports, and responses. It is a practice for manipulating general system services and does not imply restarting all existing services in the same way.

Commands Target to change Result of this practice
start / stop Currently running service Start or stop the service without changing its startup links
enable / disable Unit startup links Add or remove startup links without stopping a running process
enable --now Startup configuration and runtime state Enable startup links and also start the service now
daemon-reload Unit settings read by systemd Reread unit definitions without replacing the HTTP process
restart Service process Apply new execution command by stopping and starting

Even if enabled, the service can fail, and even if disabled, it can be started manually or executed at the request of another unit. The target specified as [Install] in this example is the reference for startup links. There are services that are static units without installation connections or that start via sockets, so do not determine the boot behavior of all services based solely on whether they are enabled. The detailed command meanings can be found in the Debian 13 systemctl manual.

Check the Dedicated Lab’s Initial State

Use the sudo-capable lfstudent account, Python 3 and curl. If it is a different account, adjust the User of the service below and the document path to match the actual account. The Python HTTP server is for practice purposes and does not need to be exposed to the host or LAN, so it listens only on 127.0.0.1. No NAT forwarding or firewall changes are required.

id lfstudent
python3 --version
curl --version
systemctl --version
systemctl show lf-http17.service -p LoadState
sudo ss -lntp 'sport = :8080'
sudo ss -lntp 'sport = :8082'
ls -ld /home/lfstudent/lf-http17 /etc/systemd/system/lf-http17.service.d

The service is LoadState=not-found, neither port has a listening row, and the folder does not exist as the starting condition. The file missing error in the last ls is to check whether that name is empty. If any lab resource already exists, stop here and identify its owner. Do not overwrite it or stop another service. If Python or curl is not installed, review the change list in sudo apt install --no-install-recommends python3 curl to install them.

Create a dedicated file on the terminal logged in as lfstudent.

mkdir /home/lfstudent/lf-http17 &&
printf 'systemd-service-lab\n' > /home/lfstudent/lf-http17/probe.txt

If directory creation fails, the chained printf command is skipped. Stop the lab at that point rather than continuing with the service file. The practice document root is restricted separately, and the entire home directory is not provided. The system service is generally handled by the system administrator, but the HTTP process itself is executed with regular user permissions as shown below in User=lfstudent.

Write and Validate the Complete Service Unit

Open a new file with sudo nano /etc/systemd/system/lf-http17.service and save the entire contents below. You may use another editor, but keep the filename, path, and line structure. Do not overwrite an existing file with a new example.

[Unit]
Description=Local HTTP service for lesson 17

[Service]
Type=exec
User=lfstudent
ExecStart=/usr/bin/python3 -m http.server 8080 --bind 127.0.0.1 --directory /home/lfstudent/lf-http17
Restart=on-failure
RestartSec=2s

[Install]
WantedBy=multi-user.target

Type=exec helps check errors at the stage of starting the executable. However, successful start of the executable does not guarantee that the HTTP listener is ready. Restart=on-failure is a setting to restart on abnormal termination, and it is not an option to revive a service that the administrator has stopped normally.

Do not append & for background execution in ExecStart. systemd directly manages the process by running it in the foreground. Unlike a normal shell command line, pipes and redirection are not automatically handled as shell syntax. Refer to the relevant option in systemd.service documentation for execution methods.

sudo systemd-analyze verify /etc/systemd/system/lf-http17.service
sudo systemctl daemon-reload
systemctl is-enabled lf-http17.service
systemctl is-active lf-http17.service
systemctl cat lf-http17.service

Check the cause if there are any inspection errors or warnings. Even after reading without errors, it hasn't started yet, so disabled and inactive is expected. These two queries return non-zero exit codes depending on the status, so do not simply treat all abnormal exits as installation failures in automation.

Observe active and enabled Separately

First, start the service manually and check the actual file response.

sudo systemctl start lf-http17.service
systemctl is-active lf-http17.service
systemctl is-enabled lf-http17.service
curl --noproxy '*' --retry 5 --retry-connrefused --retry-delay 1 --max-time 10 -fsS http://127.0.0.1:8080/probe.txt
sudo ss -lntp 'sport = :8080'

Expect active and disabled from the state queries, and systemd-service-lab from the HTTP request. The limited retries in curl take into account the short difference for the port to be ready immediately after the process starts. If it continues to fail, do not rely solely on the status and check the cause with sudo journalctl -u lf-http17.service -b --no-pager -n 30.

Enable the startup link, then stop the current process.

sudo systemctl enable lf-http17.service
sudo systemctl stop lf-http17.service
systemctl is-enabled lf-http17.service
systemctl is-active lf-http17.service

enabled and inactive is expected. Stop does not remove the start link at boot. Start the service again, then disable its startup link.

sudo systemctl start lf-http17.service
sudo systemctl disable lf-http17.service
systemctl is-enabled lf-http17.service
systemctl is-active lf-http17.service
curl --noproxy '*' --retry 5 --retry-connrefused --retry-delay 1 --max-time 10 -fsS http://127.0.0.1:8080/probe.txt

disabled and active and the same file response are expected. In this example, disable did not stop the running HTTP process. If immediate stop is desired, use disable --now. In this comparison, leave it in active and disabled state for the subsequent port change.

Change the Port with a Drop-in

A drop-in is a supplementary configuration added to the unit-name.d/ folder next to the original unit file. Instead of directly modifying the /usr/lib/systemd/system/ file provided by the package, administrators generally manage changes as a drop-in of /etc/systemd/system/. This example applies the same method to a manually created unit to distinguish between the original and supplementary files.

systemctl show lf-http17.service -p MainPID -p ExecStart -p FragmentPath -p DropInPaths
sudo install -d /etc/systemd/system/lf-http17.service.d

Record the current MainPID so you can compare it later. Create the drop-in with sudo nano /etc/systemd/system/lf-http17.service.d/20-port.conf.

[Service]
ExecStart=
ExecStart=/usr/bin/python3 -m http.server 8082 --bind 127.0.0.1 --directory /home/lfstudent/lf-http17

An empty ExecStart= is for resetting the previously set execution command and replacing it on the next line. If a second execution command is added without resetting, the intended replacement in this service type will not occur. Drop-ins merge or override differently depending on the option, so not all settings are handled in the same way. systemd.unit's configuration search path and drop-in description are the reference.

sudo systemd-analyze verify /etc/systemd/system/lf-http17.service
sudo systemctl daemon-reload
systemctl cat lf-http17.service
systemctl show lf-http17.service -p MainPID -p ExecStart -p DropInPaths
curl --noproxy '*' --max-time 5 -fsS http://127.0.0.1:8080/probe.txt
curl --noproxy '*' --max-time 3 -fsS http://127.0.0.1:8082/probe.txt

Although the manager now shows 8082 in ExecStart, the MainPID of the running process is the previous value, and 8080 responses continue. Requests to 8082 are expected to fail because nothing is listening there yet. This is the comparison that daemon-reload re-reads the unit definition and is different from restarting the process.

sudo systemctl restart lf-http17.service
systemctl show lf-http17.service -p MainPID -p ActiveState -p SubState -p UnitFileState
sudo ss -lntp 'sport = :8082'
curl --noproxy '*' --retry 5 --retry-connrefused --retry-delay 1 --max-time 10 -fsS http://127.0.0.1:8082/probe.txt
curl --noproxy '*' --max-time 3 -fsS http://127.0.0.1:8080/probe.txt

Check the PID of the restarted process and verify the listener on port 8082 and the file response, and compare whether the previous listener on port 8080 has disappeared. The PID number varies depending on the environment, and it is more important to check the status, listener, and response together than the number itself. The reload command is also a separate action. This unit did not specify ExecReload, etc., so it does not use an unsupported reload as a means to apply settings.

Remove Only the Lab Drop-in and Restore Port 8080

Keep the original service file and delete only the 20-port.conf created this time. Do not use a full revert in this operation, which could erase other supplementary settings.

sudo rm -- /etc/systemd/system/lf-http17.service.d/20-port.conf
sudo rmdir -- /etc/systemd/system/lf-http17.service.d
sudo systemctl daemon-reload
sudo systemctl restart lf-http17.service
systemctl show lf-http17.service -p ExecStart -p DropInPaths
curl --noproxy '*' --retry 5 --retry-connrefused --retry-delay 1 --max-time 10 -fsS http://127.0.0.1:8080/probe.txt
sudo journalctl -u lf-http17.service -b --no-pager -n 20

Restoration is confirmed when DropInPaths is empty, ExecStart again specifies port 8080, and the HTTP request returns the original file. If rmdir fails because it is not empty, first check if there are other files and do not delete the entire folder. The log retains traces of start, stop, and requests, allowing you to verify state transitions.

Diagnose Errors and Remove the Dedicated Service

File path typos or access permission issues may manifest as HTTP request failures or service start failures. Port conflicts can be checked with ss to see if another server is listening. Read the results of systemctl status lf-http17.service --no-pager and the specific errors in the journal and correct them. Running only reset-failed to clear failure records does not solve the underlying cause.

After finishing the practice, stop only the dedicated service, disable automatic startup, and then remove the created files.

sudo systemctl disable --now lf-http17.service
sudo rm -- /etc/systemd/system/lf-http17.service
sudo systemctl daemon-reload
rm -- /home/lfstudent/lf-http17/probe.txt
rmdir -- /home/lfstudent/lf-http17
systemctl show lf-http17.service -p LoadState
sudo ss -lntp 'sport = :8080'
sudo ss -lntp 'sport = :8082'

Check that the unit is not-found and that neither lab port has a listening row. If the service remains in a failed state, first confirm file removal and process termination, then clean only that unit's failure records with sudo systemctl reset-failed lf-http17.service. Keep other service and system logs.