mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
deluge: Manage starting/stoping deluged
- run deluged daemon with default configuration location - deluge-web: autoconnect to the deluged daemon - functional tests: assert deluge-web is connected to the deluged daemon Signed-off-by: Veiko Aasa <veiko17@disroot.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
1 parent
7d2c57bbf5
commit
ff27f1d21b
4 files changed
+76
-43
No files matched your search
+62
-5
@@ -20,10 +20,18 @@ Configuration helper for BitTorrent web client.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import fileinput
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
SYSTEMD_SERVICE_PATH = '/etc/systemd/system/deluge-web.service'
|
||||
SYSTEMD_SERVICE = '''
|
||||
import augeas
|
||||
from plinth import action_utils
|
||||
|
||||
DELUGED_DEFAULT_FILE = '/etc/default/deluged'
|
||||
DELUGE_WEB_CONFIG_FILE = '/var/lib/deluged/.config/deluge/web.conf'
|
||||
|
||||
DELUGE_WEB_SYSTEMD_SERVICE_PATH = '/etc/systemd/system/deluge-web.service'
|
||||
DELUGE_WEB_SYSTEMD_SERVICE = '''
|
||||
#
|
||||
# This file is managed and overwritten by Plinth. If you wish to edit
|
||||
# it, disable Deluge in Plinth, remove this file and manage it manually.
|
||||
@@ -69,12 +77,61 @@ def parse_arguments():
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def _set_configuration(filename, parameter, value):
|
||||
"""Set the configuration parameter."""
|
||||
deluged_is_running = action_utils.service_is_running('deluged')
|
||||
if deluged_is_running:
|
||||
action_utils.service_stop('deluged')
|
||||
deluge_web_is_running = action_utils.service_is_running('deluge-web')
|
||||
if deluge_web_is_running:
|
||||
action_utils.service_stop('deluge-web')
|
||||
|
||||
for line in fileinput.FileInput(filename, inplace=True):
|
||||
if '"{0}"'.format(parameter) in line:
|
||||
print(' "{0}": "{1}", '.format(parameter, value))
|
||||
else:
|
||||
print(line, end='')
|
||||
|
||||
if deluged_is_running:
|
||||
action_utils.service_start('deluged')
|
||||
if deluge_web_is_running:
|
||||
action_utils.service_start('deluge-web')
|
||||
|
||||
|
||||
def _set_deluged_daemon_options():
|
||||
"""Set deluged daemon options."""
|
||||
aug = augeas.Augeas(
|
||||
flags=augeas.Augeas.NO_LOAD + augeas.Augeas.NO_MODL_AUTOLOAD)
|
||||
aug.set('/augeas/load/Shellvars/lens', 'Shellvars.lns')
|
||||
aug.set('/augeas/load/Shellvars/incl[last() + 1]', DELUGED_DEFAULT_FILE)
|
||||
aug.load()
|
||||
aug.set('/files' + DELUGED_DEFAULT_FILE + '/ENABLE_DELUGED', '1')
|
||||
# overwrite daemon args, use default config directory (same as deluge-web)
|
||||
aug.set('/files' + DELUGED_DEFAULT_FILE + '/DAEMON_ARGS',
|
||||
'"-d -l /var/log/deluged/daemon.log -L info"')
|
||||
aug.save()
|
||||
|
||||
|
||||
def subcommand_setup(_):
|
||||
"""Perform initial setup for deluge-web."""
|
||||
with open(SYSTEMD_SERVICE_PATH, 'w') as file_handle:
|
||||
file_handle.write(SYSTEMD_SERVICE)
|
||||
"""Perform initial setup for deluge."""
|
||||
|
||||
with open(DELUGE_WEB_SYSTEMD_SERVICE_PATH, 'w') as file_handle:
|
||||
file_handle.write(DELUGE_WEB_SYSTEMD_SERVICE)
|
||||
|
||||
_set_deluged_daemon_options()
|
||||
|
||||
subprocess.check_call(['systemctl', 'daemon-reload'])
|
||||
# restarting deluge-web service stops also possible deluged process
|
||||
# that was started from the web interface
|
||||
action_utils.service_restart('deluge-web')
|
||||
action_utils.service_restart('deluged')
|
||||
# wait processes to start
|
||||
time.sleep(5)
|
||||
|
||||
# configure deluge-web to autoconnect to the default deluged daemon, also
|
||||
# restarts deluged and deluge-web services again to create config files
|
||||
_set_configuration(DELUGE_WEB_CONFIG_FILE, 'default_daemon',
|
||||
'127.0.0.1:58846')
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in new issue
Block a user