CentOS 7-每次systemctl重新启动network.service时如何运行bash脚本(&Reload,&Start)

时间:2018-11-21 22:42:34

标签: networking centos redhat systemd

我想在每次系统重新引导时以及在systemctl重新启动network.service运行时(也在Reload&Start运行时)运行bash脚本来更新ifcfg脚本文件。该脚本旨在检查文件中是否包含正确的HWADDR,如果没有,它将对其进行更新。我正在使用自定义的网络设备名称。

我创建了一个SystemD服务文件,该文件似乎在重新启动网络启动之前就运行了,但是,如果在操作过程中更改了网络配置,并且运行了systemctl restart network.service或systemctl reload network.service,它将不会运行脚本文件。请帮忙!

注意:我的服务文件有点脏,因为我一直在对其进行测试。

# /etc/systemd/system/HWADDR.service
# systemctl enable HWADDR.service
# Only Seems to run on reboot, but this should be fine for now

[Unit]
Description=Update HWADDR on Network Adaptors to Retain Custom Names
Before=network-pre.target network.service NetworkManager.service
Wants=network-pre.target network.service NetworkManager.service
DefaultDependencies=no
Requires=local-fs.target
After=local-fs.target

[Service]
Type=oneshot
ExecStart=/etc/sysconfig/network-scripts/GT/updateHWADDR.sh

[Install]
RequiredBy=network.target network-pre.target network.service
WantedBy=network.target NetworkManager.service

0 个答案:

没有答案