gvaweb/gvaweb/webtasks/tasks.py

113 lines
2.5 KiB
Python

"""
This module defines Celery_ tasks to manage website configurations.
"""
from __future__ import absolute_import
import os
from celery import shared_task
from celery.utils.log import get_task_logger
from gvaweb import settings
_LOGGER = get_task_logger(__name__)
SUDO_CMD = '/usr/bin/sudo'
RM_CMD = '/bin/rm'
LN_CMD = '/bin/ln'
SERVICE_CMD = '/usr/sbin/service'
INSTALL_CMD = '/usr/bin/install'
def _build_vhost_config_path(sitename):
return os.path.join(settings.GVAWEB_NGINX_SITES_AVAILABLE, sitename)
def _build_enabled_vhost_path(sitename):
return os.path.join(settings.GVAWEB_NGINX_SITES_ENABLED, sitename)
def _build_php_fpm_pool_file(username):
return os.path.join(settings.GVAWEB_PHPFPM_POOL, "{username}.conf".format(
username=username))
def _build_document_root_path(sitename, username):
return os.path.join(
settings.GVAWEB_WWWUSER_MOUNT, username, sitename, 'html')
@shared_task
def create_web_vhost_config(username, sitename):
"""
This task creates a virtual host configuration on an nginx web
server.
:param str username: user who owns the site
:param str sitename: site name
:return: :py:const:`True` if the creation finished successfully
:rtype: boolean
"""
@shared_task
def disable_web_vhost(sitename):
"""
This task disables a virtual host configuration on an nginx web server.
:param str sitename: site name
:return: :py:const:`True` if the virtual host has been disabled
:rtype: boolean
"""
@shared_task
def enable_web_vhost(sitename):
"""
This task enables an existing virtual host configuration on an nginx web
server.
:param str sitename: site name
:return: :py:const:`True` if the virtual host has been enabled
:rtype: boolean
"""
@shared_task
def delete_web_vhost_config(sitename):
"""
This task removes a virtual host configuration on an nginx web server.
:param str sitename: site name
:return: :py:const:`True` if the configuration has been deleted
:rtype: boolean
"""
@shared_task
def create_web_php_fpm_pool_config(username):
"""
This task creates a PHP FPM pool configuration.
:param str username: user name
:return: :py:const:`True` if the creation finished successfully
:rtype: boolean
"""
@shared_task
def delete_web_php_fpm_pool_config(username):
"""
This task deletes a PHP FPM pool configuration.
:param str username: user name
:return: :py:const:`True` if the pool has been deleted
:rtype: boolean
"""