Galle, LK--:--5/6 sites live

Linux Systemd Init System (PID 1), Daemons & Centralized Logging

පිටුව 07: Systemd Init System (PID 1), සේවා (Daemons) සහ Journalctl Logs

Linux boot වන විට පළමුවෙන්ම පණ ලබන PID 1 (Systemd), Background Services පාලනය (systemctl) සහ Logs කියවීම (journalctl).

8 Sept 20264 min readSelf Guide · Stage 10#systemd#Logging#SRE Labs

Lab 07 of 20 · Systemd & Daemons · 5 hands-on activities · bilingual (English + සිංහල)

පිටුව 07: Systemd Init System (PID 1), සේවා (Daemons) සහ Journalctl Logs

Linux boot වන විට පළමුවෙන්ම පණ ලබන PID 1 (Systemd), Background Services පාලනය (systemctl) සහ Logs කියවීම (journalctl).

💡 සරල සිංහලෙන්: Systemd (PID 1) කියන්නේ මුළු Server එකේම ප්‍රධාන Manager වගේ

ආයතනයක ප්‍රධාන විධායක නිලධාරියා (CEO):

පරිගණකය On කරපු ගමන් මුලින්ම වැඩ පටන් ගන්නේ Systemd (PID 1). ඊට පස්සේ Nginx, Jenkins, Docker, Databases ඔක්කොම සේවකයින් වගේ වැඩට බස්සන්නේ මෙයා තමයි.

Systemctl සහ Journalctl:

  • systemctl status nginx: Nginx සේවකයා හරියට වැඩ කරනවද, එයාට ලෙඩක්ද කියලා පරීක්ෂා කරනවා.
  • systemctl enable nginx: පරිගණකය Restart වුණත් Nginx එක ස්වයංක්‍රීයව On වෙන්න සෙට් කරනවා.
  • journalctl -u nginx -f: Nginx සේවකයා කරන හැමදේම ලියන දිනපොත (Logs) සජීවීව බලාගෙන ඉන්නවා.

Architectural Foundation & Systems Diagram

When the Linux kernel finishes booting, it mounts the root filesystem and executes the first user-space program: PID 1. On modern Linux distributions, PID 1 is systemd, the central system and service manager.

  • 👑 PID 1 (Ancestor of All) — PID 1 is the parent of all user-space processes. It initializes system targets, mounts storage, manages cgroups, and adopts orphaned processes.

  • ⚙️ Systemctl Service Control — • systemctl status [name]: Active state, PID, memory.
    • systemctl start/stop/restart: Lifecycle actions.
    • systemctl enable: Auto-start on boot!

  • 📜 Journalctl Centralized Logs — Replaces old plain-text log files with a binary, indexed journal. Query specific services with journalctl -u nginx -f in real-time!

Step-by-step practical lab

Step 01: Check Daemon Status with Systemctl

සිංහලෙන් — Systemd මඟින් සේවාවක (Service) තත්ත්වය පරීක්ෂා කරමු.

Query the current active state, memory usage, main process ID, and recent journal log entries for the Nginx service.

ExampleShell
systemctl status nginx
  • status : Service එක active ද, PID එක කුමක්ද, සහ log records පෙන්වයි.

Expected output

Output
● nginx.service - A high performance web server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled)
   Active: active (running) since Mon 2026-09-14 09:30:12 UTC
 Main PID: 1042 (nginx)

SRE Tip: 'enabled' means the service will automatically restart on machine reboot; 'disabled' requires manual startup.

Step 02: Stream Real-Time Service Logs via Journalctl

සිංහලෙන් — සේවාවක Logs සජීවීව බලාගැනීමට Journalctl භාවිතා කරමු.

Stream real-time log output generated by the systemd journal for the specified unit.

ExampleShell
journalctl -u nginx -f
  • -u nginx : Nginx service එකට අදාළ logs පමණක් filter කරයි.
  • -f : Follow: අලුතින් එකතු වන logs සජීවීව පෙන්වයි (live stream).

Expected output

Output
Sep 16 12:44:20 aws-ec2 nginx[1042]: 192.168.1.50 - - [16/Sep/2026] "GET / HTTP/1.1" 200 612
Sep 16 12:44:21 aws-ec2 nginx[1042]: 192.168.1.50 - - [16/Sep/2026] "GET /api/v1/health HTTP/1.1" 200 45

SRE Tip: Add -p err to filter logs and only display error, critical, and alert priority log entries.

Hands-on practice activities

Work through these yourself — tick them off as you go.

  • Activity 31: Inspect Nginx Web Server Daemon Status (Drill) — Inspect the active running state, main PID, memory consumption, and cgroup tasks for Nginx.
  • Activity 32: Query Jenkins CI Server Daemon Status (Drill) — Verify whether the Jenkins continuous integration daemon is active and running.
  • Activity 33: Enable Auto-Restart on Service Failure (Checkpoint) — In /etc/systemd/system/*.service, always configure 'Restart=always' and 'RestartSec=5s' for self-healing!
  • Activity 34: Stream Live Logs via Journalctl (Checkpoint) — Use 'journalctl -u nginx -f' during deployments to stream live log events and catch startup crashes immediately.
  • Activity 35: Systemd Init PID Quiz (Quiz) — What is the fixed Process ID (PID) of the systemd init process in Linux? Answer: PID 1.

Keep going: ← Lab 06 · Lab 08 → · Track your progress in the Self Guide

ExerciseKnowledge check

In modern Linux distributions, what is the Process ID (PID) of the systemd init process? / Systemd init process එකේ PID අංකය කුමක්ද?

Finished this one?

Part of Self Guide · Stage 10: SRE Labs I — the machine underneath. Progress is saved in this browser.

Guide