systemd in depth: units, dependencies and socket activation
You learn unit files, dependencies and ordering, drop-in changes, socket and path activation, user services and tmpfiles to production standard.
Level 301 · 20 lessons · 18 practice labs
Lessons
Units
- Unit types: service, socket, timer, path, mount, target
- Where unit files live and their precedence
- Service types: simple, exec, forking, oneshot, notify
- Safe changes with drop-ins: systemctl edit
- Short task: customise a packaged unit without touching it
Dependencies and order
- Requires, Wants, BindsTo and PartOf
- Ordering versus dependency: Before and After
- Defining your own target
- Inspecting the dependency tree: list-dependencies and cycles
- Short task: fix an app that starts before its database and crashes
Activation
- Socket activation: a service that starts on demand
- Path units: triggering when a file changes
- Timers in depth: OnCalendar, Persistent and randomised delay
- Template units: many instances with app@.service
- Short task: move a small service to socket activation
Other tools
- User services and lingering
- systemd-tmpfiles and sysusers
- journald configuration: persistence, size and rate limits
- Restart policies and the watchdog
- Capstone: run a three-part application robustly with systemd
Practice labs
- Find which directory the active unit file comes from: Show which of two unit files with the same name is in effect and why it takes precedence.
- Override a packaged unit with a drop-in: Add an environment variable and a restart rule without touching the packaged unit file and explain why updates will not undo it.
- Run a multi-instance service from a template unit: Start three worker instances on separate ports from one template unit, each reading its own config file.
- Fix a unit timing out on the wrong service type: Correct the Type setting of a service that runs yet hits a start timeout so it matches how the program behaves.
- Add a pre-start check and a stop step: Add a pre-start command that tests the config and a stop command that drains connections to a service.
- Catch a hung service with the watchdog: Set up notify type and a watchdog interval for a service that hangs while its process lives, and show it restarts on a hang.
- Observe the difference between ordering and requirement: Try After and Requires separately on two test units and show from the output what each one guarantees.
- Find and break a dependency cycle: Find the ordering cycle that makes a unit get skipped at boot from the journal and dependency listing, and fix it.
- Build a custom target for an application stack: Group database, app and proxy units under one target so they start in order and dependants stop when one fails.
- Start a service on first connection: Write a socket unit so a service starts only when the first connection arrives and show it was not running before.
- Trigger a job when a file lands in a directory: Write a path unit watching an inbox directory so a processing service runs on each new file and moves it to an archive.
- Build a timer with a complex calendar and random delay: Write a timer that fires every fifteen minutes in weekday office hours with a random delay and verify the next run times.
- Filter a service's errors from the last boot: Show only one unit's error-level journal entries from the current boot.
- Manage runtime directories with tmpfiles: Write a tmpfiles rule for a directory created at boot with the right ownership and cleaned of files older than ten days.
- Run a limited, traceable job as a transient unit: Start a one-off heavy job with systemd-run under a memory limit and its own journal identity, then report its result and resource use.
- Write and run a user service: Without root, write a service unit for your own user, enable it and show its status.
- Keep a user service running after logout: Find why a user service stops at logout and enable lingering for the service account.
- Lower a service's exposure score by hardening: Following the security analysis output add file system, privilege and network restrictions to a unit, improving the score while it keeps working.
About this course
You learn unit files, dependencies and ordering, drop-in changes, socket and path activation, user services and tmpfiles to production standard.
What you will learn
- Units
- Dependencies and order
- Activation
- Other tools
Prerequisites
You should be comfortable with the level 101 and 201 topics of the same path.
Lab environment
Lessons run in your own Kali Linux terminal that opens in the browser. Nothing to install; the lab starts clean in every lesson.
Frequently asked questions
- Is this course right for my level?
- The course is at level 301; it assumes you know the topics of the lower-level courses.
- Is there anything to install?
- No. Every lesson runs in your own lab environment that opens in the browser.
- How do lessons work?
- Each lesson has 8 to 10 steps and a short quiz. Early steps show the command to type, later steps give less help; if two attempts fail, the solution opens.
- Can I try it for free?
- Yes. The first three lessons of every course are free.