Chinaunix首页 | 论坛 | 博客
  • 博客访问: 186098
  • 博文数量: 20
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 965
  • 用 户 组: 普通用户
  • 注册时间: 2014-03-18 23:28
文章分类

全部博文(20)

文章存档

2015年(1)

2014年(19)

分类: LINUX

2014-08-29 19:58:53


systemd下的systemctl命令

从fedora15开始,系统对于daemon的启动管理方法不再采用SystemV形式,而是使用了sytemd的架构来管理daemon的启动。

systemd的服务管理程序
systemctl是最主要的工具。它融合 service 和chkconfig的功能于一体。
运行一个服务:systemctl start network.service
关闭网络服务:systemctl stop network.service
重启网络服务:systemctl restart network.service
显示一个服务(无论运行与否)的状态: systemctl status network.service
在开机时启用一个服务: systemctl enable network.service
在开机时禁用一个服务: systemctl disable network.service
查看服务开机是否启动:systemctl is-enabled network.service;echo $?  或者是chkconfig
使用systemctl命令,请记住start,stop,restart,status,enable,disable,is-enabled。

从runlevel 到 target的转变:
在systemd的管理体系里面,以前的运行级别(runlevel)的概念被新的运行目标(target)所取代。tartget的命名类似于 multi-user.target等这种形式,比如原来的运行级别3(runlevel3)就对应新的多用户目标(multi- user.target),run level 5就相当于graphical.target。由于不再使用runlevle概念,所以/etc/inittab也不再被系统使用。

而在systemd的管理体系里面,默认的target(相当于以前的默认运行级别)是通过软链来实现。例如
ln -s /lib/systemd/system/runlevel3.target /etc/systemd/system/default.target

在/lib/systemd/system/ 下面定义runlevelX.target文件目的主要是为了能够兼容以前的运行级别level的管理方法。 事实上/lib/systemd/system/runlevel3.target,同样是被软连接到multi-user.target。

实例详解:
显示当前的处于运行状态的daemon
# systemctl
UNIT                      LOAD   ACTIVE SUB       JOB DESCRIPTION
<略>
fedora-l...odules.service loaded active exited        Load legacy module configu
iptables.service          loaded active exited        IPv4 firewall with iptable

显示该daemon的当前状态
# systemctl status httpd.service
httpd.service - The Apache HTTP Server (prefork MPM)
        Loaded: loaded (/lib/systemd/system/httpd.service; disabled)
        Active: inactive (dead)  <-- 表示未启动,启动时为activing;
        CGroup: name=systemd:/system/httpd.service
等同于/etc/init.d/httpd status
该启动文件原本在/etc/init.d/目录下,新架构下被/lib/systemd/system/下相应的文件所取代。例如实例中的/lib/systemd/system/httpd.service,http的启动等相关的配置都在这个文件里修改。

unit的启动停止
# systemctl start httpd.service    等同于 /etc/init.d/httpd start
# systemctl stop httpd.service    等同于 /etc/init.d/httpd stop

配置成系统启动时默认启动
# systemctl enable httpd.service  等同于/sbin/checkconfig httpd

在启动文件/lib/systemd/system/httpd.service里的[Install]单元里来指定启动的目标(target)级别。比如
[Install]
WantedBy=multi-user.target
则表明在多用户目标(multi-user.target,相当于level3)时自动启动。

另外一旦设定了自动启动(enbale),就在/etc/systemd/system/.wants/下面建了一个httpd.service的软连接,连接到/lib/systemd/system/下的相应服务那里

关闭自动启动
# systemctl disable httpd.service    相当于  /sbin/checkconfig httpd off

添加新的unit
把新生成的foo.service 放到/lib/systemd/system/下面,然后采用load命令导入
#systemctl load foo.service   相当于/sbin/chkconfig --add foo

显示自动启动状态的unit
在systemd里面没有像/sbin/chkconfig –list那样显示自动启动的状态的可操作的命令,只能用以下命令显示
#ls /etc/systemd/system/multi-user.target.wants/

阅读(3335) | 评论(0) | 转发(0) |
0

上一篇:wget用法指南

下一篇:Linux Kernel 开发树

给主人留下些什么吧!~~