Skip to content

Commit 1486b06

Browse files
committed
docs: add systemD
1 parent 8e038c2 commit 1486b06

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

docs/systemd.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# SystemD
2+
3+
## 简介
4+
5+
SystemD 是 Linux 的系统管理器,它的主要接口是 systemctl(即用户执行的命令)。
6+
7+
通过 systemctl 接口,可以启动/停止“单元”(unit),最常用的单元是“服务单元”(service),即系统守护程序。其他单元还有套接字单元(network socket)、定时器单元(timer)等等。
8+
9+
服务单元会有一个服务描述文件,里面设置启动该服务需要知道的信息,比如 sshd 的服务描述是“在多用户模式下,等待网络可用后,运行 SSH 服务器。” 修改服务描述文件以后,必须重新启动服务,修改才会生效。
10+
11+
## 服务描述文件
12+
13+
下面是一个服务描述文件的示例。它有很多设置,但是常用的就是那么几个。
14+
15+
```bash
16+
[Unit]
17+
Description=OpenBSD Secure Shell server
18+
Documentation=man:sshd(8) man:sshd_config(5)
19+
After=network.target auditd.service
20+
ConditionPathExists=!/etc/ssh/sshd_not_to_be_run
21+
22+
[Service]
23+
EnvironmentFile=-/etc/default/ssh
24+
ExecStartPre=/usr/sbin/sshd -t
25+
ExecStart=/usr/sbin/sshd -D $SSHD_OPTS
26+
ExecReload=/usr/sbin/sshd -t
27+
ExecReload=/bin/kill -HUP $MAINPID
28+
KillMode=process
29+
Restart=on-failure
30+
RestartPreventExitStatus=255
31+
Type=notify
32+
RuntimeDirectory=sshd
33+
RuntimeDirectoryMode=0755
34+
35+
[Install]
36+
WantedBy=multi-user.target
37+
Alias=sshd.service
38+
```
39+
40+
网上有一些[描述文件生成器](https://mysystemd.talos.sh/),可以使用。
41+
42+
系统的单元描述文件,一般放在目录`/etc/systemd/system`。用户的单元描述文件放在目录`/etc/systemd/user`。命令`systemctl status xxx.service`会显示单元描述文件的位置。
43+
44+
45+
46+
47+
48+

0 commit comments

Comments
 (0)