Centos7服务文件(.service)位置及案例介绍

本文介绍了CentOS 7中systemd服务文件的位置,包括系统级和服务级路径:/usr/lib/systemd/system和/usr/lib/systemd/user。以httpd服务为例,详细解析了.service文件的[Unit]、[Service]和[Install]三个主要部分。
摘要由CSDN通过智能技术生成

Centos7服务文件(.service)位置及案例介绍

systemd:
CentOS 7的服务systemctl脚本存放在:/usr/lib/systemd/,有系统(system)和用户(user)之分,即:/usr/lib/systemd/system ,/usr/lib/systemd/user

每一个服务以.service结尾,一般会分为3部分:[Unit]、[Service]和[Install],就以httpd为例吧,具体内容如下:
 

[root@localhost system]# pwd
/usr/lib/systemd/system
[root@localhost system]# cat httpd.service
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)

[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND
ExecReload=/usr/sbin/httpd $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH ${MAINPID}
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target
[root@localhost system]# ll
total 824
-rw-r--r--. 1 root root  275 Aug  9  2019 arp-ethers.service
-rw-r--r--. 1 root root 1384 Aug  8  2019 auditd.service
lrwxrwxrwx. 1 root root   14 Jan 28 06:01 autovt@.service -> getty@.service
-rw-r--r--. 1 root root  517 Oct 19 00:48 basic.target
drwxr-xr-x. 2 root root   67 Feb  5 05:50 basic.target.wants
-r--r--r--. 1 root root  429 Oct 19 00:05 blk-availability.service
-rw-r--r--. 1 root root  379 Oct 19 00:48 bluetooth.target
-rw-r--r--. 1 root root  160 Mar 29  2019 brandbot.path
-rw-r--r--. 1 root root  116 Mar 29  2019 brandbot.service
-rw-r--r--. 1 root root  787 Oct 19 00:48 console-getty.service
-rw-r--r--. 1 root root  749 Oct 19 00:48 console-shell.service
-rw-r--r--. 1 root root  808 Oct 19 00:48 container-getty@.service
-rw-r--r--. 1 root root  294 Dec  7 00:00 cpupower.service
-rw-r--r--. 1 root root  318 Aug  9  2019 crond.service
-rw-r--r--. 1 root root  425 Oct 19 00:48 cryptsetup-pre.target
-rw-r--r--. 1 root root  372 Oct 19 00:48 cryptsetup.target
lrwxrwxrwx. 1 root root   13 Jan 28 06:01 ctrl-alt-del.target -> reboot.target
lrwxrwxrwx. 1 root root   25 Jan 28 06:01 dbus-org.freedesktop.hostname1.service -> systemd-hostnamed.service
lrwxrwxrwx. 1 root root   23 Jan 28 06:01 dbus-org.freedesktop.import1.service -> systemd-importd.service
lrwxrwxrwx. 1 root root   23 Jan 28 06:01 dbus-org.freedesktop.locale1.service -> systemd-localed.service
lrwxrwxrwx. 1 root root   22 Jan 28 06:01 dbus-org.freedesktop.login1.service -> systemd-logind.service
lrwxrwxrwx. 1 root root   24 Jan 28 06:01 dbus-org.freedesktop.machine1.service -> systemd-machined.service
lrwxrwxrwx. 1 root root   25 Jan 28 06:01 dbus-org.freedesktop.timedate1.service -> systemd-timedated.service
-rw-r--r--. 1 root root  366 Mar 14  2019 dbus.service
-rw-r--r--. 1 root root  102 Mar 14  2019 dbus.socket
drwxr-xr-x. 2 root root    6 Oct 19 00:48 dbus.target.wants
-rw-r--r--. 1 root root 1014 Oct 19 00:48 debug-shell.service
lrwxrwxrwx. 1 root root   16 Jan 28 06:01 default.target -> graphical.target
drwxr-xr-x. 2 root root    6 Oct 19 00:48 default.target.wants
-rw-r--r--. 1 root root  670 Oct 19 00:48 dev-hugepages.mount
-rw-r--r--. 1 root root  590 Oct 19 00:48 dev-mqueue.mount
-r--r--r--. 1 root root  345 Oct 19 00:05 dm-event.service
-r--r--r--. 1 root root  248 Oct 19 00:05 dm-event.socket
lrwxrwxrwx. 1 root r
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值