Skip to content

Unit Files

You'll write your own systemd service and timer, read the journal with filters, see what runs at boot and why, and shave seconds off your startup.

About

Systemd runs almost every modern distro, and most people meet it only through the error that says a unit failed. This weekend you'll write units from scratch so you know what the text inside means, run something of your own on a timer, and read the journal with filters instead of scrolling. You'll also find out what your machine is actually doing between the firmware and the login screen, which is usually more than it needs to. Scheduling a script with cron belongs to Automation & Scripts, and this badge is about the init system itself.

At a glance

Per requirement
25 XP
Completion bonus
150 XP
Requirements
6
Takes
One weekend
Skill level
Intermediate (months of practice)
Cost
Free
Supplies
Nothing special
Where
At home
Other people
On your own
Locked for now
Earn two more Common badges in Linux to open this one. Log in to see how far along you are.

Requirements

  1. 1
    Write a service unit for a small program and make it start at boot. Pick a tiny thing, like a script that logs the date to a file every few seconds, or a small daemon. Write the [Unit], [Service] and [Install] sections by hand in /etc/systemd/system, run daemon-reload, enable it, and reboot. Take a photo of the unit file and of systemctl status showing it active after the reboot. Photo
  2. 2
    Make it restart itself after you kill it. Add Restart=on-failure and a RestartSec, then kill the process with kill -9 and watch systemd bring it back. Take a photo of the journal lines showing the death and the restart, or film it. Photo or video
  3. 3
    Replace a cron-style job with a timer unit. Write a .timer that fires every ten minutes, or at a fixed time, and the .service it triggers. Check it with systemctl list-timers. Take a photo of the timer listing with your timer and its next run. Photo
  4. 4
    Read the journal with filters for one unit, one boot and one priority. Use journalctl -u for your unit, -b -1 for the previous boot, and -p err for only errors. Find one real error on your system that way and work out what it was. Take a photo of the error and one line on what caused it. Photo
  5. 5
    Run systemd-analyze and cut your boot time. Run systemd-analyze blame and critical-chain, find the slowest unit, and decide whether you need it. Disable or mask one thing you don't, reboot, and compare. Many laptops lose five seconds to a network wait they never needed. Take a photo of the two numbers before and after, with the unit you removed. Photo
  6. 6
    Write a user unit that runs without root. Put a unit in ~/.config/systemd/user and manage it with systemctl --user. Enable linger if you want it to keep running when you're logged out. Take a photo of systemctl --user status showing it running. Photo