例子:

以下是如何运行和使用Ubuntu Linux上的SystemCtl的一些示例。

使用systemctl命令启动服务:

sudo systemctl start application.service

使用systemctl命令停止服务

sudo systemctl stop application.service

可以只使用应用程序名称(没有.service)

例子:

sudo systemctl start application

重启服务:

sudo systemctl restart application.service

或者重新加载服务:

sudo systemctl reload application.service

启用和禁用服务

启用服务将允许服务器每次服务器启动时自动启动。

sudo systemctl enable application.service

或者禁用:

sudo systemctl disable application.service

检查服务状态

sudo systemctl status application.service

列出所有服务:

要列出在服务器上运行或者停止的所有服务,请运行以下命令:

systemctl list-units --all --type=service --no-pager

输出示例

UNIT                                  LOAD      ACTIVE   SUB     DESCRIPTION                                                 
  accounts-daemon.service               loaded    active   running Accounts Service                                            
  acpid.service                         loaded    active   running ACPI event daemon                                           
  alsa-restore.service                  loaded    active   exited  Save/Restore Sound Card State                               
  alsa-state.service                    loaded    inactive dead    Manage Sound Card State (restore and store)                 
  anacron.service                       loaded    inactive dead    Run anacron jobs                                            
  apparmor.service                      loaded    active   exited  AppArmor initialization                                     
  apport-autoreport.service             loaded    inactive dead    Process error reports when automatic reporting is enabled   
  apport.service                        loaded    active   exited  LSB: automatic crash report generation                      
  apt-daily-upgrade.service             loaded    inactive dead    Daily apt upgrade and clean activities                      
  apt-daily.service                     loaded    inactive dead    Daily apt download activities                               
● auditd.service                        not-found inactive dead    auditd.service                                              
  avahi-daemon.service                  loaded    active   running Avahi mDNS/DNS-SD Stack                                     
  bolt.service                          loaded    active   running Thunderbolt system service                                  
  colord.service                        loaded    active   running Manage, Install and Generate Color Profiles                 
● connman.service                       not-found inactive dead    connman.service

如果我们正在运行Ubuntu 16.04,则可以使用下面命令

service --status-all

要列出所有非活动服务,请运行以下命令:

systemctl list-units --all --state=inactive

只列出活动的服务:

systemctl list-units --all --state=inactive

使用-help选项 查看帮助文档:

systemctl [OPTIONS. ] {COMMAND} . 
Query or send control commands to the systemd manager.
  -h --help           Show this help
     --version        Show package version
     --system         Connect to system manager
     --user           Connect to user service manager
  -H --host=[USER@]HOST
                      Operate on remote host
  -M --machine=CONTAINER
                      Operate on local container
  -t --type=TYPE      List units of a particular type
     --state=STATE    List units with particular LOAD or SUB or ACTIVE state
  -p --property=NAME  Show only properties by this name
  -a --all            Show all properties/all units currently in memory,
                      including dead/empty ones. To list all units installed on
. . . .

语法:

下面是如何使用SystemCtl命令的示例语法。

systemctl [OPTIONS. ] {COMMAND} .

选项:

以下是systemctl命令的某些选项:

COMMAND.命令服务名称
-t -type=TYPE, -state=STATE使用-t或者-type或者-state = state来列出特定类型的服务状态的单位:活动,非活动
-a -all使用-a或者-all显示当前内存中的所有属性/所有单位,包括死/空。要列出所有安装在系统上的单元,请使用“列表单元文件”命令。
-r -recursive使用-r或者-rocursive显示主机和本地容器的单位列表
-help显示帮助消息并退出。

关于systemctl命令:

在Linux系统(包括Ubuntu)上,可以使用systemctl命令实用程序来控制和管理systemd服务。
在Ubuntu 16.04上,可以使用service命令来完成同样的任务。

使用systemctl和service命令,您可以列出所有正在运行、已停止或者已禁用的服务。

如何在Ubuntu 16.04/18.04上列出所有服务
日期:2020-07-07 20:55:33 来源:oir作者:oir