五:unit的配置文件
每个unit都有一个配置文件,告诉systemd怎么启动这个unit。
systemd默认从目录/etc/systemd/system/读取配置文件,但是,里面存放的大部分文件都是符号链接,指向目录/usr/lib/systemd/system/,真正的配置文件存放在那个目录。
systemctl enable命令用于在上面两个目录之间,建立符号链接关系:
$ sudo systemctl enable clamd@scan.service
# 等同于
$ sudo ln -s '/usr/lib/systemd/system/clamd@scan.service' '/etc/systemd/system/multi-user.target.wants/clamd@scan.service'
如果配置文件里面设置了开机启动,systemctl enable 命令相当于激活开机启动。
与之对应的,systemctl disable命令用于在两个目录之间,撤销符号链接关系,相当于撤销开机启动。
$ sudo systemctl disable clamd@scan.service
配置文件的后缀名,就是该unit的种类,比如sshd.socket。如果省略,systemd默认后缀名为.service,所以sshd会被理解为sshd.service。
2. 配置文件的状态
systemctl list-unit-files命令用于列出所有配置文件。
# 列出所有配置文件
$ systemctl list-unit-files
# 列出指定类型的配置文件
$ systemctl list-unit-files --type=service
这个命令会输出一个列表。
$ systemctl list-unit-files
UNIT FILE STATE
这个列表显示每个配置文件的状态,一共有四种。
enabled:已建立启动链接
disabled:没建立启动链接
static:该配置文件没有[install]部分(无法执行),只能作为其它配置文件的依赖
masked:该配置文件被禁止建立启动链接
从配置文件无法看出,该unit是否正在运行。这必须执行前面提到的systemctl status命令。
$ systemctl status bluetooth.service
一旦修改配置文件,就要让systemd重新加载配置文件,然后重新启动,否则修改不会生效。
$ sudo systemctl daemon-reload
$ sudo systemctl restart httpd.service
3. 配置文件的格式