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
networking centos redhat systemd
add a comment |
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
networking centos redhat systemd
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
add a comment |
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
networking centos redhat systemd
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
networking centos redhat systemd
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
add a comment |
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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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