Debian Packaging: From Source to Repository

systemd, Configuration, and Permissions

A practical Debian packaging course lesson covering systemd, configuration, and permissions.

systemd, Configuration, and Permissions

A Debian package must install files in appropriate locations and assign sensible permissions. Some packages also install configuration files or systemd units.

Syspeek is a command-line utility, not a background service. That distinction matters: we should not create a systemd service simply because packaging supports one.

In this lesson, we will review standard filesystem locations, permissions, configuration handling, and when systemd integration is appropriate.

Learning Objectives

  • Choose appropriate filesystem locations.
  • Set executable and configuration-file permissions.
  • Understand Debian configuration-file handling.
  • Recognize when a systemd unit is appropriate.
  • Avoid unnecessary service integration.

1. Choose the Correct Installation Paths

For Syspeek, the main executable belongs in:

1
/usr/bin/syspeek

This is already handled by our rules file:

1
2
override_dh_auto_install:
	install -D -m 0755 syspeek debian/syspeek/usr/bin/syspeek

Common filesystem locations include:

Location Typical use
/usr/bin User-facing commands
/usr/sbin System administration commands
/usr/share Architecture-independent shared data
/etc Host-specific configuration
/var/lib Persistent application state
/var/log Log files
/usr/lib/systemd/system Packaged systemd unit files

Do not place ordinary application binaries in /etc or /var.

2. Understand File Permissions

The executable should normally be installed with mode 0755:

  • Owner can read, write, and execute.
  • Group can read and execute.
  • Others can read and execute.

A configuration file should usually be readable but not executable, often 0644, unless it contains secrets that require stricter permissions.

Inspect staged files after a build:

1
find debian/syspeek -type f -exec stat -c '%a %n' {} \;

3. Configuration Files

If an application has administrator-managed configuration, it commonly belongs under /etc.

Debian packages use special handling for configuration files so that local administrator changes are not silently overwritten during upgrades.

For example, a package may use a debian/package.conffiles file or install a file through debhelper mechanisms that mark it as a conffile.

Syspeek does not currently need a configuration file. Do not add an empty or unused configuration file just to demonstrate the mechanism.

4. When Should a Package Install a systemd Unit?

A systemd unit is appropriate for software that runs as a service or performs scheduled/background work.

Examples include:

  • A network daemon.
  • A monitoring agent.
  • A background worker.
  • A service that exposes an API.

Syspeek is an interactive command-line program. It runs when the user invokes it and then exits. Therefore, a systemd service would add complexity without providing a useful function.

This is an important packaging lesson: package only what the software actually needs.

5. A Service Unit Example

For reference, a long-running application might install a unit similar to:

1
2
3
4
5
6
7
8
9
10
11
12
[Unit]
Description=Example background service
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/example-daemon
Restart=on-failure
User=example

[Install]
WantedBy=multi-user.target

A real package must also consider service users, writable directories, sandboxing, restart behavior, and Debian’s systemd helper integration.

Do not copy this example into Syspeek; it is illustrative only.

6. Verify the Package’s File Layout

After building Syspeek:

1
dpkg-deb --contents ../syspeek_*.deb

Confirm that the executable is installed under /usr/bin.

After installing the package, inspect permissions:

1
stat -c '%a %U:%G %n' /usr/bin/syspeek

7. What We Learned

We selected the correct location and permissions for the Syspeek executable. We also examined configuration-file handling and learned why a command-line utility does not need a systemd service.

Exercises

  1. Explain the difference between /usr/bin and /etc.
  2. Inspect the permissions of /usr/bin/syspeek.
  3. Find a Debian package that installs a systemd service and inspect its unit file.
  4. Explain why Syspeek should not start automatically at boot.

What’s Next?

Next, we will learn how Debian source packages manage patches and how quilt records changes to upstream source code.

Next: Patches and Source Management