微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为systemd添加一个服务

新建一个服务

systemdunit文件分布在

系统模式

用户模式

新建服务时,新建一个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使其开机加载

参考资料










stemd-tutorial-part-two.html">systemd 实战2

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐