1. list service
列出正在运行的 Unit
$ systemctl list-units
# 列出所有Unit,包括没有找到配置文件的或者启动失败的
$ systemctl list-units --all
# 列出所有没有运行的 Unit
$ systemctl list-units --all --state=inactive
# 列出所有加载失败的 Unit
$ systemctl list-units --failed
# 列出所有正在运行的、类型为 service 的 Unit
$ systemctl list-units --type=service
Example
root@localhost:~# systemctl list-units --all |grep gett
getty-static.service loaded inactive dead getty on tty2-tty6 if dbus and logind are not available
serial-getty@ttyS0.service loaded active running Serial Getty on ttyS0
system-serial\x2dgetty.slice loaded active active system-serial\x2dgetty.slice
getty-pre.target loaded inactive dead Login Prompts (Pre)
getty.target loaded active active Login Prompts
root@localhost:~#
2. restart
# 立即启动一个服务
$ sudo systemctl start apache.service
# 立即停止一个服务
$ sudo systemctl stop apache.service
# 重启一个服务
$ sudo systemctl restart apache.service
# 杀死一个服务的所有子进程
$ sudo systemctl kill apache.service
3. Enable/disable
$ 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'
root@Ubuntu 18.04 LTS
ls -l /etc/systemd/system/getty.target.wants/
total 0
lrwxrwxrwx 1 root root 34 Jan 8 2020 getty@tty1.service -> /lib/systemd/system/getty@.service
lrwxrwxrwx 1 root root 34 Jan 8 2020 getty@ttyAMA0.service -> /lib/systemd/system/getty@.service