---
id: systemd
title: "systemd"
type: concept
tags: [linux, service-manager]
date: 2026-04-16
---

## Definition
systemd 是 Linux 系统的服务管理器，负责管理系统进程、服务和启动项，是大多数现代 Linux 发行版的初始系统。

## Key Components
- **systemd**：系统和服务管理器
- **systemctl**：命令行管理工具
- **journald**：日志收集系统
- **unit files**：服务配置文件（.service）

## Common Commands
```bash
# 启动服务
sudo systemctl start <service>

# 停止服务
sudo systemctl stop <service>

# 重启服务
sudo systemctl restart <service>

# 查看状态
sudo systemctl status <service>

# 开机自启
sudo systemctl enable <service>

# 禁用开机自启
sudo systemctl disable <service>

# 查看日志
sudo journalctl -u <service>
```

## Unit File Structure
```ini
[Unit]
Description=<description>
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
ExecStart=/path/to/executable
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target
```

## Connections
- [[systemd]] ← manages ← [[Linux系统服务]]
- [[systemd]] ← writes_logs_to ← [[journald]]