1. 程式人生 > >systemctl -- 系統服務管理器 【轉】

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

等級 simple note calc chkconfig eve bbs udev conf

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

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