大佬教程收集整理的这篇文章主要介绍了为systemd添加一个服务,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
systemd
的unit
文件分布在
/usr/lib/systemd/system/
软件包安装
/etc/systemd/system/
系统管理员维护
/usr/lib/systemd/user/
软件包安装
/etc/systemd/user/
管理员维护的用户服务
~/.config/systemd/user/
用户自身的服务
新建服务时,新建一个sample.service
,比如要实现重启防火墙的功能,格式如下
[Unit]
Description=Restart firewalld.service # 描述
After=ovirt-ENGIne.service # 服务在其他服务之后启动
requires=ovirt-ENGIne.service # 服务需要其他服务启动后启动
[service]
Type=oneshot # 类型,只运行一次
ExecStartPre=/usr/bin/env systemctl stop firewalld # 启动之前执行
ExecStart=/usr/bin/env systemctl start firewalld # 启动执行
Killmode=none # 重启模式
Restart=no # 重启
[Install]
WantedBy=multi-user.target # 安装时依赖的目标
添加好需要的service
文件之后,使用
systemctl daemon-reload
重新加载所有的service
使用systemctl list-units --type=service
,可以查询到刚才添加的服务
使用systemctl enable sample
使其开机加载
http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-part-two.html">systemd 实战2@H_197_66@
以上是大佬教程为你收集整理的为systemd添加一个服务全部内容,希望文章能够帮你解决为systemd添加一个服务所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。