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
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
"""
Configuration helper for Radicale.
"""
import argparse
import augeas
import os
import subprocess
from distutils.version import LooseVersion as LV
from plinth import action_utils
from plinth.modules import radicale
CONFIG_FILE = '/etc/radicale/config'
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():
"""Return parsed command line arguments as dictionary."""
@ -58,19 +50,19 @@ def parse_arguments():
def subcommand_setup(_):
"""Setup Radicale configuration."""
current_version = _get_version()
current_version = radicale.get_package_version()
if not current_version:
print('Warning: Unable to get radicale version.')
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' + CONFIG_FILE + '/server/hosts',
'127.0.0.1:5232, [::1]:5232')
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 + '/well-known/caldav',
'/radicale/%(user)s/caldav/')
@ -82,17 +74,7 @@ def subcommand_setup(_):
aug.save()
action_utils.service_enable('radicale')
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')
subcommand_enable(None)
def subcommand_configure(arguments):
@ -106,37 +88,26 @@ def subcommand_configure(arguments):
def subcommand_enable(_):
"""Start service."""
action_utils.service_enable('radicale')
action_utils.webserver_enable(_get_web_config())
if radicale.get_package_version() >= radicale.VERSION_2:
# 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(_):
"""Stop service."""
action_utils.webserver_disable(_get_web_config())
action_utils.service_disable('radicale')
def _get_version():
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'
action_utils.webserver_disable(radicale.get_web_config())
if radicale.get_package_version() >= radicale.VERSION_2:
action_utils.uwsgi_disable('radicale')
else:
action_utils.service_disable('radicale')
def load_augeas():

View File

@ -18,12 +18,15 @@
FreedomBox app for radicale.
"""
import subprocess
from distutils.version import LooseVersion as LV
import augeas
from django.urls import reverse_lazy
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 service as service_module
from plinth.menu import main_menu
from plinth.utils import format_lazy
@ -58,21 +61,24 @@ manual_page = 'Radicale'
CONFIG_FILE = '/etc/radicale/config'
VERSION_2 = LV('2')
def init():
"""Initialize the radicale module."""
menu = main_menu.get('apps')
menu.add_urlname(name, 'radicale', 'radicale:index',
short_description)
menu.add_urlname(name, 'radicale', 'radicale:index', short_description)
global service
setup_helper = globals()['setup_helper']
if setup_helper.get_state() != 'needs-setup':
service = service_module.Service(managed_services[0], name, ports=[
'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()
@ -84,7 +90,9 @@ def setup(helper, old_version=None):
if service is None:
service = service_module.Service(managed_services[0], name, ports=[
'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', add_shortcut)
@ -96,6 +104,50 @@ def add_shortcut():
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():
"""Enable the module."""
actions.superuser_run('radicale', ['enable'])
@ -110,8 +162,8 @@ def disable():
def load_augeas():
"""Prepares the augeas."""
aug = augeas.Augeas(
flags=augeas.Augeas.NO_LOAD + augeas.Augeas.NO_MODL_AUTOLOAD)
aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD +
augeas.Augeas.NO_MODL_AUTOLOAD)
# INI file lens
aug.set('/augeas/load/Puppet/lens', 'Puppet.lns')