mirror of
https://github.com/StevenBlack/hosts.git
synced 2026-09-28 22:05:58 +01:00
Merge pull request #1339 from codeswhite/patch-systemctl-restart-check
Check if a service is running (Fixed #1337)
This commit is contained in:
@@ -1324,7 +1324,7 @@ class TestFlushDnsCache(BaseStdout):
|
||||
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"
|
||||
|
||||
@@ -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]):
|
||||
|
||||
Reference in New Issue
Block a user