radicale: Don't keep radicale service running

- uwsgi service is sufficient to handle radicale2. Disable radicale service for
  radicale2.

- Use action utils to deal with uwsgi configuration management.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2019-01-14 15:18:03 -08:00 committed by James Valleroy
parent bed43564c3
commit 3e98930f94
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 82 additions and 59 deletions

View File

@ -15,29 +15,21 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
""" """
Configuration helper for Radicale. Configuration helper for Radicale.
""" """
import argparse import argparse
import augeas import augeas
import os
import subprocess
from distutils.version import LooseVersion as LV
from plinth import action_utils from plinth import action_utils
from plinth.modules import radicale
CONFIG_FILE = '/etc/radicale/config' CONFIG_FILE = '/etc/radicale/config'
DEFAULT_FILE = '/etc/default/radicale' DEFAULT_FILE = '/etc/default/radicale'
UWSGI_FILE = '/etc/uwsgi/apps-available/radicale.ini'
UWSGI_LINK = '/etc/uwsgi/apps-enabled/radicale.ini'
VERSION_2 = LV('2')
def parse_arguments(): def parse_arguments():
"""Return parsed command line arguments as dictionary.""" """Return parsed command line arguments as dictionary."""
@ -58,19 +50,19 @@ def parse_arguments():
def subcommand_setup(_): def subcommand_setup(_):
"""Setup Radicale configuration.""" """Setup Radicale configuration."""
current_version = _get_version() current_version = radicale.get_package_version()
if not current_version: if not current_version:
print('Warning: Unable to get radicale version.') print('Warning: Unable to get radicale version.')
aug = load_augeas() aug = load_augeas()
if current_version and current_version < VERSION_2: if current_version and current_version < radicale.VERSION_2:
aug.set('/files' + DEFAULT_FILE + '/ENABLE_RADICALE', 'yes') aug.set('/files' + DEFAULT_FILE + '/ENABLE_RADICALE', 'yes')
aug.set('/files' + CONFIG_FILE + '/server/hosts', aug.set('/files' + CONFIG_FILE + '/server/hosts',
'127.0.0.1:5232, [::1]:5232') '127.0.0.1:5232, [::1]:5232')
aug.set('/files' + CONFIG_FILE + '/rights/type', 'owner_only') aug.set('/files' + CONFIG_FILE + '/rights/type', 'owner_only')
if current_version and current_version < VERSION_2: if current_version and current_version < radicale.VERSION_2:
aug.set('/files' + CONFIG_FILE + '/server/base_prefix', '/radicale/') aug.set('/files' + CONFIG_FILE + '/server/base_prefix', '/radicale/')
aug.set('/files' + CONFIG_FILE + '/well-known/caldav', aug.set('/files' + CONFIG_FILE + '/well-known/caldav',
'/radicale/%(user)s/caldav/') '/radicale/%(user)s/caldav/')
@ -82,17 +74,7 @@ def subcommand_setup(_):
aug.save() aug.save()
action_utils.service_enable('radicale') subcommand_enable(None)
action_utils.service_restart('radicale')
action_utils.webserver_enable(_get_web_config(current_version))
# Enable uwsgi for radicale 2.x. Do this after radicale is
# started, so it creates the necessary folders.
if current_version and current_version >= VERSION_2:
if not os.path.exists(UWSGI_LINK):
os.symlink(UWSGI_FILE, UWSGI_LINK)
action_utils.webserver_enable('proxy_uwsgi', kind='module')
action_utils.service_restart('uwsgi')
def subcommand_configure(arguments): def subcommand_configure(arguments):
@ -106,37 +88,26 @@ def subcommand_configure(arguments):
def subcommand_enable(_): def subcommand_enable(_):
"""Start service.""" """Start service."""
action_utils.service_enable('radicale') if radicale.get_package_version() >= radicale.VERSION_2:
action_utils.webserver_enable(_get_web_config()) # Enable uwsgi for radicale 2.x. Do this after radicale is
# started, so it creates the necessary folders.
action_utils.service_disable('radicale')
action_utils.uwsgi_enable('radicale')
action_utils.webserver_enable('proxy_uwsgi', kind='module')
else:
action_utils.service_enable('radicale')
action_utils.service_restart('radicale')
action_utils.webserver_enable(radicale.get_web_config())
def subcommand_disable(_): def subcommand_disable(_):
"""Stop service.""" """Stop service."""
action_utils.webserver_disable(_get_web_config()) action_utils.webserver_disable(radicale.get_web_config())
action_utils.service_disable('radicale') if radicale.get_package_version() >= radicale.VERSION_2:
action_utils.uwsgi_disable('radicale')
else:
def _get_version(): action_utils.service_disable('radicale')
try:
proc = subprocess.run(
['radicale', '--version'], stdout=subprocess.PIPE, check=True)
output = proc.stdout.decode('utf-8')
except subprocess.CalledProcessError:
return None
version = str(output.strip())
return LV(version)
def _get_web_config(current_version=None):
"""Return the name of the webserver configuration based on version."""
if current_version is None:
current_version = _get_version()
if current_version and current_version < VERSION_2:
return 'radicale-plinth'
return 'radicale2-freedombox'
def load_augeas(): def load_augeas():

View File

@ -18,12 +18,15 @@
FreedomBox app for radicale. FreedomBox app for radicale.
""" """
import subprocess
from distutils.version import LooseVersion as LV
import augeas import augeas
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from plinth import service as service_module
from plinth import action_utils, actions, cfg, frontpage from plinth import action_utils, actions, cfg, frontpage
from plinth import service as service_module
from plinth.menu import main_menu from plinth.menu import main_menu
from plinth.utils import format_lazy from plinth.utils import format_lazy
@ -58,21 +61,24 @@ manual_page = 'Radicale'
CONFIG_FILE = '/etc/radicale/config' CONFIG_FILE = '/etc/radicale/config'
VERSION_2 = LV('2')
def init(): def init():
"""Initialize the radicale module.""" """Initialize the radicale module."""
menu = main_menu.get('apps') menu = main_menu.get('apps')
menu.add_urlname(name, 'radicale', 'radicale:index', menu.add_urlname(name, 'radicale', 'radicale:index', short_description)
short_description)
global service global service
setup_helper = globals()['setup_helper'] setup_helper = globals()['setup_helper']
if setup_helper.get_state() != 'needs-setup': if setup_helper.get_state() != 'needs-setup':
service = service_module.Service(managed_services[0], name, ports=[ service = service_module.Service(managed_services[0], name, ports=[
'http', 'https' 'http', 'https'
], is_external=True, enable=enable, disable=disable) ], is_external=True, is_enabled=is_enabled, enable=enable,
disable=disable,
is_running=is_running)
if service.is_enabled(): if is_enabled():
add_shortcut() add_shortcut()
@ -84,7 +90,9 @@ def setup(helper, old_version=None):
if service is None: if service is None:
service = service_module.Service(managed_services[0], name, ports=[ service = service_module.Service(managed_services[0], name, ports=[
'http', 'https' 'http', 'https'
], is_external=True, enable=enable, disable=disable) ], is_external=True, is_enabled=is_enabled, enable=enable,
disable=disable,
is_running=is_running)
helper.call('post', service.notify_enabled, None, True) helper.call('post', service.notify_enabled, None, True)
helper.call('post', add_shortcut) helper.call('post', add_shortcut)
@ -96,6 +104,50 @@ def add_shortcut():
login_required=True) login_required=True)
def get_package_version():
try:
proc = subprocess.run(['radicale', '--version'],
stdout=subprocess.PIPE, check=True)
output = proc.stdout.decode('utf-8')
except subprocess.CalledProcessError:
return None
package_version = str(output.strip())
return LV(package_version)
def get_web_config(current_version=None):
"""Return the name of the webserver configuration based on version."""
if current_version is None:
current_version = get_package_version()
if current_version and current_version < VERSION_2:
return 'radicale-plinth'
return 'radicale2-freedombox'
def is_running():
"""Return whether the service is running."""
if get_package_version() < VERSION_2:
return action_utils.service_is_running('radicale')
return action_utils.service_is_running('uwsgi') \
and action_utils.uwsgi_is_enabled('radicale')
def is_enabled():
"""Return whether the module is enabled."""
package_version = get_package_version()
if package_version >= VERSION_2:
daemon_enabled = action_utils.uwsgi_is_enabled('radicale')
else:
daemon_enabled = action_utils.service_is_enabled('radicale')
return (action_utils.webserver_is_enabled(get_web_config(package_version))
and daemon_enabled)
def enable(): def enable():
"""Enable the module.""" """Enable the module."""
actions.superuser_run('radicale', ['enable']) actions.superuser_run('radicale', ['enable'])
@ -110,8 +162,8 @@ def disable():
def load_augeas(): def load_augeas():
"""Prepares the augeas.""" """Prepares the augeas."""
aug = augeas.Augeas( aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD +
flags=augeas.Augeas.NO_LOAD + augeas.Augeas.NO_MODL_AUTOLOAD) augeas.Augeas.NO_MODL_AUTOLOAD)
# INI file lens # INI file lens
aug.set('/augeas/load/Puppet/lens', 'Puppet.lns') aug.set('/augeas/load/Puppet/lens', 'Puppet.lns')