Skip to content

Commit

Permalink
Check if a service has already been restarted (Fixes #1338)
Browse files Browse the repository at this point in the history
  • Loading branch information
Max G committed Jul 10, 2020
1 parent c2ebad9 commit bb1b8e8
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions updateHostsFile.py
Expand Up @@ -1293,13 +1293,17 @@ def flush_dns_cache():

system_prefixes = ["/usr", ""]
service_types = ["NetworkManager", "wicd", "dnsmasq", "networking"]
restarted_services = []

for system_prefix in system_prefixes:
systemctl = system_prefix + "/bin/systemctl"
system_dir = system_prefix + "/lib/systemd/system"

for service_type in service_types:
service = service_type + ".service"
if service in restarted_services:
continue

service_file = path_join_robust(system_dir, service)
service_msg = (
"Flushing the DNS cache by restarting " + service + " {result}"
Expand All @@ -1312,6 +1316,7 @@ def flush_dns_cache():
print_failure(service_msg.format(result="failed"))
else:
print_success(service_msg.format(result="succeeded"))
restarted_services += [service]

dns_clean_file = "/etc/init.d/dns-clean"
dns_clean_msg = "Flushing the DNS cache via dns-clean executable {result}"
Expand Down

0 comments on commit bb1b8e8

Please sign in to comment.