django-orchestra-test/orchestra/apps/webapps/backends/phpfcgid.py

59 lines
2.1 KiB
Python
Raw Normal View History

2014-05-08 16:59:35 +00:00
import os
2014-10-10 14:39:46 +00:00
import textwrap
2014-05-08 16:59:35 +00:00
from django.utils.translation import ugettext_lazy as _
2014-07-09 16:17:43 +00:00
from orchestra.apps.orchestration import ServiceController
2014-05-08 16:59:35 +00:00
from . import WebAppServiceMixin
from .. import settings
2014-07-09 16:17:43 +00:00
class PHPFcgidBackend(WebAppServiceMixin, ServiceController):
""" Per-webapp fcgid application """
2014-05-08 16:59:35 +00:00
verbose_name = _("PHP-Fcgid")
def save(self, webapp):
context = self.get_context(webapp)
self.create_webapp_dir(context)
self.append("mkdir -p %(wrapper_dir)s" % context)
2014-10-10 14:39:46 +00:00
self.append(textwrap.dedent("""\
{
echo -e '%(wrapper_content)s' | diff -N -I'^\s*#' %(wrapper_path)s -
} || {
echo -e '%(wrapper_content)s' > %(wrapper_path)s; UPDATED_APACHE=1
}""" % context))
2014-05-08 16:59:35 +00:00
self.append("chmod +x %(wrapper_path)s" % context)
self.append("chown -R %(user)s.%(group)s %(wrapper_dir)s" % context)
def delete(self, webapp):
context = self.get_context(webapp)
self.append("rm '%(wrapper_path)s'" % context)
2014-05-08 16:59:35 +00:00
self.delete_webapp_dir(context)
2014-10-10 14:39:46 +00:00
def commit(self):
super(PHPFcgidBackend, self).commit()
self.append("[[ $UPDATED_APACHE == 1 ]] && { /etc/init.d/apache reload; }")
2014-05-08 16:59:35 +00:00
def get_context(self, webapp):
context = super(PHPFcgidBackend, self).get_context(webapp)
init_vars = self.get_php_init_vars(webapp)
2014-05-08 16:59:35 +00:00
if init_vars:
init_vars = [ '%s="%s"' % (k,v) for v,k in init_vars.iteritems() ]
init_vars = ', -d '.join(init_vars)
context['init_vars'] = '-d %s' % init_vars
else:
context['init_vars'] = ''
wrapper_path = settings.WEBAPPS_FCGID_PATH % context
context.update({
2014-10-10 14:39:46 +00:00
'wrapper_content': textwrap.dedent("""\
#!/bin/sh
# %(banner)s
export PHPRC=/etc/%(type)s/cgi/
exec /usr/bin/%(type)s-cgi %(init_vars)s
""" % context),
2014-05-08 16:59:35 +00:00
'wrapper_path': wrapper_path,
'wrapper_dir': os.path.dirname(wrapper_path),
})
return context