RousselTMLEARNING

TP · Linux administration: from discovery to expertise

Lab: Create and manage a systemd service

What you will learn in this TP
  • Manage packages and services
  • Write a hardened systemd unit
  • Schedule with a timer

Introduction #

What you will learn in this section
  • Manage packages and services
  • Write a hardened systemd unit
  • Schedule with a timer

Context. A small internal application is started by hand in a terminal and stops at every logout. You turn it into a proper, supervised and hardened service.

Prerequisites: a disposable Ubuntu 24.04 virtual machine (Multipass, Vagrant or cloud) with a sudo account  ·  Estimated time: 45 min

A service that starts at boot, restarts on its own and is checked every minute.

Hands-on #

Guided steps, with their solution.

  1. 1. Install and manage nginx

    Why? A distribution package already ships its systemd unit: learn the commands on a simple case.

    Update the index, install nginx, check it is active and enabled at boot, and test it with curl.
  2. 2. Prepare the application

    Why? The application runs under a dedicated service account, never root.

    Create the app account (if missing) and a static site in /srv/app/www served by python3 -m http.server on port 8080.
  3. 3. Write the unit

    Why? systemd starts the service at boot, restarts it on crash and isolates it from the rest of the system.

    Create /etc/systemd/system/app.service with Restart=on-failure and hardening options, reload systemd, enable and start the service.
  4. 4. Test automatic restart

    Why? Verify crash behaviour instead of assuming it.

    Kill the main process with SIGKILL, see a new PID appear, then find the event in the journal.
  5. 5. Override the unit

    Why? A drop-in override changes a service without editing its file, and survives updates.

    Limit the service memory to 200 MB and CPU to 50% with an override, then check the applied values and the security score.
  6. 6. Schedule a check with a timer

    Why? A systemd timer logs every run and catches up missed ones, unlike cron.

    Create a healthcheck service querying /health and a timer running it every minute. Stop the application and watch the failure in the journal.

Difficulty level : ●●○○○ (2/5)

My progress

  • ⏱ Estimated time : ≈ 45 min

Sign in to track your progress and take notes. Sign in

💬 Questions about this lesson

No questions yet: be the first to ask for help or share your configuration.

Ask a question about this lesson →

Recommended Articles

Networking on Linux: configuration, diagnosis, firewall and SSH

Configure and troubleshoot Linux networking: ip, ss, netplan and NetworkManager, DNS, layered dia...

Bash scripts for administrators: writing robust scripts

Automate Linux administration with Bash: variables and quoting, conditions, loops, functions, exi...

Backup, monitoring and troubleshooting of a Linux server

Operate a Linux server day to day: 3-2-1 backup strategy with rsync, tar, LVM snapshots and resti...

Users, groups, NTFS permissions and SMB shares

Manage local accounts and groups, understand UAC, apply NTFS permissions with inheritance, create...

Linting Dockerfiles with Hadolint and docker build --check

Spot Dockerfile errors and bad practices before building: Hadolint, its rules, thresholds, and Bu...

Fluent Bit: pipeline inputs in detail

Everything about Fluent Bit inputs: the role of tags, reading files with tail (positions, rotatio...

Services, scheduled tasks, event logs and performance

Control Windows services and their recovery, automate with Task Scheduler, use event logs with Ge...

Windows networking: IP, DNS, DHCP, firewall and remote access

Configure and troubleshoot Windows networking with PowerShell, deploy a DHCP server, master Windo...

Processes, memory and performance: monitoring and troubleshooting a Linux server

Understand and control Linux processes (ps, top, signals, nice, jobs), interpret load, memory and...

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!