Skills2026年5月5日·1 分钟阅读

systemd — The Modern Linux Init System and Service Manager

The init system and service manager adopted by most major Linux distributions, managing system startup, services, logging, and resource control.

Agent 就绪

先审查再安装

这个资产需要先审查。复制的指令会要求 Agent dry-run、列出写入项,确认后再继续。

Needs Confirmation · 64/100策略:需确认
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
systemd
先审查命令
npx -y tokrepo@latest install 2bb1031c-48c0-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run,确认写入项后再运行此命令。

Introduction

systemd is the init system and service manager that has become the default on most major Linux distributions including Debian, Ubuntu, Fedora, RHEL, and Arch. It manages the full lifecycle from early boot through service supervision, logging, and shutdown.

What systemd Does

  • Starts and supervises system services with dependency-based parallel activation
  • Manages the full boot sequence from initrd handoff to multi-user target
  • Collects and indexes logs via journald with structured metadata
  • Controls resource allocation per service using cgroups (CPU, memory, I/O limits)
  • Provides timers, socket activation, device management, and network configuration

Architecture Overview

systemd replaces traditional SysV init with a dependency graph of units. Unit files declare what a service needs and wants, letting systemd parallelize startup. PID 1 (the main systemd process) spawns and monitors services, collecting their output into the journal. Auxiliary daemons handle logging (journald), networking (networkd), DNS resolution (resolved), and time synchronization (timesyncd).

Self-Hosting & Configuration

  • Installed by default on most modern Linux distributions
  • Place custom unit files in /etc/systemd/system/ to define new services
  • Override existing units with systemctl edit <service> for drop-in configuration
  • Configure journal retention in /etc/systemd/journald.conf (size and time limits)
  • Set resource limits per service with directives like MemoryMax, CPUQuota, and IOWeight

Key Features

  • Dependency-based parallel startup reduces boot time significantly
  • Socket and D-Bus activation start services on demand rather than at boot
  • Structured logging with journald supports filtering by unit, priority, or time range
  • Transient services via systemd-run for one-off supervised commands
  • Portable services and systemd-nspawn provide lightweight containerization

Comparison with Similar Tools

  • OpenRC — used by Gentoo and Alpine; shell-based, simpler but less feature-rich
  • runit — minimalist process supervisor; no journal, no cgroup management
  • s6 — supervision suite focused on correctness; steeper learning curve, niche adoption
  • launchd — macOS service manager; similar scope but proprietary and Apple-only

FAQ

Q: Why did Linux distributions switch to systemd? A: systemd offers faster parallel boot, unified service management, built-in logging, and cgroup integration that traditional init systems lacked.

Q: Can I still use SysV init scripts? A: Yes. systemd includes a compatibility layer that wraps legacy init scripts as service units.

Q: How do I write a basic service unit? A: Create a .service file in /etc/systemd/system/ with [Service] ExecStart pointing to your binary, then run systemctl daemon-reload && systemctl start your-service.

Q: Does systemd work in containers? A: It can, but most container images use a simpler init like tini. systemd-nspawn is designed for running full systemd inside lightweight containers.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产