mirror of
https://github.com/YunoHost-Apps/weblate_ynh.git
synced 2024-10-01 13:35:04 +02:00
add cache, remove debug, improve restore, use su instead of sudo
This commit is contained in:
parent
872bdaff6c
commit
bf399e8193
5 changed files with 39 additions and 37 deletions
|
@ -27,7 +27,7 @@ from logging.handlers import SysLogHandler
|
||||||
# Django settings for Weblate project.
|
# Django settings for Weblate project.
|
||||||
#
|
#
|
||||||
|
|
||||||
DEBUG = True
|
DEBUG = False
|
||||||
|
|
||||||
ADMINS = (
|
ADMINS = (
|
||||||
('__ADMIN__', '__ADMINMAIL__'),
|
('__ADMIN__', '__ADMINMAIL__'),
|
||||||
|
@ -125,7 +125,7 @@ USE_L10N = True
|
||||||
USE_TZ = True
|
USE_TZ = True
|
||||||
|
|
||||||
# URL prefix to use, please see documentation for more details
|
# URL prefix to use, please see documentation for more details
|
||||||
URL_PREFIX = '__PATHURL__/'
|
URL_PREFIX = '__PATHURL__'
|
||||||
|
|
||||||
# Absolute filesystem path to the directory that will hold user-uploaded files.
|
# Absolute filesystem path to the directory that will hold user-uploaded files.
|
||||||
# Example: "/home/media/media.lawrence.com/media/"
|
# Example: "/home/media/media.lawrence.com/media/"
|
||||||
|
@ -638,20 +638,20 @@ DEFAULT_FROM_EMAIL = '__ADMINMAIL__'
|
||||||
ALLOWED_HOSTS = ['__DOMAIN__']
|
ALLOWED_HOSTS = ['__DOMAIN__']
|
||||||
|
|
||||||
# Example configuration to use memcached for caching
|
# Example configuration to use memcached for caching
|
||||||
# CACHES = {
|
CACHES = {
|
||||||
# 'default': {
|
'default': {
|
||||||
# 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
|
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
|
||||||
# 'LOCATION': '127.0.0.1:11211',
|
'LOCATION': '127.0.0.1:__MEMCPORT__',
|
||||||
# },
|
},
|
||||||
# 'avatar': {
|
'avatar': {
|
||||||
# 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
|
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
|
||||||
# 'LOCATION': os.path.join(BASE_DIR, 'avatar-cache'),
|
'LOCATION': os.path.join(BASE_DIR, 'avatar-cache'),
|
||||||
# 'TIMEOUT': 3600,
|
'TIMEOUT': 3600,
|
||||||
# 'OPTIONS': {
|
'OPTIONS': {
|
||||||
# 'MAX_ENTRIES': 1000,
|
'MAX_ENTRIES': 1000,
|
||||||
# },
|
},
|
||||||
# }
|
}
|
||||||
# }
|
}
|
||||||
|
|
||||||
# REST framework settings for API
|
# REST framework settings for API
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
|
|
|
@ -8,7 +8,7 @@ ynh_psql_test_if_first_run() {
|
||||||
pgsql=$(ynh_string_random)
|
pgsql=$(ynh_string_random)
|
||||||
echo "$pgsql" >> /etc/yunohost/psql
|
echo "$pgsql" >> /etc/yunohost/psql
|
||||||
systemctl start postgresql
|
systemctl start postgresql
|
||||||
sudo -u postgres psql -c"ALTER user postgres WITH PASSWORD '${pgsql}'"
|
su --command="psql -c\"ALTER user postgres WITH PASSWORD '${pgsql}'\"" postgres
|
||||||
# we can't use peer since YunoHost create users with nologin
|
# we can't use peer since YunoHost create users with nologin
|
||||||
sed -i '/local\s*all\s*all\s*peer/i \
|
sed -i '/local\s*all\s*all\s*peer/i \
|
||||||
local all all password' /etc/postgresql/9.4/main/pg_hba.conf
|
local all all password' /etc/postgresql/9.4/main/pg_hba.conf
|
||||||
|
@ -30,7 +30,7 @@ ynh_psql_connect_as() {
|
||||||
user="$1"
|
user="$1"
|
||||||
pwd="$2"
|
pwd="$2"
|
||||||
db="$3"
|
db="$3"
|
||||||
sudo -u postgres PGUSER="${user}" PGPASSWORD="${pwd}" psql "${db}"
|
su --command="PGUSER=\"${user}\" PGPASSWORD=\"${pwd}\" psql \"${db}\"" postgres
|
||||||
}
|
}
|
||||||
|
|
||||||
# # Execute a command as root user
|
# # Execute a command as root user
|
||||||
|
@ -40,7 +40,7 @@ ynh_psql_connect_as() {
|
||||||
# | arg: db - the database to connect to
|
# | arg: db - the database to connect to
|
||||||
ynh_psql_execute_as_root () {
|
ynh_psql_execute_as_root () {
|
||||||
sql="$1"
|
sql="$1"
|
||||||
sudo -u postgres psql <<< "$sql"
|
su --command="psql" postgres <<< "$sql"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Execute a command from a file as root user
|
# Execute a command from a file as root user
|
||||||
|
@ -85,7 +85,7 @@ ynh_psql_create_db() {
|
||||||
user="$2"
|
user="$2"
|
||||||
pwd="$3"
|
pwd="$3"
|
||||||
ynh_psql_create_user "$user" "$pwd"
|
ynh_psql_create_user "$user" "$pwd"
|
||||||
sudo -u postgres createdb --owner="${user}" "${db}"
|
su --command="createdb --owner=\"${user}\" \"${db}\"" postgres
|
||||||
}
|
}
|
||||||
|
|
||||||
# Drop a database
|
# Drop a database
|
||||||
|
@ -96,7 +96,7 @@ ynh_psql_create_db() {
|
||||||
ynh_psql_remove_db() {
|
ynh_psql_remove_db() {
|
||||||
db="$1"
|
db="$1"
|
||||||
user="$2"
|
user="$2"
|
||||||
sudo -u postgres dropdb "${db}"
|
su --command="dropdb \"${db}\"" postgres
|
||||||
ynh_psql_drop_user "${user}"
|
ynh_psql_drop_user "${user}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ ynh_psql_remove_db() {
|
||||||
# | ret: the psqldump output
|
# | ret: the psqldump output
|
||||||
ynh_psql_dump_db() {
|
ynh_psql_dump_db() {
|
||||||
db="$1"
|
db="$1"
|
||||||
sudo -u postgres pg_dump "${db}"
|
su --command="pg_dump \"${db}\"" postgres
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ ynh_psql_dump_db() {
|
||||||
ynh_psql_create_user() {
|
ynh_psql_create_user() {
|
||||||
user="$1"
|
user="$1"
|
||||||
pwd="$2"
|
pwd="$2"
|
||||||
sudo -u postgres psql -c"CREATE USER ${user} WITH PASSWORD '${pwd}'"
|
su --command="psql -c\"CREATE USER ${user} WITH PASSWORD '${pwd}'\"" postgres
|
||||||
}
|
}
|
||||||
|
|
||||||
# Drop a user
|
# Drop a user
|
||||||
|
@ -129,5 +129,5 @@ ynh_psql_create_user() {
|
||||||
# | arg: user - the user name to drop
|
# | arg: user - the user name to drop
|
||||||
ynh_psql_drop_user() {
|
ynh_psql_drop_user() {
|
||||||
user="$1"
|
user="$1"
|
||||||
sudo -u postgres dropuser "${user}"
|
su --command="dropuser \"${user}\"" postgres
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,13 +52,13 @@ fi
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Backup the current version of the app
|
# Backup the current version of the app
|
||||||
ynh_backup_before_upgrade
|
# ynh_backup_before_upgrade
|
||||||
ynh_clean_setup () {
|
# ynh_clean_setup () {
|
||||||
# restore it if the upgrade fails
|
# # restore it if the upgrade fails
|
||||||
ynh_restore_upgradebackup
|
# ynh_restore_upgradebackup
|
||||||
}
|
# }
|
||||||
# Exit if an error occurs during the execution of the script
|
# # Exit if an error occurs during the execution of the script
|
||||||
ynh_abort_if_errors
|
# ynh_abort_if_errors
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STANDARD MODIFICATIONS
|
# STANDARD MODIFICATIONS
|
||||||
|
|
|
@ -74,7 +74,7 @@ ynh_app_setting_set "$app" final_path "$final_path"
|
||||||
|
|
||||||
ynh_install_app_dependencies libxml2-dev libxslt-dev libfreetype6-dev \
|
ynh_install_app_dependencies libxml2-dev libxslt-dev libfreetype6-dev \
|
||||||
libjpeg-dev libz-dev libyaml-dev python-dev python-pip python-virtualenv \
|
libjpeg-dev libz-dev libyaml-dev python-dev python-pip python-virtualenv \
|
||||||
postgresql libpq-dev uwsgi uwsgi-plugin-python
|
postgresql libpq-dev uwsgi uwsgi-plugin-python memcached
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CREATE A PostgreSQL DATABASE
|
# CREATE A PostgreSQL DATABASE
|
||||||
|
@ -136,7 +136,7 @@ virtualenv "${final_path}/venv"
|
||||||
set +eu
|
set +eu
|
||||||
source "${final_path}/venv/bin/activate"
|
source "${final_path}/venv/bin/activate"
|
||||||
"${final_path}/venv/bin/pip" install Weblate==2.16
|
"${final_path}/venv/bin/pip" install Weblate==2.16
|
||||||
"${final_path}/venv/bin/pip" install pytz python-bidi PyYaML Babel pyuca pylibravatar pydns psycopg2 django_sendmail_backend
|
"${final_path}/venv/bin/pip" install pytz python-bidi PyYaML Babel pyuca pylibravatar pydns psycopg2 django_sendmail_backend python-memcached
|
||||||
)
|
)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -147,6 +147,7 @@ virtualenv "${final_path}/venv"
|
||||||
db_pwd=$(ynh_app_setting_get "$app" psqlpwd)
|
db_pwd=$(ynh_app_setting_get "$app" psqlpwd)
|
||||||
admin_mail=$(ynh_user_get_info "$admin" mail)
|
admin_mail=$(ynh_user_get_info "$admin" mail)
|
||||||
key=$(ynh_string_random)
|
key=$(ynh_string_random)
|
||||||
|
memc_port=$(ynh_find_port 8080)
|
||||||
|
|
||||||
cp ../conf/settings.py "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py"
|
cp ../conf/settings.py "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py"
|
||||||
|
|
||||||
|
@ -159,6 +160,7 @@ ynh_replace_string "__KEY__" "$key" "$final_path/venv/lib/python2.7
|
||||||
ynh_replace_string "__PATHURL__" "$path_url" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py"
|
ynh_replace_string "__PATHURL__" "$path_url" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py"
|
||||||
ynh_replace_string "__FINALPATH__" "$final_path" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py"
|
ynh_replace_string "__FINALPATH__" "$final_path" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py"
|
||||||
ynh_replace_string "__SMTPPWD__" "$smtp_pwd" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py"
|
ynh_replace_string "__SMTPPWD__" "$smtp_pwd" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py"
|
||||||
|
ynh_replace_string "__MEMCPORT__" "$memc_port" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC SETUP Filling up the database
|
# SPECIFIC SETUP Filling up the database
|
||||||
|
|
|
@ -38,10 +38,10 @@ smtp_pwd=$(ynh_app_setting_get $app smtppwd)
|
||||||
# CHECK IF THE APP CAN BE RESTORED
|
# CHECK IF THE APP CAN BE RESTORED
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
yunohost app checkurl "${domain}${path_url}" -a "$app" \
|
# Check web path availability
|
||||||
|| ynh_die "Path not available: ${domain}${path_url}"
|
ynh_webpath_available "$domain" "$path_url"
|
||||||
test ! -d $final_path \
|
|
||||||
|| ynh_die "There is already a directory: $final_path "
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STANDARD RESTORATION STEPS
|
# STANDARD RESTORATION STEPS
|
||||||
|
|
Loading…
Reference in a new issue