1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/weblate_ynh.git synced 2024-10-01 13:35:04 +02:00

Merge pull request #55 from YunoHost-Apps/testing

Apply last example_ynh
This commit is contained in:
yalh76 2022-03-17 08:26:13 +01:00 committed by GitHub
commit 214e3472f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 356 additions and 383 deletions

View file

@ -17,7 +17,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in
Weblate is a libre web-based translation tool with tight version control integration. It provides two user interfaces, propagation of translations across components, quality checks and automatic linking to source files. Weblate is a libre web-based translation tool with tight version control integration. It provides two user interfaces, propagation of translations across components, quality checks and automatic linking to source files.
**Shipped version:** 4.11.2~ynh1 **Shipped version:** 4.11.2~ynh2
**Demo:** https://hosted.weblate.org/ **Demo:** https://hosted.weblate.org/

View file

@ -13,7 +13,7 @@ Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour
Weblate est un outil de traduction libre avec une intégration étroite du contrôle de version. Il fournit deux interfaces utilisateur, la propagation des traductions entre les composants, les contrôles de qualité et la liaison automatique aux fichiers source. Weblate est un outil de traduction libre avec une intégration étroite du contrôle de version. Il fournit deux interfaces utilisateur, la propagation des traductions entre les composants, les contrôles de qualité et la liaison automatique aux fichiers source.
**Version incluse :** 4.11.2~ynh1 **Version incluse :** 4.11.2~ynh2
**Démo :** https://hosted.weblate.org/ **Démo :** https://hosted.weblate.org/

View file

@ -6,7 +6,7 @@
"en": "Translation platform using Git and Python", "en": "Translation platform using Git and Python",
"fr": "Plateforme de traduction utilisant Git et Python" "fr": "Plateforme de traduction utilisant Git et Python"
}, },
"version": "4.11.2~ynh1", "version": "4.11.2~ynh2",
"url": "https://weblate.org", "url": "https://weblate.org",
"upstream": { "upstream": {
"license": "AGPL-3.0", "license": "AGPL-3.0",
@ -26,7 +26,7 @@
"email": "jean-baptiste@holcroft.fr" "email": "jean-baptiste@holcroft.fr"
}], }],
"requirements": { "requirements": {
"yunohost": ">= 4.2.0" "yunohost": ">= 4.3.0"
}, },
"multi_instance": true, "multi_instance": true,
"services": [ "services": [
@ -47,10 +47,6 @@
{ {
"name": "is_public", "name": "is_public",
"type": "boolean", "type": "boolean",
"help": {
"en": "Any YunoHost user and anonymous people from the web will be able to access the application",
"fr": "Tout utilisateur YunoHost et les personnes anonymes pourront accéder à l'application"
},
"default": false "default": false
}, },
{ {

View file

@ -6,9 +6,18 @@
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
#================================================= #=================================================
@ -18,9 +27,9 @@ ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app="$app" --key=final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get --app="$app" --key=domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get --app="$app" --key=db_name) db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#================================================= #=================================================
# DECLARE DATA AND CONF FILES TO BACKUP # DECLARE DATA AND CONF FILES TO BACKUP
@ -39,12 +48,6 @@ ynh_backup --src_path="$final_path"
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP THE PostgreSQL DATABASE
#=================================================
ynh_psql_dump_db --database="$db_name" > db.sql
#================================================= #=================================================
# SPECIFIC BACKUP # SPECIFIC BACKUP
#================================================= #=================================================
@ -53,12 +56,6 @@ ynh_psql_dump_db --database="$db_name" > db.sql
ynh_backup --src_path="/etc/logrotate.d/$app" ynh_backup --src_path="/etc/logrotate.d/$app"
#=================================================
# BACKUP THE UWSGI files
#=================================================
ynh_backup --src_path="/etc/uwsgi/apps-available/$app.ini"
#================================================= #=================================================
# BACKUP SYSTEMD # BACKUP SYSTEMD
#================================================= #=================================================
@ -66,6 +63,19 @@ ynh_backup --src_path="/etc/uwsgi/apps-available/$app.ini"
ynh_backup --src_path="/etc/systemd/system/$app.service" ynh_backup --src_path="/etc/systemd/system/$app.service"
ynh_backup --src_path="/etc/systemd/system/$app-celery.service" ynh_backup --src_path="/etc/systemd/system/$app-celery.service"
#=================================================
# BACKUP VARIOUS FILES
#=================================================
ynh_backup --src_path="/etc/uwsgi/apps-available/$app.ini"
#=================================================
# BACKUP THE POSTGRESQL DATABASE
#=================================================
ynh_print_info --message="Backing up the PostgreSQL database..."
ynh_psql_dump_db --database="$db_name" > db.sql
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================

View file

@ -26,21 +26,23 @@ app=$YNH_APP_INSTANCE_NAME
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1 ynh_script_progression --message="Loading installation settings..." --weight=1
final_path=$(ynh_app_setting_get --app="$app" --key=final_path) # Needed for helper "ynh_add_nginx_config"
is_public=$(ynh_app_setting_get --app="$app" --key=is_public) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#================================================= #=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP # BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP
#================================================= #=================================================
ynh_script_progression --message="Backing up the app before changing its url (may take a while)..." --weight=40 ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..."
# 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 () {
ynh_clean_check_starting
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
# 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
@ -69,11 +71,9 @@ fi
#================================================= #=================================================
ynh_script_progression --message="Stopping systemd services..." --weight=1 ynh_script_progression --message="Stopping systemd services..." --weight=1
ynh_systemd_action --service_name="$app" --action="stop" ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/weblate.log" --line_match="goodbye to uWSGI"
ynh_systemd_action --service_name="$app-celery" --action="stop" ynh_systemd_action --service_name="$app-celery" --action="stop" --log_path="systemd" --line_match="Stopped"
#=================================================
# STANDARD MODIFICATIONS
#================================================= #=================================================
# MODIFY URL IN NGINX CONF # MODIFY URL IN NGINX CONF
#================================================= #=================================================
@ -81,19 +81,19 @@ ynh_script_progression --message="Updating NGINX web server configuration..." --
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
# Change the path in the nginx config file # Change the path in the NGINX config file
if [ $change_path -eq 1 ] if [ $change_path -eq 1 ]
then then
# Make a backup of the original nginx config file if modified # Make a backup of the original NGINX config file if modified
ynh_backup_if_checksum_is_different --file="$nginx_conf_path" ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
# Set global variables for nginx helper # Set global variables for NGINX helper
domain="$old_domain" domain="$old_domain"
path_url="$new_path" path_url="$new_path"
# Create a dedicated nginx config # Create a dedicated NGINX config
ynh_add_nginx_config ynh_add_nginx_config
fi fi
# Change the domain for nginx # Change the domain for NGINX
if [ $change_domain -eq 1 ] if [ $change_domain -eq 1 ]
then then
# Delete file checksum for the old conf file location # Delete file checksum for the old conf file location
@ -152,10 +152,10 @@ ynh_store_file_checksum --file="$finaluwsgiini"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting systemd services..." --weight=5 ynh_script_progression --message="Starting a systemd service..." --weight=5
ynh_systemd_action --service_name="$app" --action="start" ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/weblate.log" --line_match="spawned uWSGI"
ynh_systemd_action --service_name="$app-celery" --action="start" ynh_systemd_action --service_name="$app-celery" --action="start" --log_path="/var/log/$app/weblate-celery-celery.log" --line_match="mingle: all alone"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX

View file

@ -13,6 +13,9 @@ source /usr/share/yunohost/helpers
# MANAGE SCRIPT FAILURE # MANAGE SCRIPT FAILURE
#================================================= #=================================================
ynh_clean_setup () {
ynh_clean_check_starting
}
# 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
@ -23,13 +26,16 @@ ynh_abort_if_errors
domain=$YNH_APP_ARG_DOMAIN domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH path_url=$YNH_APP_ARG_PATH
admin=$YNH_APP_ARG_ADMIN admin=$YNH_APP_ARG_ADMIN
password=$YNH_APP_ARG_PASSWORD
is_public=$YNH_APP_ARG_IS_PUBLIC is_public=$YNH_APP_ARG_IS_PUBLIC
password=$YNH_APP_ARG_PASSWORD
github_account=$YNH_APP_ARG_GITHUB_ACCOUNT github_account=$YNH_APP_ARG_GITHUB_ACCOUNT
github_token=$YNH_APP_ARG_GITHUB_TOKEN github_token=$YNH_APP_ARG_GITHUB_TOKEN
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
admin_mail=$(ynh_user_get_info --username="$admin" --key=mail)
key=$(ynh_string_random --length=50)
#================================================= #=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#================================================= #=================================================
@ -41,19 +47,16 @@ test ! -e "$final_path" || ynh_die --message="This path already contains a folde
# Register (book) web path # Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
mkdir -p "$final_path"
#================================================= #=================================================
# STORE SETTINGS FROM MANIFEST # STORE SETTINGS FROM MANIFEST
#================================================= #=================================================
ynh_script_progression --message="Storing installation settings..." --weight=1 ynh_script_progression --message="Storing installation settings..." --weight=1
ynh_app_setting_set --app="$app" --key=domain --value="$domain" ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app="$app" --key=path --value="$path_url" ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set --app="$app" --key=admin --value="$admin" ynh_app_setting_set --app=$app --key=admin --value=$admin
ynh_app_setting_set --app="$app" --key=final_path --value="$final_path" ynh_app_setting_set --app=$app --key=github_account --value=$github_account
ynh_app_setting_set --app="$app" --key=github_account --value="$github_account" ynh_app_setting_set --app=$app --key=github_token --value=$github_token
ynh_app_setting_set --app="$app" --key=github_token --value="$github_token"
#================================================= #=================================================
# STANDARD MODIFICATIONS # STANDARD MODIFICATIONS
@ -62,38 +65,54 @@ ynh_app_setting_set --app="$app" --key=github_token --value="$github_token"
#================================================= #=================================================
ynh_script_progression --message="Installing dependencies..." --weight=40 ynh_script_progression --message="Installing dependencies..." --weight=40
ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies" ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
#=================================================
# CREATE A PostgreSQL DATABASE
#=================================================
ynh_script_progression --message="Creating a PostgreSQL database..." --weight=2
db_name=$(ynh_sanitize_dbid --db_name="$app")
db_user=$db_name
ynh_app_setting_set --app="$app" --key=db_name --value="$db_name"
ynh_psql_test_if_first_run
# Initialize database and store postgres password for upgrade
ynh_psql_setup_db --db_user="$db_user" --db_name="$db_name"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
# Create a dedicated nginx config
ynh_add_nginx_config
#================================================= #=================================================
# CREATE DEDICATED USER # CREATE DEDICATED USER
#================================================= #=================================================
ynh_script_progression --message="Configuring system user..." --weight=1 ynh_script_progression --message="Configuring system user..." --weight=1
# Hub needs a home directory with a config file # Create a system user
ynh_system_user_create --username="$app" --home_dir="$final_path" --use_shell ynh_system_user_create --username=$app --home_dir="$final_path" --use_shell
#=================================================
# CREATE A POSTGRESQL DATABASE
#=================================================
ynh_script_progression --message="Creating a PostgreSQL database..." --weight=2
db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_psql_test_if_first_run
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..."
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
mkdir -p "$final_path"
mkdir -p "$final_path/avatar-cache"
mkdir -p "$final_path/data"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# SPECIFIC SETUP
#================================================= #=================================================
# CONFIGURE HUB # CONFIGURE HUB
#================================================= #=================================================
@ -106,17 +125,13 @@ cat <<EOF > "$final_path/.bashrc"
eval "$(hub alias -s /bin/bash)" eval "$(hub alias -s /bin/bash)"
EOF EOF
#=================================================
# SPECIFIC SETUP
#================================================= #=================================================
# PIP INSTALLATION # PIP INSTALLATION
#================================================= #=================================================
ynh_script_progression --message="Install weblate using PIP..." --weight=80 ynh_script_progression --message="Install weblate using PIP..." --weight=80
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name
virtualenv --python=python3 "${final_path}/venv" virtualenv --python=python3 "${final_path}/venv"
chown -R "$app": "$final_path" chown -R $app: "$final_path"
#run source in a 'sub shell' #run source in a 'sub shell'
( (
@ -130,7 +145,7 @@ chown -R "$app": "$final_path"
# Read the "Note" section in https://docs.weblate.org/en/weblate-4.11/admin/install/venv-debian.html#python-modules # Read the "Note" section in https://docs.weblate.org/en/weblate-4.11/admin/install/venv-debian.html#python-modules
sudo --user=$app $final_path/venv/bin/pip install --force-reinstall --no-binary :all: cffi sudo --user=$app $final_path/venv/bin/pip install --force-reinstall --no-binary :all: cffi
# Still needed with latest version of weblate? # Still needed with latest version of weblate?
sudo --user=$app $final_path/venv/bin/pip install Weblate=="$weblate_version" sudo --user=$app BORG_OPENSSL_PREFIX=/usr/lib/x86_64-linux-gnu/ $final_path/venv/bin/pip install Weblate=="$weblate_version"
sudo --user=$app $final_path/venv/bin/pip install psycopg2-binary ruamel.yaml aeidon phply sudo --user=$app $final_path/venv/bin/pip install psycopg2-binary ruamel.yaml aeidon phply
#pip install pytz python-bidi PyYaML Babel pyuca pylibravatar py3dns psycopg2-binary phply django-redis hiredis aeidon ruamel.yaml #pip install pytz python-bidi PyYaML Babel pyuca pylibravatar py3dns psycopg2-binary phply django-redis hiredis aeidon ruamel.yaml
# specific to YunoHost package: # specific to YunoHost package:
@ -138,26 +153,29 @@ chown -R "$app": "$final_path"
) )
#================================================= #=================================================
# SPECIFIC SETUP settings.py # ADD A CONFIGURATION
# https://docs.weblate.org/en/latest/admin/install.html#installation
# TODO: use --extra-search-dir=/path/to/dists
#================================================= #=================================================
ynh_script_progression --message="Create weblate configuration file..." --weight=1 ynh_script_progression --message="Adding a configuration file..." --weight=1
db_pwd=$(ynh_app_setting_get --app="$app" --key=psqlpwd)
admin_mail=$(ynh_user_get_info --username="$admin" --key=mail)
key=$(ynh_string_random --length=50)
redis_db=$(ynh_redis_get_free_db) redis_db=$(ynh_redis_get_free_db)
ynh_app_setting_set --app=$app --key=redis_db --value="$redis_db"
path_url="${path_url%/}" path_url="${path_url%/}"
settings="$final_path/venv/lib/$weblate_pypath/site-packages/weblate/settings.py" settings="$final_path/venv/lib/$weblate_pypath/site-packages/weblate/settings.py"
ynh_add_config --template="../conf/settings.py" --destination="$settings" ynh_add_config --template="../conf/settings.py" --destination="$settings"
ynh_add_config --template="../conf/celery-weblate" --destination="$final_path/celery-weblate"
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db" ynh_add_config --template="../conf/uwsgi.ini" --destination="/etc/uwsgi/apps-available/$app.ini"
touch "$final_path/local_settings.py" touch "$final_path/local_settings.py"
ln -sf "$final_path/local_settings.py" "$final_path/venv/lib/$weblate_pypath/site-packages/weblate/local_settings.py" ln -sf "$final_path/local_settings.py" "$final_path/venv/lib/$weblate_pypath/site-packages/weblate/local_settings.py"
# Set permissions to app files
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app: "$final_path"
chown "$app:www-data" "$final_path"
chown -R "$app:www-data" "$final_path/data"
#================================================= #=================================================
# SPECIFIC SETUP Filling up the database # SPECIFIC SETUP Filling up the database
# https://docs.weblate.org/en/latest/admin/install.html#filling-up-the-database # https://docs.weblate.org/en/latest/admin/install.html#filling-up-the-database
@ -172,68 +190,29 @@ ynh_script_progression --message="Filling up the database..." --weight=10
cd "${final_path}" cd "${final_path}"
# the user needs to be weblate for postgresql # the user needs to be weblate for postgresql
sudo --user=$app $final_path/venv/bin/weblate migrate --noinput ynh_exec_warn_less sudo --user=$app $final_path/venv/bin/weblate migrate --noinput
# generate static files # generate static files
sudo --user=$app $final_path/venv/bin/weblate collectstatic --noinput ynh_exec_warn_less sudo --user=$app $final_path/venv/bin/weblate collectstatic --noinput
sudo --user=$app $final_path/venv/bin/weblate createadmin --no-color \ ynh_exec_warn_less sudo --user=$app $final_path/venv/bin/weblate createadmin --no-color \
--password "$password" \ --password "$password" \
--username "$admin" \ --username "$admin" \
--email "$admin_mail" --email "$admin_mail"
# Check the configuration # Check the configuration
# This may fail in some cases with errors, etc., but the app works and the user can fix issues later. # This may fail in some cases with errors, etc., but the app works and the user can fix issues later.
sudo --user=$app $final_path/venv/bin/weblate check --deploy || true ynh_exec_warn_less sudo --user=$app $final_path/venv/bin/weblate check --deploy || true
) )
#=================================================
# STORE THE CHECKSUM OF THE CONFIG FILE
#=================================================
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="$settings"
#=================================================
# SPECIFIC SETUP UWSGI
#=================================================
ynh_script_progression --message="Configure uwsgi..." --weight=1
finaluwsgiini="/etc/uwsgi/apps-available/$app.ini"
ynh_add_config --template="../conf/uwsgi.ini" --destination="$finaluwsgiini"
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
#================================================= #=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=2 ynh_script_progression --message="Configuring a systemd service..." --weight=3
ynh_add_systemd_config --service="$app" --template="weblate.service"
#=================================================
# ACTIVATE CELERY
#=================================================
ynh_script_progression --message="Configure celery..." --weight=1
celeryconf="$final_path/celery-weblate"
ynh_add_config --template="../conf/celery-weblate" --destination="$celeryconf"
ynh_add_systemd_config --service=$app --template="weblate.service"
ynh_add_systemd_config --service="$app-celery" --template="celery-weblate.service" ynh_add_systemd_config --service="$app-celery" --template="celery-weblate.service"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions to app files
mkdir -p "$final_path/avatar-cache"
chown -R "$app": "$final_path"
chown "$app:www-data" "$final_path"
chown -R "$app:www-data" "$final_path/data"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
#================================================= #=================================================
# SETUP LOGROTATE # SETUP LOGROTATE
#================================================= #=================================================
@ -247,8 +226,16 @@ ynh_use_logrotate --non-append
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=3 ynh_script_progression --message="Integrating service in YunoHost..." --weight=3
yunohost service add "$app" --log "/var/log/$app/weblate.log" yunohost service add $app --log="/var/log/$app/weblate.log"
yunohost service add "$app-celery" --log "/var/log/$app/weblate-celery-w1.log" yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=5
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/weblate.log" --line_match="spawned uWSGI"
ynh_systemd_action --service_name="$app-celery" --action="start" --log_path="/var/log/$app/weblate-celery-celery.log" --line_match="mingle: all alone"
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
@ -256,19 +243,11 @@ yunohost service add "$app-celery" --log "/var/log/$app/weblate-celery-w1.log"
ynh_script_progression --message="Configuring permissions..." --weight=1 ynh_script_progression --message="Configuring permissions..." --weight=1
# Make app public if necessary # Make app public if necessary
if [ "$is_public" -eq 1 ] if [ $is_public -eq 1 ]
then then
ynh_permission_update --permission="main" --add="visitors" ynh_permission_update --permission="main" --add="visitors"
fi fi
#=================================================
# Start weblate
#=================================================
ynh_script_progression --message="Starting weblate's services..." --weight=5
ynh_systemd_action --service_name="$app" --action="start"
ynh_systemd_action --service_name="$app-celery" --action="start"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================

View file

@ -15,63 +15,57 @@ source /usr/share/yunohost/helpers
ynh_script_progression --message="Loading installation settings..." --weight=1 ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app="$app" --key=domain)
db_name=$(ynh_app_setting_get --app="$app" --key=db_name) domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name db_user=$db_name
final_path=$(ynh_app_setting_get --app="$app" --key=final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#================================================= #=================================================
# STANDARD REMOVE # STANDARD REMOVE
#================================================= #=================================================
# REMOVE SERVICE FROM ADMIN PANEL # REMOVE SERVICE INTEGRATION IN YUNOHOST
#================================================= #=================================================
# Remove a service from the admin panel, added by `yunohost service add` # Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
if yunohost service status "$app" >/dev/null 2>&1 if ynh_exec_warn_less yunohost service status $app >/dev/null
then then
ynh_script_progression --message="Removing $app service integration..." --weight=1 ynh_script_progression --message="Removing $app service integration..." --weight=1
yunohost service remove "$app" yunohost service remove $app
fi fi
# Remove a service from the admin panel, added by `yunohost service add` # Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
if yunohost service status "$app-celery" >/dev/null 2>&1 if ynh_exec_warn_less yunohost service status "$app-celery" >/dev/null
then then
ynh_script_progression --message="Removing $app-celery service integration..." --weight=1 ynh_script_progression --message="Removing $app-celery service integration..." --weight=1
yunohost service remove "$app-celery" yunohost service remove "$app-celery"
fi fi
#================================================= #=================================================
# STOP WEBLATE'S SERVICES # STOP AND REMOVE SERVICE
#================================================= #=================================================
ynh_script_progression --message="Stopping and removing systemd services..." --weight=5 ynh_script_progression --message="Stopping and removing the systemd service..." --weight=5
ynh_remove_systemd_config --service="$app" # Remove the dedicated systemd config
ynh_remove_systemd_config --service=$app
ynh_remove_systemd_config --service="$app-celery" ynh_remove_systemd_config --service="$app-celery"
#================================================= #=================================================
# REMOVE THE PostgreSQL DATABASE # REMOVE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Removing logrotate configuration..." --weight=1
# Remove the app-specific logrotate config
ynh_remove_logrotate
#=================================================
# REMOVE THE POSTGRESQL DATABASE
#================================================= #=================================================
ynh_script_progression --message="Removing the PostgreSQL database..." --weight=1 ynh_script_progression --message="Removing the PostgreSQL database..." --weight=1
# Remove a database if it exists, along with the associated user # Remove a database if it exists, along with the associated user
ynh_psql_remove_db --db_user=$db_user --db_name=$db_name ynh_psql_remove_db --db_user=$db_user --db_name=$db_name
#=================================================
# REMOVE REDIS DB
#=================================================
ynh_redis_remove_db
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --weight=10
# Remove metapackage and its dependencies
finaluwsgiini="/etc/uwsgi/apps-available/$app.ini"
ynh_secure_remove --file="$finaluwsgiini"
ynh_exec_warn_less ynh_remove_app_dependencies
#================================================= #=================================================
# REMOVE APP MAIN DIR # REMOVE APP MAIN DIR
#================================================= #=================================================
@ -85,25 +79,30 @@ ynh_secure_remove --file="$final_path"
#================================================= #=================================================
ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1 ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1
# Remove the dedicated nginx config # Remove the dedicated NGINX config
ynh_remove_nginx_config ynh_remove_nginx_config
#================================================= #=================================================
# REMOVE LOGROTATE CONFIGURATION # REMOVE DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Removing logrotate configuration..." --weight=1 ynh_script_progression --message="Removing dependencies..." --weight=10
# Remove the app-specific logrotate config # Remove metapackage and its dependencies
ynh_remove_logrotate ynh_exec_warn_less ynh_remove_app_dependencies
#================================================= #=================================================
# SPECIFIC REMOVE # SPECIFIC REMOVE
#================================================= #=================================================
# REMOVE CELERY FILES # REMOVE VARIOUS FILES
#================================================= #=================================================
ynh_script_progression --message="Removing various files..."
ynh_secure_remove --file="/etc/uwsgi/apps-available/$app.ini"
ynh_secure_remove --file="/var/run/$app-celery" ynh_secure_remove --file="/var/run/$app-celery"
ynh_redis_remove_db
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================
@ -112,9 +111,10 @@ ynh_secure_remove --file="/var/run/$app-celery"
ynh_script_progression --message="Removing the dedicated system user..." --weight=1 ynh_script_progression --message="Removing the dedicated system user..." --weight=1
# Delete a system user # Delete a system user
ynh_system_user_delete --username="$app" ynh_system_user_delete --username=$app
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Removal of $app completed" --last ynh_script_progression --message="Removal of $app completed" --last

View file

@ -6,6 +6,7 @@
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -13,6 +14,10 @@ source /usr/share/yunohost/helpers
# MANAGE SCRIPT FAILURE # MANAGE SCRIPT FAILURE
#================================================= #=================================================
ynh_clean_setup () {
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
#================================================= #=================================================
@ -22,12 +27,11 @@ ynh_script_progression --message="Loading settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app="$app" --key=domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app="$app" --key=path) path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app="$app" --key=final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app="$app" --key=db_name) db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name db_user=$db_name
db_pwd=$(ynh_app_setting_get --app="$app" --key=psqlpwd)
#================================================= #=================================================
# CHECK IF THE APP CAN BE RESTORED # CHECK IF THE APP CAN BE RESTORED
@ -42,9 +46,18 @@ test ! -d $final_path \
#================================================= #=================================================
# RESTORE THE NGINX CONFIGURATION # RESTORE THE NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
# Create the dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path" --use_shell
#================================================= #=================================================
# RESTORE THE APP MAIN DIR # RESTORE THE APP MAIN DIR
#================================================= #=================================================
@ -55,26 +68,11 @@ ynh_restore_file --origin_path="$final_path"
touch "$final_path/local_settings.py" touch "$final_path/local_settings.py"
ln -sf "$final_path/local_settings.py" "$final_path/venv/lib/$weblate_pypath/site-packages/weblate/local_settings.py" ln -sf "$final_path/local_settings.py" "$final_path/venv/lib/$weblate_pypath/site-packages/weblate/local_settings.py"
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
# Create the dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path" --use_shell
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
mkdir -p "$final_path/avatar-cache"
chown -R "$app": "$final_path"
chown "$app:www-data" "$final_path"
chown -R "$app:www-data" "$final_path/data"
chmod 750 "$final_path" chmod 750 "$final_path"
chmod -R o-rwx "$final_path" chmod -R o-rwx "$final_path"
chown -R $app: "$final_path"
chown $app:www-data "$final_path"
chown -R $app:www-data "$final_path/data"
#================================================= #=================================================
# SPECIFIC RESTORATION # SPECIFIC RESTORATION
@ -83,6 +81,7 @@ chmod -R o-rwx "$final_path"
#================================================= #=================================================
ynh_script_progression --message="Reinstalling dependencies..." --weight=40 ynh_script_progression --message="Reinstalling dependencies..." --weight=40
# Define and install dependencies
ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies" ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies"
#================================================= #=================================================
@ -90,11 +89,19 @@ ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies"
#================================================= #=================================================
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=5 ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=5
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
ynh_psql_test_if_first_run ynh_psql_test_if_first_run
ynh_psql_setup_db --db_user="$db_user" --db_name="$db_name" --db_pwd="$db_pwd" ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name
ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
#=================================================
# RESTORE VARIOUS FILES
#=================================================
ynh_script_progression --message="Restoring various files..." --weight=1
ynh_restore_file --origin_path="/etc/uwsgi/apps-available/$app.ini"
#================================================= #=================================================
# RESTORE SYSTEMD # RESTORE SYSTEMD
#================================================= #=================================================
@ -106,45 +113,40 @@ ynh_restore_file --origin_path="/etc/systemd/system/$app-celery.service"
systemctl enable "$app-celery" --quiet systemctl enable "$app-celery" --quiet
#================================================= #=================================================
# RESTORE UWSGI # RESTORE THE LOGROTATE CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Restoring uwsgi configurations..." --weight=1 ynh_script_progression --message="Restoring the logrotate configuration..."
ynh_restore_file --origin_path="/etc/uwsgi/apps-available/$app.ini" mkdir -p "/var/log/$app"
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=3 ynh_script_progression --message="Integrating service in YunoHost..." --weight=3
yunohost service add "$app" --log "/var/log/$app/weblate.log" yunohost service add $app --log="/var/log/$app/weblate.log"
yunohost service add "$app-celery" --log "/var/log/$app/weblate-celery-w1.log" yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log"
#================================================= #=================================================
# RESTORE THE LOGROTATE CONFIGURATION # START SYSTEMD SERVICE
#=================================================
mkdir -p "/var/log/$app"
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#=================================================
# GENERIC FINALIZATION
#=================================================
# START WEBLATE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=5 ynh_script_progression --message="Starting a systemd service..." --weight=5
ynh_systemd_action --service_name="$app" --action="start" ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/weblate.log" --line_match="spawned uWSGI"
ynh_systemd_action --service_name="$app-celery" --action="start" ynh_systemd_action --service_name="$app-celery" --action="start" --log_path="/var/log/$app/weblate-celery-celery.log" --line_match="mingle: all alone"
#=================================================
# GENERIC FINALIZATION
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name="nginx" --action="reload" ynh_systemd_action --service_name=nginx --action=reload
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Restoration completed for $app" --last ynh_script_progression --message="Restoration completed for $app" --last

128
scripts/upgrade Executable file → Normal file
View file

@ -5,6 +5,7 @@
#================================================= #=================================================
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -15,18 +16,19 @@ ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
path_url=$(ynh_app_setting_get --app="$app" --key=path) domain=$(ynh_app_setting_get --app=$app --key=domain)
final_path=$(ynh_app_setting_get --app="$app" --key=final_path) path_url=$(ynh_app_setting_get --app=$app --key=path)
db_name=$(ynh_app_setting_get --app="$app" --key=db_name) admin=$(ynh_app_setting_get --app=$app --key=admin)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name db_user=$db_name
domain=$(ynh_app_setting_get --app="$app" --key=domain) db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
db_pwd=$(ynh_app_setting_get --app="$app" --key=psqlpwd)
admin=$(ynh_app_setting_get --app="$app" --key=admin)
admin_mail=$(ynh_user_get_info "$admin" mail) admin_mail=$(ynh_user_get_info "$admin" mail)
github_account=$(ynh_app_setting_get --app="$app" --key=github_account) github_account=$(ynh_app_setting_get --app=$app --key=github_account)
github_token=$(ynh_app_setting_get --app="$app" --key=github_token) github_token=$(ynh_app_setting_get --app=$app --key=github_token)
key=$(ynh_string_random 50) key=$(ynh_string_random 50)
redis_db=$(ynh_app_setting_get --app="$app" --key=redis_db) redis_db=$(ynh_app_setting_get --app=$app --key=redis_db)
#================================================= #=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
@ -36,15 +38,28 @@ ynh_script_progression --message="Backing up the app before upgrading (may take
# 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 ynh_clean_check_starting
# 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
#================================================= #=================================================
# Migrate legacy permissions to new system # STANDARD UPGRADE STEPS
#================================================= #=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping systemd services..." --weight=5
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/weblate.log" --line_match="goodbye to uWSGI"
ynh_systemd_action --service_name="$app-celery" --action="stop" --log_path="systemd" --line_match="Stopped"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
if ynh_legacy_permissions_exists if ynh_legacy_permissions_exists
then then
ynh_legacy_permissions_delete_all ynh_legacy_permissions_delete_all
@ -52,11 +67,6 @@ then
ynh_app_setting_delete --app=$app --key=is_public ynh_app_setting_delete --app=$app --key=is_public
fi fi
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
if [[ -d "$final_path/bin/" ]] if [[ -d "$final_path/bin/" ]]
then then
ynh_secure_remove --file="$final_path/bin/" ynh_secure_remove --file="$final_path/bin/"
@ -65,47 +75,37 @@ fi
# (<3.8) log cleanups # (<3.8) log cleanups
if [[ -e "/var/log/uwsgi/app/$app" ]] if [[ -e "/var/log/uwsgi/app/$app" ]]
then then
ynh_systemd_action --service_name="$app" --action="stop" ynh_systemd_action --service_name=$app --action="stop"
ynh_systemd_action --service_name="$app-celery" --action="stop" ynh_systemd_action --service_name="$app-celery" --action="stop"
ynh_secure_remove --file="/var/log/uwsgi/app/$app" ynh_secure_remove --file="/var/log/uwsgi/app/$app"
ynh_secure_remove --file="/var/log/$app-celery" ynh_secure_remove --file="/var/log/$app-celery"
fi fi
#================================================= #=================================================
# STANDARD UPGRADE STEPS # CREATE DEDICATED USER
#================================================= #=================================================
# STOP SYSTEMD SERVICE ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
#=================================================
ynh_script_progression --message="Stopping systemd services..." --weight=5
ynh_systemd_action --service_name="$app" --action="stop" # Create a dedicated user (if not existing)
ynh_systemd_action --service_name="$app-celery" --action="stop" ynh_system_user_create --username=$app --home_dir="$final_path" --use_shell
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=3 ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=3
# Create a dedicated nginx config # Create a dedicated NGINX config
ynh_add_nginx_config ynh_add_nginx_config
#================================================= #=================================================
# SPECIFIC UPGRADE # UPGRADE DEPENDENCIES
#=================================================
# Update dependencies
#================================================= #=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=5 ynh_script_progression --message="Upgrading dependencies..." --weight=5
ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies" ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies"
#================================================= #=================================================
# CREATE DEDICATED USER # SPECIFIC UPGRADE
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
# Create a system user
ynh_system_user_create --username="$app" --home_dir="$final_path" --use_shell
#================================================= #=================================================
# CONFIGURE HUB # CONFIGURE HUB
#================================================= #=================================================
@ -119,30 +119,20 @@ eval "$(hub alias -s /bin/bash)"
EOF EOF
#================================================= #=================================================
# SPECIFIC SETUP UWSGI # UPDATE A CONFIG FILE
#================================================= #=================================================
ynh_script_progression --message="Configure uwsgi..." --weight=2 ynh_script_progression --message="Updating a configuration file..." --weight=2
finaluwsgiini="/etc/uwsgi/apps-available/$app.ini" ynh_add_config --template="../conf/uwsgi.ini" --destination="/etc/uwsgi/apps-available/$app.ini"
ynh_add_config --template="../conf/uwsgi.ini" --destination="$finaluwsgiini" ynh_add_config --template="../conf/celery-weblate" --destination="$final_path/celery-weblate"
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
#================================================= #=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=3 ynh_script_progression --message="Configuring a systemd service..." --weight=3
ynh_add_systemd_config --service="$app" --template="weblate.service" ynh_add_systemd_config --service=$app --template="weblate.service"
#=================================================
# ACTIVATE CELERY
#=================================================
ynh_script_progression --message="Configure celery..." --weight=2
celeryconf="$final_path/celery-weblate"
ynh_add_config --template="../conf/celery-weblate" --destination="$celeryconf"
ynh_add_systemd_config --service="$app-celery" --template="celery-weblate.service" ynh_add_systemd_config --service="$app-celery" --template="celery-weblate.service"
#================================================= #=================================================
@ -157,8 +147,6 @@ upgrade() {
#================================================= #=================================================
ynh_script_progression --message="Install weblate using PIP..." --weight=15 ynh_script_progression --message="Install weblate using PIP..." --weight=15
ynh_systemd_action --service_name="$app-celery" --action="stop"
ynh_secure_remove --file="${final_path}/venv" ynh_secure_remove --file="${final_path}/venv"
virtualenv --python=python3 "${final_path}/venv" virtualenv --python=python3 "${final_path}/venv"
chown -R $app: "$final_path" chown -R $app: "$final_path"
@ -192,7 +180,7 @@ upgrade() {
ynh_add_config --template="../conf/settings.py" --destination="$settings" ynh_add_config --template="../conf/settings.py" --destination="$settings"
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db" ynh_app_setting_set --app=$app --key=redis_db --value="$redis_db"
# Recalculate and store the config file checksum into the app settings # Recalculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="$settings" ynh_store_file_checksum --file="$settings"
@ -226,6 +214,8 @@ upgrade() {
sudo --user=$app $final_path/venv/bin/weblate check --deploy || true sudo --user=$app $final_path/venv/bin/weblate check --deploy || true
fi fi
) )
ynh_systemd_action --service_name="$app-celery" --action="stop"
} }
file_version="${final_path}/venv/lib/$weblate_pypath/site-packages/weblate/__init__.py" file_version="${final_path}/venv/lib/$weblate_pypath/site-packages/weblate/__init__.py"
@ -250,6 +240,17 @@ fi
upgrade $weblate_version "../conf/settings.py" upgrade $weblate_version "../conf/settings.py"
# Set right permissions for curl installation
mkdir -p "$final_path/avatar-cache"
chown -R $app: "$final_path"
chown "$app:www-data" "$final_path"
chown -R "$app:www-data" "$final_path/data"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
#=================================================
# GENERIC FINALIZATION
#================================================= #=================================================
# SETUP LOGROTATE # SETUP LOGROTATE
#================================================= #=================================================
@ -263,31 +264,16 @@ ynh_use_logrotate --non-append
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=2 ynh_script_progression --message="Integrating service in YunoHost..." --weight=2
yunohost service add "$app" --log "/var/log/$app/weblate.log" yunohost service add $app --log="/var/log/$app/weblate.log"
yunohost service add "$app-celery" --log "/var/log/$app/weblate-celery-w1.log" yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log"
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set right permissions for curl installation
mkdir -p "$final_path/avatar-cache"
chown -R "$app": "$final_path"
chown "$app:www-data" "$final_path"
chown -R "$app:www-data" "$final_path/data"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
#================================================= #=================================================
# START SYSTEMD SERVICES # START SYSTEMD SERVICES
#================================================= #=================================================
ynh_script_progression --message="Starting systemd services..." --weight=5 ynh_script_progression --message="Starting systemd services..." --weight=5
ynh_systemd_action --service_name="$app" --action="start" ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/weblate.log" --line_match="spawned uWSGI"
ynh_systemd_action --service_name="$app-celery" --action="start" ynh_systemd_action --service_name="$app-celery" --action="start" --log_path="/var/log/$app/weblate-celery-celery.log" --line_match="mingle: all alone"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX