pagekite: Use Daemon component to simplify handling daemon actions

- Turn some methods in action script to private to improve abstraction.

- Always enable the predefined services when setting the configuration for the
first time.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
Sunil Mohan Adapa authored and Veiko Aasa committed 2020-03-15 09:27:07 +02:00
1 parent a1c1104a61
commit 98ecb6ea40
3 files changed
+33 -71

No files matched your search

+3 -1
View File
@@ -7,6 +7,7 @@ from django.utils.translation import ugettext_lazy as _
from plinth import app as app_module
from plinth import cfg, menu
from plinth.daemon import Daemon
from plinth.modules.names.components import DomainType
from plinth.utils import format_lazy
@@ -75,7 +76,8 @@ class PagekiteApp(app_module.App):
'pagekite:index', can_have_certificate=True)
self.add(domain_type)
# XXX: Add pagekite daemon component and simplify action script
daemon = Daemon('daemon-pagekite', managed_services[0])
self.add(daemon)
def init():
-35
View File
@@ -2,7 +2,6 @@
import copy
import json
import logging
from django import forms
from django.contrib import messages
@@ -15,8 +14,6 @@ from plinth.forms import AppForm
from . import utils
LOGGER = logging.getLogger(__name__)
class TrimmedCharField(forms.CharField):
"""Trim the contents of a CharField"""
@@ -92,38 +89,6 @@ class ConfigurationForm(AppForm):
frontend
], input=new['kite_secret'].encode())
messages.success(request, _('Configuration updated'))
config_changed = True
if old['is_enabled'] != new['is_enabled']:
if new['is_enabled']:
utils.run(['start-and-enable'])
# Ensure all standard/predefined services are enabled
for service_name in utils.PREDEFINED_SERVICES.keys():
service = \
utils.PREDEFINED_SERVICES[service_name]['params']
service = json.dumps(service)
# Probably should keep track of which services
# are enabled since adding the service produces
# an error if it is already added. But this works
# too.
try:
utils.run(['add-service', '--service', service])
except ActionError as exception:
if "already exists" in str(exception):
pass
else:
raise
messages.success(request, _('PageKite enabled'))
else:
utils.run(['stop-and-disable'])
messages.success(request, _('PageKite disabled'))
# Restart the service if the config was changed while the service
# was running, so changes take effect immediately.
elif config_changed and new['is_enabled']:
utils.run(['restart'])
# Update kite name registered with Name Services module.
utils.update_names_module(enabled=new['is_enabled'],