systemctl -- 系統服務管理器 【轉】

systemctl  -- 系統服務管理器

systemctl 是系統服務管理器命令,它實際上將 service 和 chkconfig 這兩個命令組合到一塊兒。

直接運行命令能夠列出全部正在運行的服務,輸出列表具備更詳細的信息,好比:

[root @beyes   command]# systemctl
... ...
sendmail.service          loaded active exited        LSB: start and stop sendmail
sshd.service              loaded active running       LSB: Start up the OpenSSH server daemon
udev.service              loaded active running       udev Kernel Device Manager
... ...


這裏,還有一個 systemd-cgls 命令能夠以樹狀的形式列出正在運行的進程信息。

若是要啓動 httpd 服務,那麼運行下面命令:
[root @beyes   command]# systemctl start httpd.service

注意,上面的 httpd 後面的 .service 是不能少的。

同理,中止服務和重啓服務能夠分別以下運行命令:
# systemctl stop httpd.service       #中止服務
# systemctl restart httpd.service              #重啓服務


若是咱們要查看服務的運行狀態,那麼以下運行:
[root @beyes   command]# systemctl status httpd.service
httpd.service - LSB: start and stop Apache HTTP Server
      Loaded: loaded (/etc/rc.d/init.d/httpd)
      Active: active (running) since Wed, 22 Feb 2012 10:37:30 +0800; 2s ago
     Process: 2573 ExecStop=/etc/rc.d/init.d/httpd stop (code=exited, status=0/SUCCESS)
     Process: 2589 ExecStart=/etc/rc.d/init.d/httpd start (code=exited, status=0/SUCCESS)
    Main PID: 2594 (httpd)
      CGroup: name=systemd:/system/httpd.service
          ├ 2594 /usr/sbin/httpd
          ├ 2596 /usr/sbin/httpd
          ├ 2597 /usr/sbin/httpd
          ├ 2598 /usr/sbin/httpd
          ├ 2599 /usr/sbin/httpd
          ├ 2600 /usr/sbin/httpd
          ├ 2601 /usr/sbin/httpd
          ├ 2602 /usr/sbin/httpd
          └ 2603 /usr/sbin/httpd


若是咱們打算讓服務能夠隨機啓動,那麼以下運行:
[root @beyes   command]# systemctl enable httpd.service
httpd.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig httpd on


用 chkconfig 命令檢測一下服務是否運行成功
[root @beyes   command]# chkconfig --list |grep httpd

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

httpd              0:off    1:off    2:on    3:on    4:on    5:on    6:off

可見服務已經在 第2 到 第5 運行等級打開。

同理禁止服務隨機啓動能夠以下運行:
[root @beyes   command]# systemctl disable httpd.service
httpd.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig httpd off

用 chkconfig 檢測一下:
[root @beyes   command]# chkconfig --list |grep httpd

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

httpd              0:off    1:off    2:off    3:off    4:off    5:off    6:off

已經關閉成功。

此外,咱們還能夠直接檢測服務是否隨機啓動或否,以下運行命令:
[root @beyes   command]# systemctl is-enabled httpd.service; echo $? httpd.service is not a native service, redirecting to /sbin/chkconfig. Executing /sbin/chkconfig httpd --level=5 0
上面,0 表示該服務已經使能隨機啓動;若是返回 1 那麼表示該服務不隨機啓動 ref:http://www.groad.net/bbs/simple/?t6224.html
相關文章
相關標籤/搜索