mirror of
https://github.com/YunoHost-Apps/weblate_ynh.git
synced 2024-10-01 13:35:04 +02:00
switch from mysql to pgsql
This commit is contained in:
parent
0a54b3e2b4
commit
c3b5cc6061
4 changed files with 64 additions and 85 deletions
|
@ -1,5 +0,0 @@
|
||||||
[mysqld]
|
|
||||||
sql-mode=STRICT_TRANS_TABLES
|
|
||||||
innodb_large_prefix=on
|
|
||||||
innodb_file_format=barracuda
|
|
||||||
innodb_file_per_table=on
|
|
|
@ -30,7 +30,7 @@ app=$YNH_APP_INSTANCE_NAME
|
||||||
final_path=$(ynh_app_setting_get $app final_path)
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
domain=$(ynh_app_setting_get $app domain)
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
db_name=$(ynh_app_setting_get $app db_name)
|
db_name=$(ynh_app_setting_get $app db_name)
|
||||||
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
|
db_pwd=$(ynh_app_setting_get $app pgsqlpwd)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STANDARD BACKUP STEPS
|
# STANDARD BACKUP STEPS
|
||||||
|
@ -47,14 +47,12 @@ ynh_backup "$final_path" "${backup_dir}$final_path"
|
||||||
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "${backup_dir}/etc/nginx/conf.d/$domain.d/$app.conf"
|
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "${backup_dir}/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP THE MYSQL DATABASE
|
# BACKUP THE PostgreSQL DATABASE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_mysql_dump_db "$db_name" > db.sql
|
ynh_psql_dump_db "$db_name" > db.sql
|
||||||
ynh_backup "db.sql" "${backup_dir}/db.sql"
|
ynh_backup "db.sql" "${backup_dir}/db.sql"
|
||||||
|
|
||||||
ynh_backup "/etc/mysql/conf.d/$app.cnf" "${backup_dir}/etc/mysql/conf.d/$app.cnf"
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC BACKUP
|
# SPECIFIC BACKUP
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
117
scripts/install
117
scripts/install
|
@ -42,26 +42,26 @@ app=$YNH_APP_INSTANCE_NAME
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Normalize the url path syntax
|
# Normalize the url path syntax
|
||||||
path_url=$(ynh_normalize_url_path $path_url)
|
path_url=$(ynh_normalize_url_path "$path_url")
|
||||||
|
|
||||||
# Check web path availability
|
# Check web path availability
|
||||||
ynh_webpath_available $domain $path_url
|
ynh_webpath_available "$domain" "$path_url"
|
||||||
# Register (book) web path
|
# Register (book) web path
|
||||||
ynh_webpath_register $app $domain $path_url
|
ynh_webpath_register "$app" "$domain" "$path_url"
|
||||||
|
|
||||||
final_path=/var/www/$app
|
final_path=/var/www/$app
|
||||||
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
||||||
|
|
||||||
mkdir -p $final_path
|
mkdir -p "$final_path"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STORE SETTINGS FROM MANIFEST
|
# STORE SETTINGS FROM MANIFEST
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_app_setting_set $app domain $domain
|
ynh_app_setting_set "$app" domain "$domain"
|
||||||
ynh_app_setting_set $app path $path_url
|
ynh_app_setting_set "$app" path "$path_url"
|
||||||
ynh_app_setting_set $app admin $admin
|
ynh_app_setting_set "$app" admin "$admin"
|
||||||
ynh_app_setting_set $app is_public $is_public
|
ynh_app_setting_set "$app" is_public "$is_public"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STANDARD MODIFICATIONS
|
# STANDARD MODIFICATIONS
|
||||||
|
@ -73,33 +73,22 @@ ynh_app_setting_set $app is_public $is_public
|
||||||
|
|
||||||
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 \
|
||||||
libmysqlclient-dev uwsgi
|
postgresql python-psycopg2 uwsgi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CREATE A MYSQL DATABASE
|
# CREATE A PostgreSQL DATABASE
|
||||||
#=================================================
|
#=================================================
|
||||||
# If your app uses a MySQL database, you can use these lines to bootstrap
|
|
||||||
# a database, an associated user and save the password in app settings
|
|
||||||
|
|
||||||
db_name=$(ynh_sanitize_dbid $app)
|
ynh_psql_test_if_first_run
|
||||||
ynh_app_setting_set $app db_name $db_name
|
|
||||||
ynh_mysql_setup_db $db_name $db_name
|
|
||||||
|
|
||||||
# https://docs.weblate.org/en/latest/admin/install.html#unicode-issues-in-mysql
|
db_name=$(ynh_sanitize_dbid "$app")
|
||||||
# http://mechanics.flite.com/blog/2014/07/29/using-innodb-large-prefix-to-avoid-error-1071/
|
db_user_pwd=$(ynh_string_random)
|
||||||
ynh_mysql_execute_as_root "ALTER DATABASE $db_name CHARACTER SET utf8mb4;"
|
# Initialize database and store postgres password for upgrade
|
||||||
|
ynh_psql_create_db "$db_name" "$app" "$db_user_pwd"
|
||||||
|
ynh_app_setting_set "$app" db_name "$db_name"
|
||||||
|
ynh_app_setting_set "$app" psqlpwd "$db_pwd"
|
||||||
|
|
||||||
cp ../conf/weblate.cnf /etc/mysql/conf.d/$app.cnf
|
systemctl reload postgres
|
||||||
searchString="!includedir /etc/mysql/conf.d/"
|
|
||||||
if grep -Fxq "$searchString" /etc/mysql/my.cnf
|
|
||||||
then
|
|
||||||
echo "MySQL alread includes conf.d files"
|
|
||||||
else
|
|
||||||
echo "MySQL do not includes conf.d files, edditing /etc/mysql/my.cnf"
|
|
||||||
echo "$searchString" >> /etc/mysql/my.cnf
|
|
||||||
fi
|
|
||||||
|
|
||||||
systemctl restart mysql
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# NGINX CONFIGURATION
|
# NGINX CONFIGURATION
|
||||||
|
@ -113,7 +102,7 @@ ynh_add_nginx_config
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Create a system user
|
# Create a system user
|
||||||
ynh_system_user_create $app
|
ynh_system_user_create "$app"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC SETUP
|
# SPECIFIC SETUP
|
||||||
|
@ -122,36 +111,36 @@ ynh_system_user_create $app
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Copy Files
|
# Copy Files
|
||||||
cp ../conf/uwsgi.ini $final_path/uwsgi.ini
|
cp ../conf/uwsgi.ini "$final_path/uwsgi.ini"
|
||||||
ynh_replace_string "__NAME__" "$app" $final_path/uwsgi.ini
|
ynh_replace_string "__NAME__" "$app" "$final_path/uwsgi.ini"
|
||||||
ynh_replace_string "__FINALPATH__" "$final_path" $final_path/uwsgi.ini
|
ynh_replace_string "__FINALPATH__" "$final_path" "$final_path/uwsgi.ini"
|
||||||
|
|
||||||
# Config service
|
# Config service
|
||||||
mkdir -p /etc/uwsgi/apps-enabled/
|
mkdir -p /etc/uwsgi/apps-enabled/
|
||||||
ln -s $final_path/uwsgi.ini /etc/uwsgi/apps-enabled/$app.uwsgi.ini
|
ln -s "$final_path/uwsgi.ini" "/etc/uwsgi/apps-enabled/$app.uwsgi.ini"
|
||||||
|
|
||||||
cp ../conf/uwsgi_service /etc/systemd/system/$app.uwsgi.service
|
cp ../conf/uwsgi_service "/etc/systemd/system/$app.uwsgi.service"
|
||||||
ynh_replace_string "__NAME__" "$app" /etc/systemd/system/$app.uwsgi.service
|
ynh_replace_string "__NAME__" "$app" "/etc/systemd/system/$app.uwsgi.service"
|
||||||
ynh_replace_string "__FINALPATH__" "$final_path" /etc/systemd/system/$app.uwsgi.service
|
ynh_replace_string "__FINALPATH__" "$final_path" "/etc/systemd/system/$app.uwsgi.service"
|
||||||
|
|
||||||
|
|
||||||
# Start service
|
# Start service
|
||||||
systemctl enable $app.uwsgi.service
|
systemctl enable "$app.uwsgi.service"
|
||||||
systemctl restart $app.uwsgi.service
|
systemctl restart "$app.uwsgi.service"
|
||||||
|
|
||||||
# Add weblate.uwsgi as a service
|
# Add weblate.uwsgi as a service
|
||||||
yunohost service add $app.uwsgi.service
|
yunohost service add "$app.uwsgi.service"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# PIP INSTALLATION
|
# PIP INSTALLATION
|
||||||
#=================================================
|
#=================================================
|
||||||
virtualenv ${final_path}/venv
|
virtualenv "${final_path}/venv"
|
||||||
#run source in a 'sub shell'
|
#run source in a 'sub shell'
|
||||||
(
|
(
|
||||||
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 mysqlclient
|
"${final_path}/venv/bin/pip" install pytz python-bidi PyYaML Babel pyuca pylibravatar pydns
|
||||||
)
|
)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -159,20 +148,20 @@ virtualenv ${final_path}/venv
|
||||||
# https://docs.weblate.org/en/latest/admin/install.html#installation
|
# https://docs.weblate.org/en/latest/admin/install.html#installation
|
||||||
# TODO: use --extra-search-dir=/path/to/dists
|
# TODO: use --extra-search-dir=/path/to/dists
|
||||||
#=================================================
|
#=================================================
|
||||||
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
|
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)
|
||||||
|
|
||||||
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"
|
||||||
|
|
||||||
ynh_replace_string "__NAME__" "$app" $final_path/venv/lib/python2.7/site-packages/weblate/settings.py
|
ynh_replace_string "__NAME__" "$app" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py"
|
||||||
ynh_replace_string "__DB_PWD__" "$db_pwd" $final_path/venv/lib/python2.7/site-packages/weblate/settings.py
|
ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py"
|
||||||
ynh_replace_string "__ADMIN__" "$admin" $final_path/venv/lib/python2.7/site-packages/weblate/settings.py
|
ynh_replace_string "__ADMIN__" "$admin" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py"
|
||||||
ynh_replace_string "__ADMINMAIL__" "$admin_mail" $final_path/venv/lib/python2.7/site-packages/weblate/settings.py
|
ynh_replace_string "__ADMINMAIL__" "$admin_mail" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py"
|
||||||
ynh_replace_string "__DOMAIN__" "$domain" $final_path/venv/lib/python2.7/site-packages/weblate/settings.py
|
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/venv/lib/python2.7/site-packages/weblate/settings.py"
|
||||||
ynh_replace_string "__KEY__" "$key" $final_path/venv/lib/python2.7/site-packages/weblate/settings.py
|
ynh_replace_string "__KEY__" "$key" "$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 "__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"
|
||||||
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -181,9 +170,9 @@ ynh_replace_string "__FINALPATH__" "$final_path" $final_path/venv/lib/python2.7/
|
||||||
#==========================================
|
#==========================================
|
||||||
(
|
(
|
||||||
set +eu
|
set +eu
|
||||||
source ${final_path}/venv/bin/activate
|
source "${final_path}/venv/bin/activate"
|
||||||
export DJANGO_SETTINGS_MODULE="weblate.settings"
|
export DJANGO_SETTINGS_MODULE="weblate.settings"
|
||||||
cd ${final_path}
|
cd "${final_path}"
|
||||||
weblate migrate --noinput
|
weblate migrate --noinput
|
||||||
# generate static files
|
# generate static files
|
||||||
weblate collectstatic --noinput
|
weblate collectstatic --noinput
|
||||||
|
@ -192,8 +181,8 @@ ynh_replace_string "__FINALPATH__" "$final_path" $final_path/venv/lib/python2.7/
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP CRON
|
# SETUP CRON
|
||||||
#=================================================
|
#=================================================
|
||||||
cp ../conf/cron_weblate /etc/cron.d/$app
|
cp ../conf/cron_weblate "/etc/cron.d/$app"
|
||||||
ynh_replace_string "__FINALPATH__" "$final_path/" /etc/cron.d/$app
|
ynh_replace_string "__FINALPATH__" "$final_path/" "/etc/cron.d/$app"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STORE THE CHECKSUM OF THE CONFIG FILE
|
# STORE THE CHECKSUM OF THE CONFIG FILE
|
||||||
|
@ -209,7 +198,7 @@ ynh_store_file_checksum "$final_path/venv/lib/python2.7/site-packages/weblate/se
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Set permissions to app files
|
# Set permissions to app files
|
||||||
chown -R root: $final_path
|
chown -R root: "$final_path"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP LOGROTATE
|
# SETUP LOGROTATE
|
||||||
|
@ -222,15 +211,15 @@ ynh_use_logrotate
|
||||||
# SETUP SSOWAT
|
# SETUP SSOWAT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
if [ $is_public -eq 0 ]
|
if [ "$is_public" -eq 0 ]
|
||||||
then # Remove the public access
|
then # Remove the public access
|
||||||
ynh_app_setting_delete $app skipped_uris
|
ynh_app_setting_delete "$app" skipped_uris
|
||||||
fi
|
fi
|
||||||
# Make app public if necessary
|
# Make app public if necessary
|
||||||
if [ $is_public -eq 1 ]
|
if [ "$is_public" -eq 1 ]
|
||||||
then
|
then
|
||||||
# unprotected_uris allows SSO credentials to be passed anyway.
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
||||||
ynh_app_setting_set $app unprotected_uris "/"
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -55,17 +55,6 @@ ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
|
|
||||||
ynh_restore_file "$final_path"
|
ynh_restore_file "$final_path"
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# RESTORE THE MYSQL DATABASE
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
ynh_restore_file "/etc/mysql/conf.d/$app.cnf"
|
|
||||||
systemctl restart mysql
|
|
||||||
|
|
||||||
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
|
|
||||||
ynh_mysql_setup_db $db_name $db_name $db_pwd
|
|
||||||
ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RECREATE THE DEDICATED USER
|
# RECREATE THE DEDICATED USER
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -73,6 +62,14 @@ ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
|
||||||
# Create the dedicated user (if not existing)
|
# Create the dedicated user (if not existing)
|
||||||
ynh_system_user_create $app
|
ynh_system_user_create $app
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESTORE THE PostgreSQL DATABASE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
db_pwd=$(ynh_app_setting_get $app pgsqlpwd)
|
||||||
|
ynh_psql_setup_db $db_name $db_name $db_pwd
|
||||||
|
ynh_psql_connect_as $db_name $db_pwd $db_name < ./db.sql
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE USER RIGHTS
|
# RESTORE USER RIGHTS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
Loading…
Reference in a new issue