From 739fab288779a70cdfcb45716a3bcee1cf55571d Mon Sep 17 00:00:00 2001 From: Marc Date: Fri, 24 Oct 2014 12:12:20 +0000 Subject: [PATCH] Added better support for domain account migration --- orchestra/apps/webapps/backends/__init__.py | 6 ++++++ orchestra/apps/webapps/backends/phpfcgid.py | 5 +++++ orchestra/apps/webapps/backends/phpfpm.py | 5 +++++ orchestra/apps/webapps/backends/static.py | 5 +++++ orchestra/apps/webapps/models.py | 2 +- 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/orchestra/apps/webapps/backends/__init__.py b/orchestra/apps/webapps/backends/__init__.py index b96a592a..c3fb9f4c 100644 --- a/orchestra/apps/webapps/backends/__init__.py +++ b/orchestra/apps/webapps/backends/__init__.py @@ -1,9 +1,15 @@ import pkgutil import textwrap +from .. import settings + class WebAppServiceMixin(object): model = 'webapps.WebApp' + directive = None + + def valid_directive(self, webapp): + return settings.WEBAPPS_TYPES[webapp.type]['directive'][0] == self.directive def create_webapp_dir(self, context): self.append(textwrap.dedent(""" diff --git a/orchestra/apps/webapps/backends/phpfcgid.py b/orchestra/apps/webapps/backends/phpfcgid.py index c796ac3f..0552d15d 100644 --- a/orchestra/apps/webapps/backends/phpfcgid.py +++ b/orchestra/apps/webapps/backends/phpfcgid.py @@ -12,8 +12,11 @@ from .. import settings class PHPFcgidBackend(WebAppServiceMixin, ServiceController): """ Per-webapp fcgid application """ verbose_name = _("PHP-Fcgid") + directive = 'fcgi' def save(self, webapp): + if not self.valid_directive(webapp): + return context = self.get_context(webapp) self.create_webapp_dir(context) self.append("mkdir -p %(wrapper_dir)s" % context) @@ -27,6 +30,8 @@ class PHPFcgidBackend(WebAppServiceMixin, ServiceController): self.append("chown -R %(user)s.%(group)s %(wrapper_dir)s" % context) def delete(self, webapp): + if not self.valid_directive(webapp): + return context = self.get_context(webapp) self.append("rm '%(wrapper_path)s'" % context) self.delete_webapp_dir(context) diff --git a/orchestra/apps/webapps/backends/phpfpm.py b/orchestra/apps/webapps/backends/phpfpm.py index eb0d5ea2..fa0384a1 100644 --- a/orchestra/apps/webapps/backends/phpfpm.py +++ b/orchestra/apps/webapps/backends/phpfpm.py @@ -13,8 +13,11 @@ from .. import settings class PHPFPMBackend(WebAppServiceMixin, ServiceController): """ Per-webapp php application """ verbose_name = _("PHP-FPM") + directive = 'fpm' def save(self, webapp): + if not self.valid_directive(webapp) + return context = self.get_context(webapp) self.create_webapp_dir(context) self.append(textwrap.dedent("""\ @@ -39,6 +42,8 @@ class PHPFPMBackend(WebAppServiceMixin, ServiceController): }""")) def get_context(self, webapp): + if not self.valid_directive(webapp): + return context = super(PHPFPMBackend, self).get_context(webapp) context.update({ 'init_vars': self.get_php_init_vars(webapp), diff --git a/orchestra/apps/webapps/backends/static.py b/orchestra/apps/webapps/backends/static.py index 7b834ec0..f06c7eef 100644 --- a/orchestra/apps/webapps/backends/static.py +++ b/orchestra/apps/webapps/backends/static.py @@ -7,11 +7,16 @@ from . import WebAppServiceMixin class StaticBackend(WebAppServiceMixin, ServiceController): verbose_name = _("Static") + directive = 'static' def save(self, webapp): + if not self.valid_directive(webapp): + return context = self.get_context(webapp) self.create_webapp_dir(context) def delete(self, webapp): + if not self.valid_directive(webapp): + return context = self.get_context(webapp) self.delete_webapp_dir(context) diff --git a/orchestra/apps/webapps/models.py b/orchestra/apps/webapps/models.py index 03eba5a1..3449ef30 100644 --- a/orchestra/apps/webapps/models.py +++ b/orchestra/apps/webapps/models.py @@ -42,7 +42,7 @@ class WebApp(models.Model): def get_path(self): context = { - 'home': webapp.get_user().get_home(), + 'home': self.get_user().get_home(), 'app_name': self.name, } return settings.WEBAPPS_BASE_ROOT % context