Compare commits
3 Commits
880991984f
...
91f47c5e0d
Author | SHA1 | Date |
---|---|---|
Jorge Pastor | 91f47c5e0d | |
Jorge Pastor | 814696d65e | |
Jorge Pastor | c593385d5c |
|
@ -22,10 +22,30 @@ from .models import WebApp, WebAppOption
|
||||||
from .options import AppOption
|
from .options import AppOption
|
||||||
from .types import AppType
|
from .types import AppType
|
||||||
|
|
||||||
|
from django.db.models.signals import post_save
|
||||||
|
from django.dispatch import receiver
|
||||||
|
|
||||||
|
class WebAppOptionForm(forms.ModelForm):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = WebAppOption
|
||||||
|
fields = '__all__'
|
||||||
|
|
||||||
|
# en las app de moodle el public-root sera siempre moodle
|
||||||
|
def clean(self):
|
||||||
|
data = self.cleaned_data
|
||||||
|
webapp = self.cleaned_data.get("webapp")
|
||||||
|
if webapp.type == 'moodle-php':
|
||||||
|
if self.cleaned_data.get("name") == 'public-root':
|
||||||
|
data['value'] = 'moodle'
|
||||||
|
data['DELETE'] = False
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
class WebAppOptionInline(admin.TabularInline):
|
class WebAppOptionInline(admin.TabularInline):
|
||||||
model = WebAppOption
|
model = WebAppOption
|
||||||
extra = 1
|
extra = 1
|
||||||
|
form = WebAppOptionForm
|
||||||
|
|
||||||
OPTIONS_HELP_TEXT = {
|
OPTIONS_HELP_TEXT = {
|
||||||
op.name: force_str(op.help_text) for op in AppOption.get_plugins()
|
op.name: force_str(op.help_text) for op in AppOption.get_plugins()
|
||||||
|
@ -124,4 +144,16 @@ class WebAppAdmin(SelectPluginAdminMixin, AccountAdminMixin, ExtendedModelAdmin)
|
||||||
obj.sftpuser = user
|
obj.sftpuser = user
|
||||||
super(WebAppAdmin, self).save_model(request, obj, form, change)
|
super(WebAppAdmin, self).save_model(request, obj, form, change)
|
||||||
|
|
||||||
|
# fuerza a las app Moodle a crear public-root moodle
|
||||||
|
def response_add(self, request, obj, post_url_continue=None):
|
||||||
|
if obj.type == 'moodle-php':
|
||||||
|
mywebapp = WebApp.objects.get(id=obj.id)
|
||||||
|
WebAppOption.objects.update_or_create(
|
||||||
|
webapp=mywebapp,
|
||||||
|
name='public-root',
|
||||||
|
defaults={'value':'moodle'}
|
||||||
|
)
|
||||||
|
return super().response_add(request, obj, post_url_continue)
|
||||||
|
|
||||||
admin.site.register(WebApp, WebAppAdmin)
|
admin.site.register(WebApp, WebAppAdmin)
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,8 @@ import textwrap
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from orchestra.contrib.orchestration import ServiceController, replace
|
from orchestra.contrib.orchestration import ServiceController, replace
|
||||||
|
from django.template import Template, Context
|
||||||
|
from orchestra.settings import NEW_SERVERS
|
||||||
from .. import settings
|
from .. import settings
|
||||||
|
|
||||||
from . import WebAppServiceMixin
|
from . import WebAppServiceMixin
|
||||||
|
@ -24,6 +25,15 @@ class MoodleController(WebAppServiceMixin, ServiceController):
|
||||||
|
|
||||||
def save(self, webapp):
|
def save(self, webapp):
|
||||||
context = self.get_context(webapp)
|
context = self.get_context(webapp)
|
||||||
|
perms = Template(textwrap.dedent("""\
|
||||||
|
{% if sftpuser %}
|
||||||
|
chown -R {{sftpuser}}:{{sftpuser}} {{home}}/webapps/{{app_name}}
|
||||||
|
{% else %}
|
||||||
|
chown -R {{user}}:{{group}} {{home}}/webapps/{{app_name}}
|
||||||
|
{% endif %}
|
||||||
|
"""
|
||||||
|
))
|
||||||
|
context.update({'perms' : perms.render(Context(context))})
|
||||||
self.append(textwrap.dedent("""\
|
self.append(textwrap.dedent("""\
|
||||||
if [[ $(ls "%(app_path)s" | wc -l) -gt 1 ]]; then
|
if [[ $(ls "%(app_path)s" | wc -l) -gt 1 ]]; then
|
||||||
echo "App directory not empty." 2> /dev/null
|
echo "App directory not empty." 2> /dev/null
|
||||||
|
@ -33,6 +43,7 @@ class MoodleController(WebAppServiceMixin, ServiceController):
|
||||||
# Prevent other backends from writting here
|
# Prevent other backends from writting here
|
||||||
touch %(app_path)s/.lock
|
touch %(app_path)s/.lock
|
||||||
# Weekly caching
|
# Weekly caching
|
||||||
|
mkdir %(cms_cache_dir)s &> /dev/null || true
|
||||||
moodle_date=$(date -r $(readlink %(cms_cache_dir)s/moodle) +%%s || echo 0)
|
moodle_date=$(date -r $(readlink %(cms_cache_dir)s/moodle) +%%s || echo 0)
|
||||||
if [[ $moodle_date -lt $(($(date +%%s)-7*24*60*60)) ]]; then
|
if [[ $moodle_date -lt $(($(date +%%s)-7*24*60*60)) ]]; then
|
||||||
moodle_url=$(wget https://download.moodle.org/releases/latest/ -O - -q \\
|
moodle_url=$(wget https://download.moodle.org/releases/latest/ -O - -q \\
|
||||||
|
@ -50,10 +61,15 @@ class MoodleController(WebAppServiceMixin, ServiceController):
|
||||||
else
|
else
|
||||||
tar -xzvf %(cms_cache_dir)s/moodle -C %(app_path)s --strip-components=1
|
tar -xzvf %(cms_cache_dir)s/moodle -C %(app_path)s --strip-components=1
|
||||||
fi
|
fi
|
||||||
mkdir %(app_path)s/moodledata && {
|
# mkdir %(app_path)s/moodledata && {
|
||||||
chmod 750 %(app_path)s/moodledata
|
# chmod 750 %(app_path)s/moodledata
|
||||||
echo -n 'order deny,allow\\ndeny from all' > %(app_path)s/moodledata/.htaccess
|
# echo -n 'order deny,allow\\ndeny from all' > %(app_path)s/moodledata/.htaccess
|
||||||
|
# }
|
||||||
|
mkdir %(home)s/webapps/%(app_name)s/moodledata && {
|
||||||
|
chmod 750 %(home)s/webapps/%(app_name)s/moodledata
|
||||||
|
echo -n 'order deny,allow\\ndeny from all' > %(home)s/webapps/%(app_name)s/moodledata/.htaccess
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ ! -e %(app_path)s/config.php ]]; then
|
if [[ ! -e %(app_path)s/config.php ]]; then
|
||||||
cp %(app_path)s/config-dist.php %(app_path)s/config.php
|
cp %(app_path)s/config-dist.php %(app_path)s/config.php
|
||||||
sed -i "s#dbtype\s*= '.*#dbtype = '%(db_type)s';#" %(app_path)s/config.php
|
sed -i "s#dbtype\s*= '.*#dbtype = '%(db_type)s';#" %(app_path)s/config.php
|
||||||
|
@ -61,24 +77,25 @@ class MoodleController(WebAppServiceMixin, ServiceController):
|
||||||
sed -i "s#dbname\s*= '.*#dbname = '%(db_name)s';#" %(app_path)s/config.php
|
sed -i "s#dbname\s*= '.*#dbname = '%(db_name)s';#" %(app_path)s/config.php
|
||||||
sed -i "s#dbuser\s*= '.*#dbuser = '%(db_user)s';#" %(app_path)s/config.php
|
sed -i "s#dbuser\s*= '.*#dbuser = '%(db_user)s';#" %(app_path)s/config.php
|
||||||
sed -i "s#dbpass\s*= '.*#dbpass = '%(password)s';#" %(app_path)s/config.php
|
sed -i "s#dbpass\s*= '.*#dbpass = '%(password)s';#" %(app_path)s/config.php
|
||||||
sed -i "s#dataroot\s*= '.*#dataroot = '%(app_path)s/moodledata';#" %(app_path)s/config.php
|
sed -i "s#dataroot\s*= '.*#dataroot = '%(home)s/webapps/%(app_name)s/moodledata';#" %(app_path)s/config.php
|
||||||
sed -i "s#wwwroot\s*= '.*#wwwroot = '%(www_root)s';#" %(app_path)s/config.php
|
sed -i "s#wwwroot\s*= '.*#wwwroot = '%(www_root)s';#" %(app_path)s/config.php
|
||||||
|
|
||||||
fi
|
fi
|
||||||
rm %(app_path)s/.lock
|
rm %(app_path)s/.lock
|
||||||
chown -R %(user)s:%(group)s %(app_path)s
|
# chown -R %(user)s:%(group)s %(app_path)s
|
||||||
|
%(perms)s
|
||||||
|
|
||||||
# Run install moodle cli command on the background, because it takes so long...
|
# Run install moodle cli command on the background, because it takes so long...
|
||||||
stdout=$(mktemp)
|
stdout=$(mktemp)
|
||||||
stderr=$(mktemp)
|
stderr=$(mktemp)
|
||||||
nohup su - %(user)s --shell /bin/bash << 'EOF' > $stdout 2> $stderr &
|
# nohup su - %(user)s --shell /bin/bash << 'EOF' > $stdout 2> $stderr &
|
||||||
php %(app_path)s/admin/cli/install_database.php \\
|
nohup su - %(sftpuser)s --shell /bin/bash << 'EOF' > $stdout 2> $stderr &
|
||||||
|
php -d max_input_vars=5000 %(app_path)s/admin/cli/install_database.php \\
|
||||||
--fullname="%(site_name)s" \\
|
--fullname="%(site_name)s" \\
|
||||||
--shortname="%(site_name)s" \\
|
--shortname="%(site_name)s" \\
|
||||||
--adminpass="%(password)s" \\
|
--adminpass="%(password)s" \\
|
||||||
--adminemail="%(email)s" \\
|
--adminemail="%(email)s" \\
|
||||||
--non-interactive \\
|
--agree-license
|
||||||
--agree-license \\
|
|
||||||
--allow-unstable
|
|
||||||
EOF
|
EOF
|
||||||
pid=$!
|
pid=$!
|
||||||
sleep 2
|
sleep 2
|
||||||
|
@ -95,14 +112,15 @@ class MoodleController(WebAppServiceMixin, ServiceController):
|
||||||
context = super(MoodleController, self).get_context(webapp)
|
context = super(MoodleController, self).get_context(webapp)
|
||||||
contents = webapp.content_set.all()
|
contents = webapp.content_set.all()
|
||||||
context.update({
|
context.update({
|
||||||
'db_type': 'mysqli',
|
'db_type': 'mariadb',
|
||||||
'db_name': webapp.data['db_name'],
|
'db_name': webapp.data['db_name'],
|
||||||
'db_user': webapp.data['db_user'],
|
'db_user': webapp.data['db_user'],
|
||||||
'password': webapp.data['password'],
|
'password': webapp.data['password'],
|
||||||
'db_host': settings.WEBAPPS_DEFAULT_MYSQL_DATABASE_HOST,
|
'db_host': 'localhost' if webapp.target_server.name in NEW_SERVERS else settings.WEBAPPS_DEFAULT_MYSQL_DATABASE_HOST,
|
||||||
'email': webapp.account.email,
|
'email': webapp.account.email,
|
||||||
'site_name': "%s Courses" % webapp.account.get_full_name(),
|
'site_name': "%s Courses" % webapp.account.get_full_name(),
|
||||||
'cms_cache_dir': os.path.normpath(settings.WEBAPPS_CMS_CACHE_DIR),
|
'cms_cache_dir': os.path.normpath(settings.WEBAPPS_CMS_CACHE_DIR),
|
||||||
'www_root': contents[0].website.get_absolute_url() if contents else 'http://empty'
|
'www_root': contents[0].website.get_absolute_url() if contents else 'http://empty',
|
||||||
|
'sftpuser': webapp.sftpuser.username if webapp.target_server.name in NEW_SERVERS else None ,
|
||||||
})
|
})
|
||||||
return replace(context, '"', "'")
|
return replace(context, '"', "'")
|
||||||
|
|
|
@ -18,7 +18,7 @@ class WordPressURLController(ServiceController):
|
||||||
self.append(textwrap.dedent("""\
|
self.append(textwrap.dedent("""\
|
||||||
mysql %(db_name)s -e 'UPDATE wp_options
|
mysql %(db_name)s -e 'UPDATE wp_options
|
||||||
SET option_value="%(url)s"
|
SET option_value="%(url)s"
|
||||||
WHERE option_id IN (1, 2) AND option_value="http:";'
|
WHERE option_id IN (1, 2) AND ( option_value="http:" OR option_value="%(wp_path)s" );'
|
||||||
""") % context
|
""") % context
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ class WordPressURLController(ServiceController):
|
||||||
return {
|
return {
|
||||||
'url': content.get_absolute_url(),
|
'url': content.get_absolute_url(),
|
||||||
'db_name': content.webapp.data.get('db_name'),
|
'db_name': content.webapp.data.get('db_name'),
|
||||||
|
'wp_path': f"http://{content.webapp.get_path()}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue