From f7080ee0c4c3de4cda4edc02a7822296dd86cbc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Wed, 28 Feb 2024 12:03:57 +0100 Subject: [PATCH] initial manifestv2 --- check_process | 36 ------ conf/app.src | 7 -- conf/nginx.conf | 2 +- conf/systemd.service | 4 +- doc/ADMIN.md | 3 + doc/{DISCLAIMER.md => PRE_INSTALL.md} | 4 - manifest.json | 42 ------- manifest.toml | 69 +++++++++++ scripts/_common.sh | 25 ++-- scripts/backup | 34 +----- scripts/change_url | 101 +-------------- scripts/install | 153 ++++------------------- scripts/remove | 63 +--------- scripts/restore | 97 +++------------ scripts/upgrade | 169 +++++++------------------- tests.toml | 7 ++ 16 files changed, 194 insertions(+), 622 deletions(-) delete mode 100644 check_process delete mode 100644 conf/app.src create mode 100644 doc/ADMIN.md rename doc/{DISCLAIMER.md => PRE_INSTALL.md} (52%) delete mode 100644 manifest.json create mode 100644 manifest.toml create mode 100644 tests.toml diff --git a/check_process b/check_process deleted file mode 100644 index 80f72b5..0000000 --- a/check_process +++ /dev/null @@ -1,36 +0,0 @@ -;; Test complet - ; Manifest - domain="domain.tld" - is_public=1 - ; Checks - pkg_linter=1 - setup_sub_dir=1 - setup_root=1 - setup_nourl=0 - setup_private=1 - setup_public=1 - upgrade=1 - # 0.0.1-2020-10-31~ynh1 - # upgrade=1 from_commit=b0541627859d2b702b55f7ac33e7f786e70b3051 - # 0.0.1-2020-12-24~ynh1 - # upgrade=1 from_commit=103b86aa716d289cab00aee49e539cab252e21a3 - # 0.0.1-2021-02-17~ynh1 - # upgrade=1 from_commit=e9864a6c794ba3ec5e6359b298d299f513a157e7 - # 0.0.1.2021.12.28~ynh1 - upgrade=1 from_commit=3409d4986706a0b89c36447a2f435f4cd8dde155 - backup_restore=1 - multi_instance=1 - port_already_use=0 - change_url=1 -;;; Options -Email= -Notification=none -;;; Upgrade options - ; commit=b0541627859d2b702b55f7ac33e7f786e70b3051 - name=0.0.1-2020-10-31~ynh1 - ; commit=103b86aa716d289cab00aee49e539cab252e21a3 - name=0.0.1-2020-12-24~ynh1 - ; commit=e9864a6c794ba3ec5e6359b298d299f513a157e7 - name=0.0.1-2021-02-17~ynh1 - ; commit=3409d4986706a0b89c36447a2f435f4cd8dde155 - name=0.0.1.2021.12.28~ynh1 diff --git a/conf/app.src b/conf/app.src deleted file mode 100644 index 4b32973..0000000 --- a/conf/app.src +++ /dev/null @@ -1,7 +0,0 @@ -SOURCE_URL=https://framagit.org/framasoft/peertube/search-index/-/archive/36a36379b469982e6b2fc219825283e2470135e7/search-index-36a36379b469982e6b2fc219825283e2470135e7.tar.gz -SOURCE_SUM=d5f92138c38642cb1cf559f2260652203aa38cfd03c5811c49e9299d1cdfe3ef -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=tar.gz -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME=search-index.tar.gz -SOURCE_EXTRACT=true diff --git a/conf/nginx.conf b/conf/nginx.conf index 41bddd1..932d6d1 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -2,7 +2,7 @@ location __PATH__/ { # Path to source - alias __FINALPATH__/; + alias __INSTALL_DIR__/; proxy_pass http://localhost:__PORT__; proxy_set_header X-Real-IP $remote_addr; diff --git a/conf/systemd.service b/conf/systemd.service index 1b128a9..dc7fe1b 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -5,11 +5,11 @@ After=network.target [Service] Type=simple Environment=NODE_ENV=production -Environment=NODE_CONFIG_DIR=__FINALPATH__/config +Environment=NODE_CONFIG_DIR=__INSTALL_DIR__/config User=__APP__ Group=__APP__ ExecStart=__YNH_NPM__ start -WorkingDirectory=__FINALPATH__/ +WorkingDirectory=__INSTALL_DIR__/ StandardOutput=syslog StandardError=syslog SyslogIdentifier=__APP__ diff --git a/doc/ADMIN.md b/doc/ADMIN.md new file mode 100644 index 0000000..e8d1162 --- /dev/null +++ b/doc/ADMIN.md @@ -0,0 +1,3 @@ +## Configuration + +To configure this app: modify the file `/var/www/peertube-search-index/config/production.yaml` with SSH. diff --git a/doc/DISCLAIMER.md b/doc/PRE_INSTALL.md similarity index 52% rename from doc/DISCLAIMER.md rename to doc/PRE_INSTALL.md index da5f91e..73eff80 100644 --- a/doc/DISCLAIMER.md +++ b/doc/PRE_INSTALL.md @@ -1,7 +1,3 @@ ## Important points to read before installing 1. **PeerTube search-index** requires a dedicated **root domain**, e.g. search.domain.tld - -## Configuration - -To configure this app: modify the file `/var/www/peertube-search-index/config/production.yaml` with SSH. diff --git a/manifest.json b/manifest.json deleted file mode 100644 index c63fb46..0000000 --- a/manifest.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "name": "PeerTube search-index", - "id": "peertube-search-index", - "packaging_format": 1, - "description": { - "en": "Search engine for PeerTube videos and channels", - "fr": "Moteur de recherche de vidéos et chaînes PeerTube" - }, - "version": "0.0.1.2023.08.08~ynh1", - "url": "https://search.joinpeertube.org/", - "upstream": { - "license": "AGPL-3.0-only", - "website": "https://search.joinpeertube.org/", - "demo": "https://search.joinpeertube.org/", - "admindoc": "https://framagit.org/framasoft/peertube/search-index", - "code": "https://framagit.org/framasoft/peertube/search-index" - }, - "license": "AGPL-3.0-only", - "maintainer": { - "name": "yalh76" - }, - "requirements": { - "yunohost": ">= 4.3.0" - }, - "multi_instance": true, - "services": [ - "nginx" - ], - "arguments": { - "install" : [ - { - "name": "domain", - "type": "domain" - }, - { - "name": "is_public", - "type": "boolean", - "default": true - } - ] - } -} diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..88a105a --- /dev/null +++ b/manifest.toml @@ -0,0 +1,69 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json + +packaging_format = 2 + +id = "peertube-search-index" +name = "PeerTube search-index" +description.en = "Search engine for PeerTube videos and channels" +description.fr = "Moteur de recherche de vidéos et chaînes PeerTube" + +version = "0.0.1.2023.08.08~ynh1" + +maintainers = ["yalh76"] + +[upstream] +license = "AGPL-3.0-only" +website = "https://search.joinpeertube.org/" +demo = "https://search.joinpeertube.org/" +admindoc = "https://framagit.org/framasoft/peertube/search-index" +code = "https://framagit.org/framasoft/peertube/search-index" +fund = "https://framasoft.org/fr/#support" + +[integration] +yunohost = ">= 4.3.0" +architectures = "all" +multi_instance = true +ldap = "not_relevant" +sso = "not_relevant" +disk = "50M" # FIXME: replace with an **estimate** minimum disk requirement. e.g. 20M, 400M, 1G, ... +ram.build = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... +ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... + +[install] + [install.domain] + type = "domain" + + [install.init_main_permission] + type = "group" + default = "visitors" + +[resources] + [resources.sources.main] + url = "https://framagit.org/framasoft/peertube/search-index/-/archive/36a36379b469982e6b2fc219825283e2470135e7/search-index-36a36379b469982e6b2fc219825283e2470135e7.tar.gz" + sha256 = "d5f92138c38642cb1cf559f2260652203aa38cfd03c5811c49e9299d1cdfe3ef" + # Unused because of submodules... + prefetch = false + autoupdate.strategy = "latest_gitlab_tag" + + [resources.system_user] + + [resources.install_dir] + + [resources.permissions] + main.url = "/" + + [resources.ports] + main.default = 8095 + + [resources.apt] + packages = ["git", ] + + [resources.apt.extras.elastic] + repo = "deb https://artifacts.elastic.co/packages/oss-7.x/apt stable main" + key = "https://artifacts.elastic.co/GPG-KEY-elasticsearch" + packages = ["elasticsearch-oss"] + + [resources.apt.extras.yarn] + repo = "deb https://dl.yarnpkg.com/debian/ stable main" + key = "https://dl.yarnpkg.com/debian/pubkey.gpg" + packages = ["yarn"] diff --git a/scripts/_common.sh b/scripts/_common.sh index 3075898..cc4e944 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,21 +4,28 @@ # COMMON VARIABLES #================================================= -# dependencies used by the app -pkg_dependencies="git" - -extra_pkg_dependencies="elasticsearch-oss" - NODEJS_VERSION=16 -REPOSITORY="https://framagit.org/framasoft/peertube/search-index" - -COMMIT="316adda0db184cb36f0645a60dc8f6a1611ecd28" - #================================================= # PERSONAL HELPERS #================================================= +_git_clone_or_pull() { + repo_dir="$1" + + upstream_repository=$(ynh_read_manifest --key='.upstream.code') + upstream_url=$(ynh_read_manifest --key='.resources.sources.main.url') + upstream_commit=$(echo "$upstream_url" | sed -e "s|^${upstream_repository}/-/archive/\([^/]*\)/.*|\1|") + + if [ -d "$repo_dir" ]; then + ynh_exec_as "$app" git -C "$repo_dir" fetch --quiet + else + ynh_exec_as "$app" git clone "$upstream_repository" "$repo_dir" --quiet + fi + ynh_exec_as "$app" git -C "$repo_dir" checkout "$upstream_commit" + ynh_exec_as "$app" git -C "$repo_dir" submodule update --init --recursive +} + #================================================= # EXPERIMENTAL HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index f78c623..132f64e 100644 --- a/scripts/backup +++ b/scripts/backup @@ -10,26 +10,6 @@ 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 - -#================================================= -# LOAD SETTINGS -#================================================= -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) - #================================================= # DECLARE DATA AND CONF FILES TO BACKUP #================================================= @@ -39,26 +19,16 @@ ynh_print_info --message="Declaring files to be backed up..." # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$final_path" +ynh_backup --src_path="$install_dir" #================================================= -# BACKUP THE NGINX CONFIGURATION +# SYSTEM CONFIGURATION #================================================= ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# SPECIFIC BACKUP -#================================================= -# BACKUP LOGROTATE -#================================================= - ynh_backup --src_path="/etc/logrotate.d/$app" -#================================================= -# BACKUP SYSTEMD -#================================================= - ynh_backup --src_path="/etc/systemd/system/$app.service" #================================================= diff --git a/scripts/change_url b/scripts/change_url index 8dca7d6..ca645f1 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -9,68 +9,12 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -old_domain=$YNH_APP_OLD_DOMAIN -old_path=$YNH_APP_OLD_PATH - -new_domain=$YNH_APP_NEW_DOMAIN -new_path="/" - -app=$YNH_APP_INSTANCE_NAME - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -# Needed for helper "ynh_add_nginx_config" -final_path=$(ynh_app_setting_get --app=$app --key=final_path) - -# Add settings here as needed by your application -port=$(ynh_app_setting_get --app=$app --key=port) - -#================================================= -# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP -#================================================= -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 () { - # 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 - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# CHECK WHICH PARTS SHOULD BE CHANGED -#================================================= - -change_domain=0 -if [ "$old_domain" != "$new_domain" ] -then - change_domain=1 -fi - -change_path=0 -if [ "$old_path" != "$new_path" ] -then - change_path=1 -fi - #================================================= # STANDARD MODIFICATIONS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." +ynh_script_progression --message="Stopping $app's systemd service..." ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" --line_match="Stopped $app search index daemon" @@ -79,52 +23,15 @@ ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" --li #================================================= ynh_script_progression --message="Updating NGINX web server configuration..." -nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf +ynh_change_url_nginx_config -# 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 - ynh_backup_if_checksum_is_different --file="$nginx_conf_path" - # Set global variables for NGINX helper - domain="$old_domain" - path_url="$new_path" - # Create a dedicated NGINX config - ynh_add_nginx_config -fi - -# Change the domain for NGINX -if [ $change_domain -eq 1 ] -then - # Delete file checksum for the old conf file location - ynh_delete_file_checksum --file="$nginx_conf_path" - mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf - # Store file checksum for the new config file location - ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" -fi - -#================================================= -# SPECIFIC MODIFICATIONS -#================================================= -# ... -#================================================= - -#================================================= -# GENERIC FINALISATION #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression --message="Starting $app's systemd service..." # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Server listening on port" - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." - -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="Server listening on port" #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index f81fb89..83248a6 100644 --- a/scripts/install +++ b/scripts/install @@ -10,114 +10,39 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# MANAGE SCRIPT FAILURE +# INSTALL NODEJS #================================================= +ynh_script_progression --message="Installing NodeJS..." -ynh_clean_setup () { - true -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors +ynh_install_nodejs --nodejs_version="$NODEJS_VERSION" #================================================= -# RETRIEVE ARGUMENTS FROM THE MANIFEST +# START ELASTICSEARCH #================================================= +ynh_script_progression --message="Starting elasticsearch..." -domain=$YNH_APP_ARG_DOMAIN -path_url="/" -is_public=$YNH_APP_ARG_IS_PUBLIC - -app=$YNH_APP_INSTANCE_NAME - -#================================================= -# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS -#================================================= -ynh_script_progression --message="Validating installation parameters..." - -final_path=/var/www/$app -test ! -e "$final_path" || ynh_die --message="This path already contains a folder" - -# Register (book) web path -ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url - -#================================================= -# STORE SETTINGS FROM MANIFEST -#================================================= -ynh_script_progression --message="Storing installation settings..." - -ynh_app_setting_set --app=$app --key=domain --value=$domain -ynh_app_setting_set --app=$app --key=path --value=$path_url - -#================================================= -# STANDARD MODIFICATIONS -#================================================= -# FIND AND OPEN A PORT -#================================================= -ynh_script_progression --message="Finding an available port..." - -# Find an available port -port=$(ynh_find_port --port=8095) -ynh_app_setting_set --app=$app --key=port --value=$port - -#================================================= -# INSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Installing dependencies..." - -ynh_install_app_dependencies $pkg_dependencies -ynh_install_extra_app_dependencies --repo="deb https://artifacts.elastic.co/packages/oss-7.x/apt stable main" --package="$extra_pkg_dependencies" --key="https://artifacts.elastic.co/GPG-KEY-elasticsearch" systemctl enable elasticsearch.service --quiet systemctl start elasticsearch.service -ynh_install_nodejs --nodejs_version=$NODEJS_VERSION -ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" - -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." - -# Create a system user -ynh_system_user_create --username=$app --home_dir=$final_path #================================================= # 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 -# Download, check integrity, uncompress and patch the source from app.src +_git_clone_or_pull "$install_dir/sources" +chmod -R o-rwx "$install_dir" +chown -R "$app:$app" "$install_dir" -install -d -o $app -g $app -m 0750 $final_path -ynh_exec_as $app git clone $REPOSITORY $final_path --quiet -pushd "$final_path" - ynh_exec_as $app git checkout $COMMIT --quiet -popd - -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:$app "$final_path" - -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Configuring NGINX web server..." - -# Create a dedicated NGINX config -ynh_add_nginx_config - -#================================================= -# SPECIFIC SETUP #================================================= # BUILDING #================================================= ynh_script_progression --message="Building..." -pushd "$final_path" - ynh_exec_as $app git submodule update --init --recursive - ynh_use_nodejs - ynh_exec_as $app env $ynh_node_load_PATH yarn install --pure-lockfile - ynh_exec_as $app mkdir -p "$final_path/dist" - ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm run build +pushd "$install_dir" + ynh_use_nodejs + ynh_exec_as "$app" env "$ynh_node_load_PATH" yarn install --pure-lockfile + ynh_exec_as "$app" mkdir -p "$install_dir/dist" + ynh_exec_as "$app" env "$ynh_node_load_PATH" "$ynh_npm" run build popd #================================================= @@ -125,63 +50,33 @@ popd #================================================= ynh_script_progression --message="Adding a config file..." -ynh_add_config --template="../conf/default.yaml" --destination="$final_path/config/production.yaml" +ynh_add_config --template="default.yaml" --destination="$install_dir/config/production.yaml" -chmod 400 "$final_path/config/production.yaml" -chown $app:$app "$final_path/config/production.yaml" +chmod 400 "$install_dir/config/production.yaml" +chown "$app:$app" "$install_dir/config/production.yaml" #================================================= -# SETUP SYSTEMD +# SYSTEM CONFIGURATION #================================================= -ynh_script_progression --message="Configuring a systemd service..." +ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 + +# Create a dedicated NGINX config +ynh_add_nginx_config # Create a dedicated systemd config ynh_add_systemd_config - -#================================================= -# GENERIC FINALIZATION -#================================================= -# SETUP LOGROTATE -#================================================= -ynh_script_progression --message="Configuring log rotation..." +yunohost service add "$app" --description="$app search index daemon" # Use logrotate to manage application logfile(s) ynh_use_logrotate -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." - -yunohost service add $app --description="$app search index daemon" - #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression --message="Starting $app's systemd service..." # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Server listening on port" - -#================================================= -# SETUP SSOWAT -#================================================= -ynh_script_progression --message="Configuring permissions..." - -# Make app public if necessary -if [ $is_public -eq 1 ] -then - # Everyone can access the app. - # The "main" permission is automatically created before the install script. - ynh_permission_update --permission="main" --add="visitors" -fi - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." - -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="Server listening on port" #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index 8e9e32f..97ba2dc 100644 --- a/scripts/remove +++ b/scripts/remove @@ -10,79 +10,24 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -port=$(ynh_app_setting_get --app=$app --key=port) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) - -#================================================= -# STANDARD REMOVE -#================================================= -# REMOVE SERVICE INTEGRATION IN YUNOHOST +# REMOVE SYSTEM CONFIGURATIONS #================================================= +ynh_script_progression --message="Removing system configurations related to $app..." --weight=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..." - yunohost service remove $app +if ynh_exec_warn_less yunohost service status "$app" >/dev/null; then + yunohost service remove "$app" fi -#================================================= -# STOP AND REMOVE SERVICE -#================================================= -ynh_script_progression --message="Stopping and removing the systemd service..." - # Remove the dedicated systemd config ynh_remove_systemd_config -#================================================= -# REMOVE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Removing logrotate configuration..." - # Remove the app-specific logrotate config ynh_remove_logrotate -#================================================= -# REMOVE APP MAIN DIR -#================================================= -ynh_script_progression --message="Removing app main directory..." - -# Remove the app directory securely -ynh_secure_remove --file="$final_path" - -#================================================= -# REMOVE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Removing NGINX web server configuration..." - # Remove the dedicated NGINX config ynh_remove_nginx_config -#================================================= -# REMOVE DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies..." - -# Remove metapackage and its dependencies -ynh_remove_app_dependencies - -#================================================= -# GENERIC FINALIZATION -#================================================= -# REMOVE DEDICATED USER -#================================================= -ynh_script_progression --message="Removing the dedicated system user..." - -# Delete a system user -ynh_system_user_delete --username=$app - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index 863b1f8..adcb874 100644 --- a/scripts/restore +++ b/scripts/restore @@ -11,112 +11,49 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= -# MANAGE SCRIPT FAILURE +# INSTALL NODEJS #================================================= +ynh_script_progression --message="Reinstalling NodeJS..." -ynh_clean_setup () { - true -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors +ynh_install_nodejs --nodejs_version="$NODEJS_VERSION" #================================================= -# LOAD SETTINGS +# START ELASTICSEARCH #================================================= -ynh_script_progression --message="Loading installation settings..." +ynh_script_progression --message="Starting elasticsearch..." -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) - -#================================================= -# CHECK IF THE APP CAN BE RESTORED -#================================================= -ynh_script_progression --message="Validating restoration parameters..." - -test ! -d $final_path \ - || ynh_die --message="There is already a directory: $final_path " - -#================================================= -# STANDARD RESTORATION STEPS -#================================================= -# 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..." - -# Create the dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir=$final_path +systemctl enable elasticsearch.service --quiet +systemctl start elasticsearch.service #================================================= # RESTORE THE APP MAIN DIR #================================================= ynh_script_progression --message="Restoring the app main directory..." -ynh_restore_file --origin_path="$final_path" +ynh_restore_file --origin_path="$install_dir" -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:$app "$final_path" +chmod -R o-rwx "$install_dir" +chown -R "$app:$app" "$install_dir" #================================================= -# SPECIFIC RESTORATION +# RESTORE SYSTEM CONFIGURATIONS #================================================= -# REINSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Reinstalling dependencies..." +ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 -# Define and install dependencies -ynh_install_app_dependencies $pkg_dependencies -ynh_install_extra_app_dependencies --repo="deb https://artifacts.elastic.co/packages/oss-7.x/apt stable main" --package="$extra_pkg_dependencies" --key="https://artifacts.elastic.co/GPG-KEY-elasticsearch" -systemctl enable elasticsearch.service --quiet -systemctl start elasticsearch.service -ynh_install_nodejs --nodejs_version=$NODEJS_VERSION -ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" - -#================================================= -# RESTORE SYSTEMD -#================================================= -ynh_script_progression --message="Restoring the systemd configuration..." +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file --origin_path="/etc/systemd/system/$app.service" -systemctl enable $app.service --quiet - -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the logrotate configuration..." +systemctl enable "$app.service" --quiet +yunohost service add "$app" --description="$app search index daemon" ynh_restore_file --origin_path="/etc/logrotate.d/$app" -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." - -yunohost service add $app --description="$app search index daemon" - #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Server listening on port" - -#================================================= -# GENERIC FINALIZATION -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." +ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="Server listening on port" ynh_systemd_action --service_name=nginx --action=reload diff --git a/scripts/upgrade b/scripts/upgrade index bd5dd2f..c9d2c2b 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -9,126 +9,64 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -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) -port=$(ynh_app_setting_get --app=$app --key=port) - -#================================================= -# CHECK VERSION -#================================================= -ynh_script_progression --message="Checking version..." - -upgrade_type=$(ynh_check_app_version_changed) - -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." - -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - # Restore it if the upgrade fails - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." +ynh_script_progression --message="Stopping $app's systemd service..." -ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" --line_match="Stopped $app search index daemon" +ynh_systemd_action --service_name="$app" --action="stop" --log_path="systemd" --line_match="Stopped $app search index daemon" + +#================================================= +# INSTALL NODEJS +#================================================= +ynh_script_progression --message="Updating NodeJS..." + +ynh_install_nodejs --nodejs_version="$NODEJS_VERSION" + +#================================================= +# START ELASTICSEARCH +#================================================= +ynh_script_progression --message="Starting elasticsearch..." + +systemctl enable elasticsearch.service --quiet +systemctl start elasticsearch.service #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= ynh_script_progression --message="Ensuring downward compatibility..." -# Cleaning legacy permissions -if ynh_legacy_permissions_exists; then - ynh_legacy_permissions_delete_all - - ynh_app_setting_delete --app=$app --key=is_public +# Move git repository one step lower +if [ -d "$install_dir/.git" ]; then + mkdir "${install_dir}__tmp__" + mv "$install_dir" "${install_dir}__tmp__" + mv "${install_dir}__tmp__" "$install_dir" fi # Fix upgrade from 0.0.1.2022.06.03~ynh1 -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:$app "$final_path" - -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." - -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir=$final_path +chmod 750 "$install_dir" +chmod -R o-rwx "$install_dir" +chown -R "$app:$app" "$install_dir" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Upgrading source files..." -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - ynh_script_progression --message="Upgrading source files..." +_git_clone_or_pull "$install_dir/sources" +chmod -R o-rwx "$install_dir" +chown -R "$app:$app" "$install_dir" - # Download, check integrity, uncompress and patch the source from app.src - pushd "$final_path" - ynh_exec_as $app git checkout master - ynh_exec_as $app git pull --quiet - ynh_exec_as $app git checkout $COMMIT --quiet - popd -fi - -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:$app "$final_path" - -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Upgrading NGINX web server configuration..." - -# Create a dedicated NGINX config -ynh_add_nginx_config - -#================================================= -# UPGRADE DEPENDENCIES -#================================================= -ynh_script_progression --message="Upgrading dependencies..." - -ynh_install_app_dependencies $pkg_dependencies -ynh_install_extra_app_dependencies --repo="deb https://artifacts.elastic.co/packages/oss-7.x/apt stable main" --package="$extra_pkg_dependencies" --key="https://artifacts.elastic.co/GPG-KEY-elasticsearch" -systemctl enable elasticsearch.service --quiet -systemctl start elasticsearch.service -ynh_install_nodejs --nodejs_version=$NODEJS_VERSION -ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" - -#================================================= -# SPECIFIC UPGRADE #================================================= # BUILDING #================================================= ynh_script_progression --message="Building..." -pushd "$final_path" - ynh_exec_as $app git submodule update --init --recursive - ynh_use_nodejs - ynh_exec_as $app env $ynh_node_load_PATH yarn install --pure-lockfile - ynh_exec_as $app mkdir -p "$final_path/dist" - ynh_exec_as $app env $ynh_node_load_PATH $ynh_npm run build +pushd "$install_dir" + ynh_use_nodejs + ynh_exec_as "$app" env "$ynh_node_load_PATH" yarn install --pure-lockfile + ynh_exec_as "$app" mkdir -p "$install_dir/dist" + ynh_exec_as "$app" env "$ynh_node_load_PATH" "$ynh_npm" run build popd #================================================= @@ -136,49 +74,32 @@ popd #================================================= ynh_script_progression --message="Updating a config file..." -ynh_add_config --template="../conf/default.yaml" --destination="$final_path/config/production.yaml" +ynh_add_config --template="default.yaml" --destination="$install_dir/config/production.yaml" -chmod 400 "$final_path/config/production.yaml" -chown $app:$app "$final_path/config/production.yaml" +chmod 400 "$install_dir/config/production.yaml" +chown "$app:$app" "$install_dir/config/production.yaml" #================================================= -# SETUP SYSTEMD +# REAPPLY SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Upgrading systemd configuration..." +ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 + +# Create a dedicated NGINX config +ynh_add_nginx_config # Create a dedicated systemd config ynh_add_systemd_config - -#================================================= -# GENERIC FINALIZATION -#================================================= -# SETUP LOGROTATE -#================================================= -ynh_script_progression --message="Upgrading logrotate configuration..." +yunohost service add "$app" --description="$app search index daemon" # Use logrotate to manage app-specific logfile(s) ynh_use_logrotate --non-append -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." - -yunohost service add $app --description="$app search index daemon" - #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression --message="Starting $app's systemd service..." -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Server listening on port" - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." - -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="Server listening on port" #================================================= # END OF SCRIPT diff --git a/tests.toml b/tests.toml new file mode 100644 index 0000000..659c9f4 --- /dev/null +++ b/tests.toml @@ -0,0 +1,7 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/tests.v1.schema.json + +test_format = 1.0 + +[default] + + test_upgrade_from.3409d4986706a0b89c36447a2f435f4cd8dde155.name = "0.0.1.2021.12.28~ynh1"