Skip to content

Commit

Permalink
Merge pull request #1339 from codeswhite/patch-systemctl-restart-check
Browse files Browse the repository at this point in the history
Check if a service is running (Fixed #1337)
  • Loading branch information
StevenBlack committed Jul 11, 2020
2 parents be57b62 + 9e3db93 commit c9986cc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion testUpdateHostsFile.py
Expand Up @@ -1324,7 +1324,7 @@ def test_flush_posix_fail(self, *_):
self.assertIn(expected, output)

@mock.patch("os.path.isfile", side_effect=[True, False, False, True] + [False] * 10)
@mock.patch("subprocess.call", side_effect=[1, 0])
@mock.patch("subprocess.call", side_effect=[1, 0, 0])
def test_flush_posix_fail_then_succeed(self, *_):
with self.mock_property("platform.system") as obj:
obj.return_value = "Linux"
Expand Down
3 changes: 3 additions & 0 deletions updateHostsFile.py
Expand Up @@ -1306,6 +1306,9 @@ def flush_dns_cache():
)

if os.path.isfile(service_file):
if 0 != subprocess.call([systemctl, "status", service],
stdout=subprocess.DEVNULL):
continue
dns_cache_found = True

if subprocess.call(SUDO + [systemctl, "restart", service]):
Expand Down

0 comments on commit c9986cc

Please sign in to comment.