From e7bcc4eb7bdff43f09582115a075963caea017b6 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Fri, 4 Mar 2022 08:23:50 +0100 Subject: [PATCH] Apply last example_ynh --- check_process | 2 +- conf/nginx.conf | 40 +++++----- manifest.json | 146 ++++++++++++++++++------------------ scripts/_common.sh | 9 ++- scripts/backup | 40 ++++++---- scripts/change_url | 34 ++++----- scripts/install | 181 ++++++++++++++++++++------------------------- scripts/remove | 72 +++++++++--------- scripts/restore | 86 ++++++++++----------- scripts/upgrade | 130 +++++++++++++++----------------- 10 files changed, 357 insertions(+), 383 deletions(-) diff --git a/check_process b/check_process index 130a260..f96a320 100644 --- a/check_process +++ b/check_process @@ -16,7 +16,7 @@ setup_public=1 upgrade=1 #4.6.1 - upgrade=1 from_commit=3f8363cdc588e609a775cb8b78b9d080f96405d9 + upgrade=1 from_commit=3f8363cdc588e609a775cb8b78b9d080f96405d9 backup_restore=1 multi_instance=1 port_already_use=0 diff --git a/conf/nginx.conf b/conf/nginx.conf index 83e71d4..e65307b 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,38 +1,38 @@ #sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; # https://github.com/WeblateOrg/weblate/blob/master/weblate/examples/weblate.nginx.conf location = __PATH__/favicon.ico { - # DATA_DIR/static/favicon.ico - alias __FINALPATH__/data/static/favicon.ico; - expires 30d; + # DATA_DIR/static/favicon.ico + alias __FINALPATH__/data/static/favicon.ico; + expires 30d; } location = __PATH__/robots.txt { - # DATA_DIR/static/robots.txt - alias __FINALPATH__/data/static/robots.txt; - expires 30d; + # DATA_DIR/static/robots.txt + alias __FINALPATH__/data/static/robots.txt; + expires 30d; } location __PATH__/static/ { - # DATA_DIR/static/ - alias __FINALPATH__/data/static/; - expires 30d; + # DATA_DIR/static/ + alias __FINALPATH__/data/static/; + expires 30d; } location __PATH__/media/ { - # DATA_DIR/media/ - alias __FINALPATH__/data/media/; - expires 30d; + # DATA_DIR/media/ + alias __FINALPATH__/data/media/; + expires 30d; } location __PATH__/ { - # Path to source - alias __FINALPATH__/ ; + # Path to source + alias __FINALPATH__/ ; - include uwsgi_params; - # Needed for long running operations in admin interface - uwsgi_read_timeout 3600; - uwsgi_pass unix:///var/run/__NAME__/socket; + include uwsgi_params; + # Needed for long running operations in admin interface + uwsgi_read_timeout 3600; + uwsgi_pass unix:///var/run/__NAME__/socket; - # Include SSOWAT user panel. - include conf.d/yunohost_panel.conf.inc; + # Include SSOWAT user panel. + include conf.d/yunohost_panel.conf.inc; } diff --git a/manifest.json b/manifest.json index 1578114..eca1516 100644 --- a/manifest.json +++ b/manifest.json @@ -1,14 +1,14 @@ { - "name": "Weblate", - "id": "weblate", - "packaging_format": 1, - "description": { - "en": "Translation platform using Git and Python", - "fr": "Plateforme de traduction utilisant Git et Python" - }, - "version": "4.11~ynh1", - "url": "https://weblate.org", - "upstream": { + "name": "Weblate", + "id": "weblate", + "packaging_format": 1, + "description": { + "en": "Translation platform using Git and Python", + "fr": "Plateforme de traduction utilisant Git et Python" + }, + "version": "4.11~ynh2", + "url": "https://weblate.org", + "upstream": { "license": "AGPL-3.0", "website": "https://weblate.org", "demo": "https://hosted.weblate.org/", @@ -16,69 +16,65 @@ "userdoc": "https://docs.weblate.org/", "code": "https://github.com/WeblateOrg/weblate" }, - "license": "AGPL-3.0", - "maintainer": { - "name": "YunoHost Contributors", - "email": "apps@yunohost.org" - }, - "previous_maintainers": [{ - "name": "Jean-Baptiste Holcroft", - "email": "jean-baptiste@holcroft.fr" - }], - "requirements": { - "yunohost": ">= 4.2.0" - }, - "multi_instance": true, - "services": [ - "nginx" - ], - "arguments": { - "install" : [ - { - "name": "domain", - "type": "domain" - }, - { - "name": "path", - "type": "path", - "example": "/weblate", - "default": "/weblate" - }, - { - "name": "is_public", - "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 - }, - { - "name": "admin", - "type": "user" - }, - { - "name": "password", - "type": "password" - }, - { - "name": "github_account", - "type": "string", - "ask": { - "en": "GitHub's username", - "fr": "Nom d'utilisateur de GitHub" - }, - "example": "Github account" - }, - { - "name": "github_token", - "type": "string", - "ask": { - "en": "GitHub's token (OAuth)", - "fr": "Jeton GitHub (OAuth)" - }, - "example": "A secret token" - } - ] - } + "license": "AGPL-3.0", + "maintainer": { + "name": "YunoHost Contributors", + "email": "apps@yunohost.org" + }, + "previous_maintainers": [{ + "name": "Jean-Baptiste Holcroft", + "email": "jean-baptiste@holcroft.fr" + }], + "requirements": { + "yunohost": ">= 4.3.0" + }, + "multi_instance": true, + "services": [ + "nginx" + ], + "arguments": { + "install": [ + { + "name": "domain", + "type": "domain" + }, + { + "name": "path", + "type": "path", + "example": "/weblate", + "default": "/weblate" + }, + { + "name": "is_public", + "type": "boolean", + "default": false + }, + { + "name": "admin", + "type": "user" + }, + { + "name": "password", + "type": "password" + }, + { + "name": "github_account", + "type": "string", + "ask": { + "en": "GitHub's username", + "fr": "Nom d'utilisateur de GitHub" + }, + "example": "Github account" + }, + { + "name": "github_token", + "type": "string", + "ask": { + "en": "GitHub's token (OAuth)", + "fr": "Jeton GitHub (OAuth)" + }, + "example": "A secret token" + } + ] + } } diff --git a/scripts/_common.sh b/scripts/_common.sh index dc0cc21..4ddc7c9 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -6,10 +6,11 @@ # dependencies used by the app pkg_dependencies="libxml2-dev libxslt-dev libfreetype6-dev libjpeg-dev libz-dev libyaml-dev \ - libcairo-dev gir1.2-pango-1.0 libgirepository1.0-dev libacl1-dev libssl-dev \ - build-essential python3-gdbm python3-enchant python3-dev python3-pip python3-virtualenv virtualenv git \ - uwsgi uwsgi-plugin-python3 redis-server postgresql postgresql-contrib \ - libpq-dev libglib2.0-dev mailutils python-celery-common hub" + libffi-dev libcairo-dev gir1.2-pango-1.0 libgirepository1.0-dev \ + libacl1-dev libacl1 libssl-dev libpq-dev libjpeg62-turbo-dev build-essential \ + python3-gdbm python3-dev python3-pip python3-virtualenv virtualenv git \ + uwsgi uwsgi-plugin-python3 redis-server postgresql postgresql-contrib \ + liblz4-dev libzstd-dev libxxhash-dev python3-enchant libglib2.0-dev mailutils python-celery-common hub pkg-config python3-pkgconfig" # Weblate's version for PIP and settings file weblate_version="4.11" diff --git a/scripts/backup b/scripts/backup index 5373c19..9e36f62 100755 --- a/scripts/backup +++ b/scripts/backup @@ -6,9 +6,18 @@ # 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 /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 #================================================= @@ -18,9 +27,9 @@ ynh_print_info --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -final_path=$(ynh_app_setting_get --app="$app" --key=final_path) -domain=$(ynh_app_setting_get --app="$app" --key=domain) -db_name=$(ynh_app_setting_get --app="$app" --key=db_name) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) #================================================= # 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" -#================================================= -# BACKUP THE PostgreSQL DATABASE -#================================================= - -ynh_psql_dump_db --database="$db_name" > db.sql - #================================================= # SPECIFIC BACKUP #================================================= @@ -53,12 +56,6 @@ ynh_psql_dump_db --database="$db_name" > db.sql ynh_backup --src_path="/etc/logrotate.d/$app" -#================================================= -# BACKUP THE UWSGI files -#================================================= - -ynh_backup --src_path="/etc/uwsgi/apps-available/$app.ini" - #================================================= # 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-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 #================================================= diff --git a/scripts/change_url b/scripts/change_url index 4da5110..7bbb34d 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -26,21 +26,23 @@ app=$YNH_APP_INSTANCE_NAME #================================================= ynh_script_progression --message="Loading installation settings..." --weight=1 -final_path=$(ynh_app_setting_get --app="$app" --key=final_path) -is_public=$(ynh_app_setting_get --app="$app" --key=is_public) +# Needed for helper "ynh_add_nginx_config" +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 ynh_backup_before_upgrade 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. 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 } # 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_systemd_action --service_name="$app" --action="stop" -ynh_systemd_action --service_name="$app-celery" --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" --log_path="systemd" --line_match="Stopped" -#================================================= -# STANDARD MODIFICATIONS #================================================= # 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 -# Change the path in the nginx config file +# Change the path in the NGINX config file if [ $change_path -eq 1 ] 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" - # Set global variables for nginx helper + # Set global variables for NGINX helper domain="$old_domain" path_url="$new_path" - # Create a dedicated nginx config + # Create a dedicated NGINX config ynh_add_nginx_config fi -# Change the domain for nginx +# Change the domain for NGINX if [ $change_domain -eq 1 ] then # Delete file checksum for the old conf file location @@ -152,10 +152,10 @@ ynh_store_file_checksum --file="$finaluwsgiini" #================================================= # 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-celery" --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" --log_path="/var/log/$app/weblate-celery-celery.log" --line_match="mingle: all alone" #================================================= # RELOAD NGINX diff --git a/scripts/install b/scripts/install index 5de2393..e3d85cc 100755 --- a/scripts/install +++ b/scripts/install @@ -13,6 +13,9 @@ source /usr/share/yunohost/helpers # 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 @@ -23,13 +26,16 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH admin=$YNH_APP_ARG_ADMIN -password=$YNH_APP_ARG_PASSWORD is_public=$YNH_APP_ARG_IS_PUBLIC +password=$YNH_APP_ARG_PASSWORD github_account=$YNH_APP_ARG_GITHUB_ACCOUNT github_token=$YNH_APP_ARG_GITHUB_TOKEN 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 #================================================= @@ -41,19 +47,16 @@ test ! -e "$final_path" || ynh_die --message="This path already contains a folde # Register (book) web path ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url -mkdir -p "$final_path" - #================================================= # STORE SETTINGS FROM MANIFEST #================================================= 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=path --value="$path_url" -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_token --value="$github_token" +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=admin --value=$admin +ynh_app_setting_set --app=$app --key=github_account --value=$github_account +ynh_app_setting_set --app=$app --key=github_token --value=$github_token #================================================= # 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_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 +ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE DEDICATED USER #================================================= ynh_script_progression --message="Configuring system user..." --weight=1 -# Hub needs a home directory with a config file -ynh_system_user_create --username="$app" --home_dir="$final_path" --use_shell +# Create a system user +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 #================================================= @@ -106,17 +125,13 @@ cat < "$final_path/.bashrc" eval "$(hub alias -s /bin/bash)" EOF -#================================================= -# SPECIFIC SETUP #================================================= # PIP INSTALLATION #================================================= 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" -chown -R "$app": "$final_path" +chown -R $app: "$final_path" #run source in a 'sub shell' ( @@ -129,7 +144,7 @@ chown -R "$app": "$final_path" # Tmp fix sudo --user=$app $final_path/venv/bin/pip install --upgrade cffi==1.14 # 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 #pip install pytz python-bidi PyYaML Babel pyuca pylibravatar py3dns psycopg2-binary phply django-redis hiredis aeidon ruamel.yaml # specific to YunoHost package: @@ -137,26 +152,29 @@ chown -R "$app": "$final_path" ) #================================================= -# SPECIFIC SETUP settings.py -# https://docs.weblate.org/en/latest/admin/install.html#installation -# TODO: use --extra-search-dir=/path/to/dists +# ADD A CONFIGURATION #================================================= -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) +ynh_app_setting_set --app=$app --key=redis_db --value="$redis_db" path_url="${path_url%/}" settings="$final_path/venv/lib/$weblate_pypath/site-packages/weblate/settings.py" ynh_add_config --template="../conf/settings.py" --destination="$settings" - -ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db" +ynh_add_config --template="../conf/celery-weblate" --destination="$final_path/celery-weblate" +ynh_add_config --template="../conf/uwsgi.ini" --destination="/etc/uwsgi/apps-available/$app.ini" 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" +# 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 # https://docs.weblate.org/en/latest/admin/install.html#filling-up-the-database @@ -184,55 +202,16 @@ ynh_script_progression --message="Filling up the database..." --weight=10 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 #================================================= -ynh_script_progression --message="Configuring a systemd service..." --weight=2 - -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_script_progression --message="Configuring a systemd service..." --weight=3 +ynh_add_systemd_config --service=$app --template="weblate.service" ynh_add_systemd_config --service="$app-celery" --template="celery-weblate.service" #================================================= # 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 #================================================= @@ -246,8 +225,16 @@ ynh_use_logrotate --non-append #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=3 -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 --log="/var/log/$app/weblate.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 @@ -255,19 +242,11 @@ yunohost service add "$app-celery" --log "/var/log/$app/weblate-celery-w1.log" ynh_script_progression --message="Configuring permissions..." --weight=1 # Make app public if necessary -if [ "$is_public" -eq 1 ] +if [ $is_public -eq 1 ] then ynh_permission_update --permission="main" --add="visitors" 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 #================================================= diff --git a/scripts/remove b/scripts/remove index 3db18e2..e831757 100755 --- a/scripts/remove +++ b/scripts/remove @@ -15,63 +15,57 @@ source /usr/share/yunohost/helpers ynh_script_progression --message="Loading installation settings..." --weight=1 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 -final_path=$(ynh_app_setting_get --app="$app" --key=final_path) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # STANDARD REMOVE #================================================= -# REMOVE SERVICE FROM ADMIN PANEL +# REMOVE SERVICE INTEGRATION IN YUNOHOST #================================================= -# Remove a service from the admin panel, added by `yunohost service add` -if yunohost service status "$app" >/dev/null 2>&1 +# Remove the service from the list of services known by YunoHost (added from `yunohost service add`) +if ynh_exec_warn_less yunohost service status $app >/dev/null then ynh_script_progression --message="Removing $app service integration..." --weight=1 - yunohost service remove "$app" + yunohost service remove $app fi -# Remove a service from the admin panel, added by `yunohost service add` -if yunohost service status "$app-celery" >/dev/null 2>&1 +# Remove the service from the list of services known by YunoHost (added from `yunohost service add`) +if ynh_exec_warn_less yunohost service status "$app-celery" >/dev/null then ynh_script_progression --message="Removing $app-celery service integration..." --weight=1 yunohost service remove "$app-celery" 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" #================================================= -# 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 # Remove a database if it exists, along with the associated user 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 #================================================= @@ -85,25 +79,30 @@ ynh_secure_remove --file="$final_path" #================================================= 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 #================================================= -# 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 -ynh_remove_logrotate +# Remove metapackage and its dependencies +ynh_exec_warn_less ynh_remove_app_dependencies #================================================= # 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_redis_remove_db + #================================================= # 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 # Delete a system user -ynh_system_user_delete --username="$app" +ynh_system_user_delete --username=$app #================================================= # END OF SCRIPT #================================================= + ynh_script_progression --message="Removal of $app completed" --last diff --git a/scripts/restore b/scripts/restore index 71b711a..cc91f76 100755 --- a/scripts/restore +++ b/scripts/restore @@ -6,6 +6,7 @@ # 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 /usr/share/yunohost/helpers @@ -13,6 +14,10 @@ source /usr/share/yunohost/helpers # 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 #================================================= @@ -22,12 +27,11 @@ ynh_script_progression --message="Loading settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get --app="$app" --key=domain) -path_url=$(ynh_app_setting_get --app="$app" --key=path) -final_path=$(ynh_app_setting_get --app="$app" --key=final_path) -db_name=$(ynh_app_setting_get --app="$app" --key=db_name) +domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path) +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_pwd=$(ynh_app_setting_get --app="$app" --key=psqlpwd) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -42,9 +46,18 @@ test ! -d $final_path \ #================================================= # 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" +#================================================= +# 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 #================================================= @@ -55,26 +68,11 @@ ynh_restore_file --origin_path="$final_path" 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" -#================================================= -# 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 -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 @@ -83,6 +81,7 @@ chmod -R o-rwx "$final_path" #================================================= ynh_script_progression --message="Reinstalling dependencies..." --weight=40 +# Define and install 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 +db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) 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_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 #================================================= @@ -106,45 +113,40 @@ ynh_restore_file --origin_path="/etc/systemd/system/$app-celery.service" 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 #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=3 -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 --log="/var/log/$app/weblate.log" +yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log" #================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= - -mkdir -p "/var/log/$app" -ynh_restore_file --origin_path="/etc/logrotate.d/$app" - -#================================================= -# GENERIC FINALIZATION -#================================================= -# START WEBLATE +# START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=5 -ynh_systemd_action --service_name="$app" --action="start" -ynh_systemd_action --service_name="$app-celery" --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" --log_path="/var/log/$app/weblate-celery-celery.log" --line_match="mingle: all alone" +#================================================= +# GENERIC FINALIZATION #================================================= # RELOAD NGINX #================================================= 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 #================================================= + ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade index 05b2f3b..80b6aad 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -5,6 +5,7 @@ #================================================= # IMPORT GENERIC HELPERS #================================================= + source _common.sh source /usr/share/yunohost/helpers @@ -15,18 +16,19 @@ ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME -path_url=$(ynh_app_setting_get --app="$app" --key=path) -final_path=$(ynh_app_setting_get --app="$app" --key=final_path) -db_name=$(ynh_app_setting_get --app="$app" --key=db_name) +domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path) +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 -domain=$(ynh_app_setting_get --app="$app" --key=domain) -db_pwd=$(ynh_app_setting_get --app="$app" --key=psqlpwd) -admin=$(ynh_app_setting_get --app="$app" --key=admin) +db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) + admin_mail=$(ynh_user_get_info "$admin" mail) -github_account=$(ynh_app_setting_get --app="$app" --key=github_account) -github_token=$(ynh_app_setting_get --app="$app" --key=github_token) +github_account=$(ynh_app_setting_get --app=$app --key=github_account) +github_token=$(ynh_app_setting_get --app=$app --key=github_token) 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 @@ -36,15 +38,28 @@ ynh_script_progression --message="Backing up the app before upgrading (may take # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { - # restore it if the upgrade fails + ynh_clean_check_starting + # Restore it if the upgrade fails ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script 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 then ynh_legacy_permissions_delete_all @@ -52,11 +67,6 @@ then ynh_app_setting_delete --app=$app --key=is_public fi -#================================================= -# ENSURE DOWNWARD COMPATIBILITY -#================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 - if [[ -d "$final_path/bin/" ]] then ynh_secure_remove --file="$final_path/bin/" @@ -65,47 +75,37 @@ fi # (<3.8) log cleanups if [[ -e "/var/log/uwsgi/app/$app" ]] 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_secure_remove --file="/var/log/uwsgi/app/$app" ynh_secure_remove --file="/var/log/$app-celery" fi #================================================= -# STANDARD UPGRADE STEPS +# CREATE DEDICATED USER #================================================= -# STOP SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Stopping systemd services..." --weight=5 +ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 -ynh_systemd_action --service_name="$app" --action="stop" -ynh_systemd_action --service_name="$app-celery" --action="stop" +# Create a dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir="$final_path" --use_shell #================================================= # NGINX CONFIGURATION #================================================= 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 #================================================= -# SPECIFIC UPGRADE -#================================================= -# Update dependencies +# UPGRADE DEPENDENCIES #================================================= ynh_script_progression --message="Upgrading dependencies..." --weight=5 ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies" #================================================= -# CREATE DEDICATED USER -#================================================= -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 - +# SPECIFIC UPGRADE #================================================= # CONFIGURE HUB #================================================= @@ -119,30 +119,20 @@ eval "$(hub alias -s /bin/bash)" 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 #================================================= 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=2 - -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" #================================================= @@ -157,10 +147,8 @@ upgrade() { #================================================= ynh_script_progression --message="Install weblate using PIP..." --weight=15 - ynh_systemd_action --service_name="$app-celery" --action="stop" - virtualenv --python=python3 "${final_path}/venv" - chown -R "$app": "$final_path" + chown -R $app: "$final_path" #run source in a 'sub shell' ( @@ -190,7 +178,7 @@ upgrade() { 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 ynh_store_file_checksum --file="$settings" @@ -224,6 +212,8 @@ upgrade() { sudo --user=$app $final_path/venv/bin/weblate check --deploy || true fi ) + + ynh_systemd_action --service_name="$app-celery" --action="stop" } file_version="${final_path}/venv/lib/$weblate_pypath/site-packages/weblate/__init__.py" @@ -248,6 +238,17 @@ fi 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 #================================================= @@ -261,31 +262,16 @@ ynh_use_logrotate --non-append #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=2 -yunohost service add "$app" --log "/var/log/$app/weblate.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" +yunohost service add $app --log="/var/log/$app/weblate.log" +yunohost service add "$app-celery" --log="/var/log/$app/weblate-celery-w1.log" #================================================= # START SYSTEMD SERVICES #================================================= ynh_script_progression --message="Starting systemd services..." --weight=5 -ynh_systemd_action --service_name="$app" --action="start" -ynh_systemd_action --service_name="$app-celery" --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" --log_path="/var/log/$app/weblate-celery-celery.log" --line_match="mingle: all alone" #================================================= # RELOAD NGINX