CentOS 7 - How to run bash script everytime systemctl restart network.service (& Reload, & Start)











up vote
0
down vote

favorite












I want to run a bash script to update the ifcfg script files every time the system is rebooted and when systemctl restart network.service is run (Also when Reload & Start are run). The script is meant to check that the correct HWADDR is in the file, and if not it updates it. I am using custom Network Device Names.



I Created a SystemD service file which seems to run before network is up on reboot, but if the network configuration is changed during operation, and systemctl restart network.service or systemctl reload network.service is run it does not run the script file. Please Help!



Note: My service file is a little dirty, as I have been testing with it.



# /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









share|improve this question






















  • I found that I could use the dispatcher Pre Up directory to get the results I wanted. /etc/NetworkManager/dispatcher.d/pre-up.d . However it should be possible to do this with a systemd service file.
    – Rahim Khoja
    2 days ago















up vote
0
down vote

favorite












I want to run a bash script to update the ifcfg script files every time the system is rebooted and when systemctl restart network.service is run (Also when Reload & Start are run). The script is meant to check that the correct HWADDR is in the file, and if not it updates it. I am using custom Network Device Names.



I Created a SystemD service file which seems to run before network is up on reboot, but if the network configuration is changed during operation, and systemctl restart network.service or systemctl reload network.service is run it does not run the script file. Please Help!



Note: My service file is a little dirty, as I have been testing with it.



# /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









share|improve this question






















  • I found that I could use the dispatcher Pre Up directory to get the results I wanted. /etc/NetworkManager/dispatcher.d/pre-up.d . However it should be possible to do this with a systemd service file.
    – Rahim Khoja
    2 days ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I want to run a bash script to update the ifcfg script files every time the system is rebooted and when systemctl restart network.service is run (Also when Reload & Start are run). The script is meant to check that the correct HWADDR is in the file, and if not it updates it. I am using custom Network Device Names.



I Created a SystemD service file which seems to run before network is up on reboot, but if the network configuration is changed during operation, and systemctl restart network.service or systemctl reload network.service is run it does not run the script file. Please Help!



Note: My service file is a little dirty, as I have been testing with it.



# /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









share|improve this question













I want to run a bash script to update the ifcfg script files every time the system is rebooted and when systemctl restart network.service is run (Also when Reload & Start are run). The script is meant to check that the correct HWADDR is in the file, and if not it updates it. I am using custom Network Device Names.



I Created a SystemD service file which seems to run before network is up on reboot, but if the network configuration is changed during operation, and systemctl restart network.service or systemctl reload network.service is run it does not run the script file. Please Help!



Note: My service file is a little dirty, as I have been testing with it.



# /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






networking centos redhat systemd






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 at 22:42









Rahim Khoja

380717




380717












  • I found that I could use the dispatcher Pre Up directory to get the results I wanted. /etc/NetworkManager/dispatcher.d/pre-up.d . However it should be possible to do this with a systemd service file.
    – Rahim Khoja
    2 days ago


















  • I found that I could use the dispatcher Pre Up directory to get the results I wanted. /etc/NetworkManager/dispatcher.d/pre-up.d . However it should be possible to do this with a systemd service file.
    – Rahim Khoja
    2 days ago
















I found that I could use the dispatcher Pre Up directory to get the results I wanted. /etc/NetworkManager/dispatcher.d/pre-up.d . However it should be possible to do this with a systemd service file.
– Rahim Khoja
2 days ago




I found that I could use the dispatcher Pre Up directory to get the results I wanted. /etc/NetworkManager/dispatcher.d/pre-up.d . However it should be possible to do this with a systemd service file.
– Rahim Khoja
2 days ago

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421450%2fcentos-7-how-to-run-bash-script-everytime-systemctl-restart-network-service%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421450%2fcentos-7-how-to-run-bash-script-everytime-systemctl-restart-network-service%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

What visual should I use to simply compare current year value vs last year in Power BI desktop

Alexandru Averescu

Trompette piccolo