-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
systemd 系列 #141
Comments
systemctl 配置文件相关目录简介
现在我们知道服务的管理是通过 systemd,而 systemd 的配置文件大部分放置于 /usr/lib/systemd/system/ 目录内。但是 Red Hat 官方文件指出, 该目录的文件主要是原本软件所提供的设置,建议不要修改!而要修改的位置应该放置于 /etc/systemd/system/ 目录内。举例来说,如果你想要额外修改 vsftpd.service 的话, 他们建议要放置到哪些地方呢?
基本上,在配置文件里面你都可以自由设置相依服务的检查,并且设置加入到哪些 target 里头去。但是如果是已经存在的配置文件,或者是官方提供的配置文件, Red Hat 是建议你不要修改原设置,而是到上面提到的几个目录去进行额外的客制化设置比较好!当然,这见仁见智~如果你硬要修改原始的 /usr/lib/systemd/system 下面的配置文件,那也是 OK 没问题的!并且也能够减少许多配置文件的增加~鸟哥自己认为,这样也不错!反正,就完全是个人喜好啰~ |
自定义 service
我们要如何设计一只名为 backup.service 的启动脚本设置呢?可以这样做喔! [[email protected] ~]# vim /etc/systemd/system/backup.service
[Unit]
Description=backup my server
Requires=atd.service
[Service]
Type=simple
ExecStart=/bin/bash -c " echo /backups/backup.sh | at now"
[Install]
WantedBy=multi-user.target
# 因为 ExecStart 里面有用到 at 这个指令,因此, atd.service 就是一定要的服务!
[[email protected] ~]# systemctl daemon-reload
[[email protected] ~]# systemctl start backup.service
[[email protected] ~]# systemctl status backup.service
backup.service - backup my server
Loaded: loaded (/etc/systemd/system/backup.service; disabled)
Active: inactive (dead)
Aug 13 07:50:31 study.centos.vbird systemd[1]: Starting backup my server...
Aug 13 07:50:31 study.centos.vbird bash[20490]: job 8 at Thu Aug 13 07:50:00 2015
Aug 13 07:50:31 study.centos.vbird systemd[1]: Started backup my server.
# 为什么 Active 是 inactive 呢?这是因为我们的服务仅是一个简单的 script 啊!
# 因此执行完毕就完毕了,不会继续存在内存中喔! 完成上述的动作之后,以后你都可以直接使用 systemctl start backup.service 进行系统的备份了!而且会直接丢进 atd 的管理中, 你就无须自己手动用 at 去处理这项任务了~好像还不赖喔! ^_^ 这样自己做一个服务好像也不难啊! ^_^!自己动手玩玩看吧! |
systemctl
常用命令
systemctl 是 systemd 的主命令,控制所有 service,如:
journalctl
journalctl 是 systemd 的日志命令,如:
The text was updated successfully, but these errors were encountered: