mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
tor, torproxy: Fix daemon services are running after reboot when app is disabled
Mask disabled Tor systemd services to prevent services starting by the Tor
master service after system reboot.
Also:
- Fix torproxy app always enabled after setup.
- Minor privileged code cleanup - removed unused functions.
Tests performed on Debian stable and testing:
- Installed and disabled the apps, rebooted the system, then applied the patch.
Ensured that apps are upgraded successfully and apps are disabled after
upgrade. Ensured that tor@default, tor@plinth and tor@fbxlocal services are
masked and not running.
- After 1)enabling and 2)disabling both apps and 3)rebooting the system:
- Ensured that the tor@default service is not running and is masked.
- Ensured that tor@plinth or tor@fbxproxy service states match the states
of the app.
- Uninstalled the apps, ensured that only the tor@default service masked
state remains in the systemd.
- All the tor and torproxy tests pass.
Closes #2369, #2454.
Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
1 parent
cde3f151fb
commit
2e7b9f8a8e
4 files changed
+40
-38
No files matched your search
@@ -24,18 +24,16 @@ TORPROXY_CONFIG_AUG = f'/files/{TORPROXY_CONFIG}'
|
||||
|
||||
|
||||
@privileged
|
||||
def setup(old_version: int):
|
||||
"""Setup Tor configuration after installing it."""
|
||||
_first_time_setup()
|
||||
|
||||
|
||||
def _first_time_setup():
|
||||
"""Setup Tor configuration for the first time setting defaults."""
|
||||
logger.info('Performing first time setup for Tor Proxy')
|
||||
def setup():
|
||||
"""Setup Tor configuration."""
|
||||
# Disable default tor service. We will use tor@fbxproxy instance
|
||||
# instead.
|
||||
_disable_apt_transport_tor()
|
||||
|
||||
# Disable default Tor service.
|
||||
action_utils.service_disable('tor@default')
|
||||
# Mask the service to prevent re-enabling it by the Tor master service.
|
||||
action_utils.service_mask('tor@default')
|
||||
|
||||
subprocess.run(['tor-instance-create', INSTANCE_NAME], check=True)
|
||||
|
||||
@@ -61,8 +59,8 @@ def _first_time_setup():
|
||||
|
||||
aug.save()
|
||||
|
||||
action_utils.service_enable(SERVICE_NAME)
|
||||
action_utils.service_restart(SERVICE_NAME)
|
||||
if action_utils.service_is_running(SERVICE_NAME):
|
||||
action_utils.service_restart(SERVICE_NAME)
|
||||
|
||||
|
||||
@privileged
|
||||
@@ -114,17 +112,6 @@ def _get_upstream_bridges(aug) -> str:
|
||||
return '\n'.join(bridges)
|
||||
|
||||
|
||||
def _enable():
|
||||
"""Enable and start the service."""
|
||||
action_utils.service_enable(SERVICE_NAME)
|
||||
|
||||
|
||||
def _disable():
|
||||
"""Disable and stop the service."""
|
||||
_disable_apt_transport_tor()
|
||||
action_utils.service_disable(SERVICE_NAME)
|
||||
|
||||
|
||||
def _use_upstream_bridges(use_upstream_bridges: bool | None = None, aug=None):
|
||||
"""Enable use of upstream bridges."""
|
||||
if use_upstream_bridges is None:
|
||||
@@ -214,3 +201,4 @@ def uninstall():
|
||||
shutil.rmtree(directory, ignore_errors=True)
|
||||
|
||||
os.unlink(f'/var/run/tor-instances/{INSTANCE_NAME}.defaults')
|
||||
action_utils.service_unmask(SERVICE_NAME)
|
||||
Reference in new issue
Block a user