mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-19 12:36:06 +00:00
tor: Ensure that is-enabled status is show properly
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
parent
45c23068db
commit
527aa66494
@ -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
|
||||
|
||||
|
||||
@ -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():
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user