diff --git a/plinth/action_utils.py b/plinth/action_utils.py index dbf94cd0c..e5acc96b5 100644 --- a/plinth/action_utils.py +++ b/plinth/action_utils.py @@ -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 diff --git a/plinth/modules/tor/utils.py b/plinth/modules/tor/utils.py index 36f62ad68..d79e87754 100644 --- a/plinth/modules/tor/utils.py +++ b/plinth/modules/tor/utils.py @@ -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():