tor: Ensure that is-enabled status is show properly

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Sunil Mohan Adapa 2018-01-30 16:58:28 +05:30
parent 45c23068db
commit 527aa66494
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
2 changed files with 17 additions and 6 deletions

View File

@ -56,12 +56,23 @@ def service_is_running(servicename):
return False
def service_is_enabled(service_name):
"""Check if service is enabled in systemd."""
def service_is_enabled(service_name, strict_check=False):
"""Check if service is enabled in systemd.
In some cases, after disabling a service, systemd puts it into a state
called 'enabled-runtime' and returns a positive response to 'is-enabled'
query. Until we understand better, a conservative work around is to pass
strict=True to services effected by this behavior.
"""
try:
subprocess.run(['systemctl', 'is-enabled', service_name], check=True,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
return True
process = subprocess.run(['systemctl', 'is-enabled', service_name],
check=True, stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL)
if not strict_check:
return True
return process.stdout.decode().strip() == 'enabled'
except subprocess.CalledProcessError:
return False

View File

@ -36,7 +36,7 @@ APT_TOR_PREFIX = 'tor+'
def is_enabled():
"""Return whether the module is enabled."""
return action_utils.service_is_enabled('tor@plinth')
return action_utils.service_is_enabled('tor@plinth', strict_check=True)
def is_running():