| $ sudo systemctl mask prometheus.service |

从上图中的输出我们可以看到,所谓的注销就是把 prometheus.service 文件链接到 /dev/null 这个空设备中去了。所以就无法再启动该服务了。下面我们尝试执行一次反注销:
| $ sudo systemctl unmask prometheus.service |

unmask 操作就是删除掉 mask 操作中创建的链接。
查看系统上的 unit
systemctl 提供了子命令可以查看系统上的 unit,命令格式为:
systemctl [command] [--type=TYPE] [--all]
command 有:
list-units:列出当前已经启动的 unit,如果添加 -all 选项会同时列出没有启动的 unit。
list-unit-files:根据 /lib/systemd/system/ 目录内的文件列出所有的 unit。
--type=TYPE:可以过滤某个类型的 unit。
不带任何参数执行 systemctl 命令会列出所有已启动的 unit:

系统默认启动的服务是非常多的,上图只截取了前面几行。下面是对输出的介绍:
UNIT:项目的名称,包括各个 unit 的类别(看扩展名)。
LOAD:开机时 unit 的配置是否被加载。
ACTIVE:目前的状态,须与后续的 SUB 搭配!就是我们用 systemctl status 观察时,active的内容。
DESCRIPTION:描述信息。
注意,systemctl 不加参数,其实等同于 systemctl list-units!
下面我们查看系统上一共安装了多少 unit:
| $ sudo systemctl list-unit-files |

结果也非常的多,我们仍然只截取一部分结果。这里的 STATE 就是我们前面介绍的 服务的启动状态,有 enable 和 disable、static 和 mask。
只查看某种类型的 unit
比如我们只想看服务类型的 unit:
| $ systemctl list-units --type=service --all |
这次只有以 .service 结尾的 unit 才会出现。
如果要看 mount 类型的 unit 指定 --type=mount 就可以了:

查看加载失败的 unit
如果发现某个 unit 不工作,可以查看是否有 unit 加载失败:
| $ systemctl --failed |

管理不同的操作环境(target unit)
通过指定 --type=target 就可以用 systemctl list-units 命令查看系统中默认有多少种 target:








