diff --git a/conf/exporter.service b/conf/exporter.service index 89079e1..c29445d 100644 --- a/conf/exporter.service +++ b/conf/exporter.service @@ -9,9 +9,9 @@ User=__APP__ Group=__APP__ WorkingDirectory=__INSTALL_DIR__/exporter -ExecStart=__YNH_NODE__ --env-file=.env app.js +ExecStart=__NODEJS_DIR__/node --env-file=.env app.js Restart=always -Environment=__YNH_NODE_LOAD_PATH__ +Environment=PATH=__PATH_WITH_NODEJS__ StandardOutput=append:/var/log/__APP__/__APP__-exporter.log StandardError=inherit Restart=on-failure diff --git a/manifest.toml b/manifest.toml index 34c0925..f52dc51 100644 --- a/manifest.toml +++ b/manifest.toml @@ -22,6 +22,7 @@ code = "https://github.com/penpot/penpot" [integration] yunohost = '>= 11.2.12' +helpers_version = "2.1" architectures = ["amd64", "arm64"] multi_instance = true ldap = false @@ -73,6 +74,7 @@ ram.runtime = "50M" allow_email = true [resources.install_dir] + group = "www-data:r-x" [resources.data_dir] subdirs = ["assets"] diff --git a/scripts/_common.sh b/scripts/_common.sh index fa0cdf5..01b9999 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,14 +1,10 @@ #!/bin/bash #================================================= -# COMMON VARIABLES +# COMMON VARIABLES AND CUSTOM HELPERS #================================================= nodejs_version=21 current_hash="a1c78683" version="2.1.2-10698-g380c77a7" build_date="Wed, 7 Aug 2024 09:14:03 +0000" - -#================================================= -# PERSONAL HELPERS -#================================================= diff --git a/scripts/backup b/scripts/backup index 33222fe..32a8dad 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,41 +1,32 @@ #!/bin/bash #### App file generated with YoloGen, the YunoHost app generator, version . -#================================================= -# GENERIC START -#================================================= -# 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 -#================================================= -# DECLARE DATA AND CONF FILES TO BACKUP -#================================================= -ynh_print_info --message="Declaring files to be backed up..." +ynh_print_info "Declaring files to be backed up..." -ynh_backup --src_path="$install_dir" +ynh_backup "$install_dir" -ynh_backup --src_path="$data_dir" --is_big +ynh_backup "$data_dir" -ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" -ynh_backup --src_path="/etc/logrotate.d/$app" +ynh_backup "/etc/logrotate.d/$app" -ynh_backup --src_path="/etc/systemd/system/$app-backend.service" -ynh_backup --src_path="/etc/systemd/system/$app-exporter.service" +ynh_backup "/etc/systemd/system/$app-backend.service" +ynh_backup "/etc/systemd/system/$app-exporter.service" #================================================= # BACKUP THE POSTGRESQL DATABASE #================================================= -ynh_print_info --message="Backing up the PostgreSQL database..." +ynh_print_info "Backing up the PostgreSQL database..." -ynh_psql_dump_db --database="$db_name" > db.sql +ynh_psql_dump_db > db.sql #================================================= # END OF SCRIPT #================================================= -ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." \ No newline at end of file +ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." \ No newline at end of file diff --git a/scripts/change_url b/scripts/change_url index 56c9b45..8544cf2 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -1,28 +1,22 @@ #!/bin/bash -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." +ynh_script_progression "Stopping $app's systemd service..." -ynh_systemd_action --service_name=$app-backend --action="stop" -ynh_systemd_action --service_name=$app-exporter --action="stop" +ynh_systemctl --service=$app-backend --action="stop" +ynh_systemctl --service=$app-exporter --action="stop" #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating NGINX web server configuration..." +ynh_script_progression "Updating NGINX web server configuration..." -ynh_change_url_nginx_config +ynh_config_change_url_nginx #================================================= # SPECIFIC MODIFICATIONS @@ -33,14 +27,14 @@ ynh_change_url_nginx_config #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name=$app-backend --action="start" --log_path="/var/log/$app/$app-backend.log" --line_match="welcome to penpot" +ynh_systemctl --service=$app-backend --action="start" --log_path="/var/log/$app/$app-backend.log" --wait_until="welcome to penpot" -ynh_systemd_action --service_name=$app-exporter --action="start" --log_path="/var/log/$app/$app-exporter.log" --line_match="redis connection established" +ynh_systemctl --service=$app-exporter --action="start" --log_path="/var/log/$app/$app-exporter.log" --wait_until="redis connection established" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Change of URL completed for $app" --last \ No newline at end of file +ynh_script_progression "Change of URL completed for $app" diff --git a/scripts/install b/scripts/install index b2a0e8f..0cf7abd 100644 --- a/scripts/install +++ b/scripts/install @@ -1,46 +1,38 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= source _common.sh source /usr/share/yunohost/helpers - - redis_db=$(ynh_redis_get_free_db) secret_key=$(ynh_string_random --length=40) main_domain=$(yunohost domain list --output-as plain | grep -A1 -e '#main' | tail -n 1) -ynh_app_setting_set --app=$app --key=redis_db --value=$redis_db -ynh_app_setting_set --app=$app --key=secret_key --value=$secret_key -ynh_app_setting_set --app=$app --key=main_domain --value=$main_domain +ynh_app_setting_set --key=redis_db --value=$redis_db +ynh_app_setting_set --key=secret_key --value=$secret_key +ynh_app_setting_set --key=main_domain --value=$main_domain #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing dependencies..." --weight=10 +ynh_script_progression "Installing dependencies..." # Install Nodejs -ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version -ynh_use_nodejs +ynh_nodejs_install ynh_setup_source --dest_dir="$install_dir/jdk" --source_id="jdk" export JAVA_HOME=$install_dir/jdk -chown -R $app:www-data "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:www-data "$install_dir" tmp_dir=$(mktemp -d) pushd $tmp_dir curl -L -O https://github.com/clojure/brew-install/releases/latest/download/linux-install.sh chmod +x linux-install.sh - ynh_exec_warn_less ./linux-install.sh -p $install_dir/clojure + ynh_hide_warnings ./linux-install.sh -p $install_dir/clojure popd -ynh_secure_remove --file=$tmp_dir +ynh_safe_rm $tmp_dir ynh_setup_source --dest_dir="$install_dir/babashka" --source_id="babashka" @@ -51,31 +43,31 @@ export PATH=$JAVA_HOME/bin:$install_dir/clojure/bin:$install_dir/babashka:$PATH #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." +ynh_script_progression "Setting up source files..." ynh_setup_source --dest_dir="$install_dir/build" -chown -R $app:www-data "$install_dir" -chmod -R o-rwx "$install_dir" - +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:www-data "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir" #================================================= # INSTALL APP #================================================= -ynh_script_progression --message="Building frontend..." --weight=5 +ynh_script_progression "Building frontend..." pushd $install_dir/build/frontend - ynh_exec_warn_less env $ynh_node_load_PATH COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack enable - ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack enable - ynh_exec_warn_less ynh_exec_as "$app" env $ynh_node_load_PATH COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack prepare --activate - ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_ENV=production COREPACK_ENABLE_DOWNLOAD_PROMPT=0 yarn install --immutable - - # ynh_exec_warn_less - ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH JAVA_HOME=$JAVA_HOME NODE_ENV=production clojure -J-Xms100M -J-Xmx800M -J-XX:+UseSerialGC -M:dev:shadow-cljs release main --config-merge "{:release-version \"${current_hash}\"}" + ynh_hide_warnings env node_load_PATH corepack enable + ynh_hide_warnings ynh_exec_as_app node_load_PATH corepack enable + ynh_hide_warnings ynh_exec_as_app node_load_PATH corepack prepare --activate + ynh_hide_warnings ynh_exec_as_app node_load_PATH NODE_ENV=production yarn install --immutable - ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_ENV=production yarn run compile + # ynh_hide_warnings - ynh_replace_string --match_string="%version%" --replace_string="$version" --target_file="$install_dir/build/frontend/resources/public/index.html" - ynh_replace_string --match_string="%buildDate%" --replace_string="$build_date" --target_file="$install_dir/build/frontend/resources/public/index.html" + ynh_hide_warnings ynh_exec_as_app PATH=$PATH JAVA_HOME=$JAVA_HOME NODE_ENV=production clojure -J-Xms100M -J-Xmx800M -J-XX:+UseSerialGC -M:dev:shadow-cljs release main --config-merge "{:release-version \"${current_hash}\"}" + + ynh_hide_warnings ynh_exec_as_app node_load_PATH NODE_ENV=production yarn run compile + + ynh_replace --match="%version%" --replace="$version" --file="$install_dir/build/frontend/resources/public/index.html" + ynh_replace --match="%buildDate%" --replace="$build_date" --file="$install_dir/build/frontend/resources/public/index.html" #echo "$version" > target/version.txt; popd @@ -84,7 +76,7 @@ mv $install_dir/build/frontend/resources/public/* $install_dir/frontend chown -R $app:www-data $install_dir/frontend chmod -R 750 $install_dir/frontend -ynh_script_progression --message="Building backend..." --weight=5 +ynh_script_progression "Building backend..." pushd $install_dir/build/backend mkdir -p target/classes; @@ -93,7 +85,7 @@ pushd $install_dir/build/backend cp ../CHANGES.md target/classes/changelog.md; chown -R $app:$app target - ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH JAVA_HOME=$JAVA_HOME clojure -T:build jar; + ynh_hide_warnings ynh_exec_as_app PATH=$PATH JAVA_HOME=$JAVA_HOME clojure -T:build jar; mv target/penpot.jar target/dist/penpot.jar cp resources/log4j2.xml target/dist/log4j2.xml cp scripts/run.template.sh target/dist/run.sh @@ -110,17 +102,17 @@ mv $install_dir/build/backend/target/dist/* $install_dir/backend chown -R $app:$app $install_dir/backend chmod -R 700 $install_dir/backend -ynh_script_progression --message="Building exporter..." --weight=5 +ynh_script_progression "Building exporter..." pushd $install_dir/build/exporter - ynh_exec_warn_less ynh_exec_as "$app" env $ynh_node_load_PATH corepack prepare --activate - ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install --immutable - ynh_secure_remove --file="target" - ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH JAVA_HOME=$JAVA_HOME NODE_ENV=production clojure -M:dev:shadow-cljs release main + ynh_hide_warnings ynh_exec_as_app node_load_PATH corepack prepare --activate + ynh_hide_warnings ynh_exec_as_app node_load_PATH yarn install --immutable + ynh_safe_rm "target" + ynh_hide_warnings ynh_exec_as_app PATH=$PATH JAVA_HOME=$JAVA_HOME NODE_ENV=production clojure -M:dev:shadow-cljs release main cp yarn.lock target/ cp package.json target/ - - ynh_replace_string --match_string="%version%" --replace_string="$version" --target_file="$install_dir/build/exporter/target/app.js" + + ynh_replace --match="%version%" --replace="$version" --file="$install_dir/build/exporter/target/app.js" popd mkdir -p $install_dir/exporter @@ -129,85 +121,85 @@ cp $install_dir/build/.yarnrc.yml $install_dir/exporter chown -R $app:$app $install_dir/exporter chmod -R 700 $install_dir/exporter -ynh_secure_remove --file=$install_dir/.cache +ynh_safe_rm $install_dir/.cache pushd $install_dir/exporter - ynh_exec_warn_less ynh_exec_as "$app" env $ynh_node_load_PATH corepack prepare --activate - ynh_exec_as $app env $ynh_node_load_PATH NODE_ENV=production yarn install --immutable - ynh_exec_as $app env $ynh_node_load_PATH NODE_ENV=production yarn run playwright install chromium + ynh_hide_warnings ynh_exec_as_app node_load_PATH corepack prepare --activate + ynh_exec_as_app node_load_PATH NODE_ENV=production yarn install --immutable + ynh_exec_as_app node_load_PATH NODE_ENV=production yarn run playwright install chromium popd -ynh_script_progression --message="Cleaning up..." --weight=1 +ynh_script_progression "Cleaning up..." -ynh_secure_remove --file=$install_dir/.npm -ynh_secure_remove --file=$install_dir/.yarn -ynh_secure_remove --file=$install_dir/build -ynh_secure_remove --file=$install_dir/.m2 -ynh_secure_remove --file=$install_dir/.clojure -ynh_secure_remove --file=$install_dir/clojure -ynh_secure_remove --file=$install_dir/babashka -ynh_secure_remove --file=$install_dir/.cache/ms-playwright/firefox-* -ynh_secure_remove --file=$install_dir/.cache/ms-playwright/webkit-* -ynh_secure_remove --file=$install_dir/.cache/yarn -ynh_secure_remove --file=$install_dir/.cache/node +ynh_safe_rm $install_dir/.npm +ynh_safe_rm $install_dir/.yarn +ynh_safe_rm $install_dir/build +ynh_safe_rm $install_dir/.m2 +ynh_safe_rm $install_dir/.clojure +ynh_safe_rm $install_dir/clojure +ynh_safe_rm $install_dir/babashka +ynh_safe_rm $install_dir/.cache/ms-playwright/firefox-* +ynh_safe_rm $install_dir/.cache/ms-playwright/webkit-* +ynh_safe_rm $install_dir/.cache/yarn +ynh_safe_rm $install_dir/.cache/node #================================================= # SYSTEM CONFIGURATION #================================================= -ynh_script_progression --message="Adding system configurations related to $app..." +ynh_script_progression "Adding system configurations related to $app..." # Create a dedicated NGINX config using the conf/nginx.conf template -ynh_add_nginx_config +ynh_config_add_nginx # Create a dedicated systemd config -ynh_add_systemd_config --template="backend.service" --service="$app-backend" +ynh_config_add_systemd --template="backend.service" --service="$app-backend" yunohost service add $app-backend --log="/var/log/$app/$app-backend.log" -ynh_add_systemd_config --template="exporter.service" --service="$app-exporter" +ynh_config_add_systemd --template="exporter.service" --service="$app-exporter" yunohost service add $app-exporter --log="/var/log/$app/$app-exporter.log" # Use logrotate to manage application logfile(s) mkdir -p /var/log/$app touch /var/log/$app/$app-backend.log touch /var/log/$app/$app-exporter.log -chown -R $app: /var/log/$app +#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app: /var/log/$app -ynh_use_logrotate --logfile="/var/log/$app/$app-backend.log" -ynh_use_logrotate --logfile="/var/log/$app/$app-exporter.log" +ynh_config_add_logrotate "/var/log/$app/$app-backend.log" +ynh_config_add_logrotate "/var/log/$app/$app-exporter.log" #================================================= # APP INITIAL CONFIGURATION #================================================= # ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Updating database configuration..." -ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";" --database=$db_name +ynh_script_progression "Updating database configuration..." +ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";" -ynh_script_progression --message="Adding app's configuration file..." +ynh_script_progression "Adding app's configuration file..." -ynh_add_config --template="config.js" --destination="$install_dir/frontend/js/config.js" -chmod 755 "$install_dir/frontend/js/config.js" -chown $app:www-data "$install_dir/frontend/js/config.js" +ynh_config_add --template="config.js" --destination="$install_dir/frontend/js/config.js" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 755 "$install_dir/frontend/js/config.js" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:www-data "$install_dir/frontend/js/config.js" -ynh_add_config --template="environ" --destination="$install_dir/backend/environ" -chmod 400 "$install_dir/backend/environ" -chown $app:$app "$install_dir/backend/environ" +ynh_config_add --template="environ" --destination="$install_dir/backend/environ" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/backend/environ" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:$app "$install_dir/backend/environ" -ynh_add_config --template="exporter.env" --destination="$install_dir/exporter/.env" -chmod 400 "$install_dir/exporter/.env" -chown $app:$app "$install_dir/exporter/.env" +ynh_config_add --template="exporter.env" --destination="$install_dir/exporter/.env" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/exporter/.env" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:$app "$install_dir/exporter/.env" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_script_progression "Starting $app's systemd service..." # Start a systemd service -ynh_systemd_action --service_name=$app-backend --action="start" --log_path="/var/log/$app/$app-backend.log" --line_match="welcome to penpot" +ynh_systemctl --service=$app-backend --action="start" --log_path="/var/log/$app/$app-backend.log" --wait_until="welcome to penpot" -ynh_systemd_action --service_name=$app-exporter --action="start" --log_path="/var/log/$app/$app-exporter.log" --line_match="redis connection established" +ynh_systemctl --service=$app-exporter --action="start" --log_path="/var/log/$app/$app-exporter.log" --wait_until="redis connection established" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" --last +ynh_script_progression "Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index e936f73..a271e98 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,10 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= source _common.sh source /usr/share/yunohost/helpers @@ -13,28 +8,26 @@ source /usr/share/yunohost/helpers #================================================= # REMOVE SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Removing system configurations related to $app..." +ynh_script_progression "Removing system configurations related to $app..." # 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-backend >/dev/null +if ynh_hide_warnings yunohost service status $app-backend >/dev/null then - ynh_script_progression --message="Removing $app-backend service integration..." + ynh_script_progression "Removing $app-backend service integration..." yunohost service remove $app-backend - ynh_remove_systemd_config --service="$app-backend" + ynh_config_remove_systemd"$app-backend" fi -if ynh_exec_warn_less yunohost service status $app-exporter >/dev/null +if ynh_hide_warnings yunohost service status $app-exporter >/dev/null then - ynh_script_progression --message="Removing $app-exporter service integration..." + ynh_script_progression "Removing $app-exporter service integration..." yunohost service remove $app-exporter - ynh_remove_systemd_config --service="$app-exporter" + ynh_config_remove_systemd"$app-exporter" fi -ynh_remove_nginx_config - -ynh_remove_logrotate - +ynh_config_remove_nginx +ynh_config_remove_logrotate ynh_redis_remove_db "$redis_db" @@ -42,4 +35,4 @@ ynh_redis_remove_db "$redis_db" # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" --last \ No newline at end of file +ynh_script_progression "Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index ec39339..bbd4053 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# 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 @@ -14,24 +8,24 @@ source /usr/share/yunohost/helpers # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring NodeJS..." --weight=2 -ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version +ynh_script_progression "Restoring NodeJS..." +ynh_nodejs_install -ynh_script_progression --message="Restoring the app main directory..." --weight=1 +ynh_script_progression "Restoring the app main directory..." -ynh_restore_file --origin_path="$install_dir" +ynh_restore "$install_dir" -chown -R $app:$app "$install_dir" -chown $app:www-data "$install_dir" -chmod -R o-rwx "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:$app "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:www-data "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir/frontend" #================================================= # RESTORE THE DATA DIRECTORY #================================================= -ynh_script_progression --message="Restoring the data directory..." --weight=1 +ynh_script_progression "Restoring the data directory..." -ynh_restore_file --origin_path="$data_dir" --not_mandatory +ynh_restore "$data_dir" chown -R $app:www-data "$data_dir" @@ -39,34 +33,34 @@ chown -R $app:www-data "$data_dir" # RESTORE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1 +ynh_script_progression "Restoring the PostgreSQL database..." -ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql +ynh_psql_db_shell < ./db.sql -ynh_script_progression --message="Updating database configuration..." -ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";" --database=$db_name +ynh_script_progression "Updating database configuration..." +ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";" #================================================= # RESTORE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 +ynh_script_progression "Restoring system configurations related to $app..." # Use logrotate to manage application logfile(s) mkdir -p /var/log/$app touch /var/log/$app/$app-backend.log touch /var/log/$app/$app-exporter.log -chown -R $app: /var/log/$app +#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app: /var/log/$app -ynh_restore_file --origin_path="/etc/logrotate.d/$app" +ynh_restore "/etc/logrotate.d/$app" -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf" -ynh_restore_file --origin_path="/etc/systemd/system/$app-backend.service" +ynh_restore "/etc/systemd/system/$app-backend.service" systemctl enable $app-backend.service --quiet yunohost service add $app-backend --log="/var/log/$app/$app-backend.log" -ynh_restore_file --origin_path="/etc/systemd/system/$app-exporter.service" +ynh_restore "/etc/systemd/system/$app-exporter.service" systemctl enable $app-exporter.service --quiet yunohost service add $app-exporter --log="/var/log/$app/$app-exporter.log" @@ -74,16 +68,16 @@ yunohost service add $app-exporter --log="/var/log/$app/$app-exporter.log" #================================================= # RELOAD NGINX AND PHP-FPM OR THE APP SERVICE #================================================= -ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 +ynh_script_progression "Reloading NGINX web server and $app's service..." -ynh_systemd_action --service_name=$app-backend --action="start" --log_path="/var/log/$app/$app-backend.log" --line_match="welcome to penpot" +ynh_systemctl --service=$app-backend --action="start" --log_path="/var/log/$app/$app-backend.log" --wait_until="welcome to penpot" -ynh_systemd_action --service_name=$app-exporter --action="start" --log_path="/var/log/$app/$app-exporter.log" --line_match="redis connection established" +ynh_systemctl --service=$app-exporter --action="start" --log_path="/var/log/$app/$app-exporter.log" --wait_until="redis connection established" -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemctl --service=nginx --action=reload #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" --last +ynh_script_progression "Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index 03ed82e..99049b2 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,26 +1,16 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers -upgrade_type=$(ynh_check_app_version_changed) - -#================================================= -# STANDARD UPGRADE STEPS #================================================= #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_systemd_action --service_name=$app-backend --action="stop" -ynh_systemd_action --service_name=$app-exporter --action="stop" +ynh_systemctl --service=$app-backend --action="stop" +ynh_systemctl --service=$app-exporter --action="stop" #================================================= # "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD...) @@ -28,63 +18,63 @@ ynh_systemd_action --service_name=$app-exporter --action="stop" # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Installing dependencies..." --weight=10 +ynh_script_progression "Installing dependencies..." # Install Nodejs -ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version -ynh_use_nodejs +ynh_nodejs_install -if [ "$upgrade_type" == "UPGRADE_APP" ] +# FIXME: this is still supported but the recommendation is now to *always* re-setup the app sources wether or not the upstream sources changed +if ynh_app_upstream_version_changed then ynh_setup_source --dest_dir="$install_dir/jdk" --source_id="jdk" export JAVA_HOME=$install_dir/jdk - chown -R $app:www-data "$install_dir" + #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:www-data "$install_dir" tmp_dir=$(mktemp -d) pushd $tmp_dir curl -L -O https://github.com/clojure/brew-install/releases/latest/download/linux-install.sh chmod +x linux-install.sh - ynh_exec_warn_less ./linux-install.sh -p $install_dir/clojure + ynh_hide_warnings ./linux-install.sh -p $install_dir/clojure popd - ynh_secure_remove --file=$tmp_dir + ynh_safe_rm $tmp_dir ynh_setup_source --dest_dir="$install_dir/babashka" --source_id="babashka" export PATH=$JAVA_HOME/bin:$install_dir/clojure/bin:$install_dir/babashka:$PATH - ynh_script_progression --message="Upgrading source files..." + ynh_script_progression "Upgrading source files..." # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir/build" - chmod -R o-rwx "$install_dir" - chown -R $app:www-data "$install_dir" - - ynh_script_progression --message="Building frontend..." --weight=5 + #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir" + #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:www-data "$install_dir" + ynh_script_progression "Building frontend..." pushd $install_dir/build/frontend - ynh_exec_warn_less env $ynh_node_load_PATH COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack enable - ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack enable - ynh_exec_warn_less ynh_exec_as "$app" env $ynh_node_load_PATH COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack prepare --activate - ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_ENV=production COREPACK_ENABLE_DOWNLOAD_PROMPT=0 yarn install --immutable - - # ynh_exec_warn_less - ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH JAVA_HOME=$JAVA_HOME NODE_ENV=production clojure -J-Xms100M -J-Xmx800M -J-XX:+UseSerialGC -M:dev:shadow-cljs release main --config-merge "{:release-version \"${current_hash}\"}" + ynh_hide_warnings env node_load_PATH corepack enable + ynh_hide_warnings ynh_exec_as_app node_load_PATH corepack enable + ynh_hide_warnings ynh_exec_as_app node_load_PATH corepack prepare --activate + ynh_hide_warnings ynh_exec_as_app node_load_PATH NODE_ENV=production yarn install --immutable - ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_ENV=production yarn run compile + # ynh_hide_warnings - ynh_replace_string --match_string="%version%" --replace_string="$version" --target_file="$install_dir/build/frontend/resources/public/index.html" - ynh_replace_string --match_string="%buildDate%" --replace_string="$build_date" --target_file="$install_dir/build/frontend/resources/public/index.html" + ynh_hide_warnings ynh_exec_as_app PATH=$PATH JAVA_HOME=$JAVA_HOME NODE_ENV=production clojure -J-Xms100M -J-Xmx800M -J-XX:+UseSerialGC -M:dev:shadow-cljs release main --config-merge "{:release-version \"${current_hash}\"}" + + ynh_hide_warnings ynh_exec_as_app node_load_PATH NODE_ENV=production yarn run compile + + ynh_replace --match="%version%" --replace="$version" --file="$install_dir/build/frontend/resources/public/index.html" + ynh_replace --match="%buildDate%" --replace="$build_date" --file="$install_dir/build/frontend/resources/public/index.html" popd - ynh_secure_remove --file=$install_dir/frontend + ynh_safe_rm $install_dir/frontend mkdir -p $install_dir/frontend mv $install_dir/build/frontend/resources/public/* $install_dir/frontend chown -R $app:www-data $install_dir/frontend chmod -R 755 $install_dir/frontend - ynh_script_progression --message="Building backend..." --weight=5 + ynh_script_progression "Building backend..." pushd $install_dir/build/backend mkdir -p target/classes; @@ -93,7 +83,7 @@ then cp ../CHANGES.md target/classes/changelog.md; chown -R $app:$app target - ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH JAVA_HOME=$JAVA_HOME clojure -T:build jar; + ynh_hide_warnings ynh_exec_as_app PATH=$PATH JAVA_HOME=$JAVA_HOME clojure -T:build jar; mv target/penpot.jar target/dist/penpot.jar cp resources/log4j2.xml target/dist/log4j2.xml cp scripts/run.template.sh target/dist/run.sh @@ -105,104 +95,104 @@ then cp -r builtin-templates target/dist/ popd - ynh_secure_remove --file=$install_dir/backend + ynh_safe_rm $install_dir/backend mkdir -p $install_dir/backend mv $install_dir/build/backend/target/dist/* $install_dir/backend chown -R $app:$app $install_dir/backend chmod -R 700 $install_dir/backend - ynh_script_progression --message="Building exporter..." --weight=5 + ynh_script_progression "Building exporter..." pushd $install_dir/build/exporter - ynh_exec_warn_less ynh_exec_as "$app" env $ynh_node_load_PATH corepack prepare --activate - ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install --immutable - ynh_secure_remove --file="target" - ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH JAVA_HOME=$JAVA_HOME NODE_ENV=production clojure -M:dev:shadow-cljs release main + ynh_hide_warnings ynh_exec_as_app node_load_PATH corepack prepare --activate + ynh_hide_warnings ynh_exec_as_app node_load_PATH yarn install --immutable + ynh_safe_rm "target" + ynh_hide_warnings ynh_exec_as_app PATH=$PATH JAVA_HOME=$JAVA_HOME NODE_ENV=production clojure -M:dev:shadow-cljs release main cp yarn.lock target/ cp package.json target/ - - ynh_replace_string --match_string="%version%" --replace_string="$version" --target_file="$install_dir/build/exporter/target/app.js" + + ynh_replace --match="%version%" --replace="$version" --file="$install_dir/build/exporter/target/app.js" popd - ynh_secure_remove --file=$install_dir/exporter + ynh_safe_rm $install_dir/exporter mkdir -p $install_dir/exporter mv $install_dir/build/exporter/target/* $install_dir/exporter cp $install_dir/build/.yarnrc.yml $install_dir/exporter chown -R $app:$app $install_dir/exporter chmod -R 700 $install_dir/exporter - ynh_secure_remove --file=$install_dir/.cache + ynh_safe_rm $install_dir/.cache pushd $install_dir/exporter - ynh_exec_warn_less ynh_exec_as "$app" env $ynh_node_load_PATH corepack prepare --activate - ynh_exec_as $app env $ynh_node_load_PATH NODE_ENV=production yarn install --immutable - ynh_exec_as $app env $ynh_node_load_PATH NODE_ENV=production yarn run playwright install chromium + ynh_hide_warnings ynh_exec_as_app node_load_PATH corepack prepare --activate + ynh_exec_as_app node_load_PATH NODE_ENV=production yarn install --immutable + ynh_exec_as_app node_load_PATH NODE_ENV=production yarn run playwright install chromium popd - ynh_script_progression --message="Cleaning up..." --weight=1 + ynh_script_progression "Cleaning up..." - ynh_secure_remove --file=$install_dir/.npm - ynh_secure_remove --file=$install_dir/.yarn - ynh_secure_remove --file=$install_dir/build - ynh_secure_remove --file=$install_dir/.m2 - ynh_secure_remove --file=$install_dir/.clojure - ynh_secure_remove --file=$install_dir/clojure - ynh_secure_remove --file=$install_dir/babashka - ynh_secure_remove --file=$install_dir/.cache/ms-playwright/firefox-* - ynh_secure_remove --file=$install_dir/.cache/ms-playwright/webkit-* - ynh_secure_remove --file=$install_dir/.cache/yarn - ynh_secure_remove --file=$install_dir/.cache/node + ynh_safe_rm $install_dir/.npm + ynh_safe_rm $install_dir/.yarn + ynh_safe_rm $install_dir/build + ynh_safe_rm $install_dir/.m2 + ynh_safe_rm $install_dir/.clojure + ynh_safe_rm $install_dir/clojure + ynh_safe_rm $install_dir/babashka + ynh_safe_rm $install_dir/.cache/ms-playwright/firefox-* + ynh_safe_rm $install_dir/.cache/ms-playwright/webkit-* + ynh_safe_rm $install_dir/.cache/yarn + ynh_safe_rm $install_dir/.cache/node fi #================================================= # REAPPLY SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Upgrading system configurations related to $app..." +ynh_script_progression "Upgrading system configurations related to $app..." -ynh_add_nginx_config +ynh_config_add_nginx -ynh_add_systemd_config --template="backend.service" --service="$app-backend" +ynh_config_add_systemd --template="backend.service" --service="$app-backend" yunohost service add $app-backend --log="/var/log/$app/$app-backend.log" -ynh_add_systemd_config --template="exporter.service" --service="$app-exporter" +ynh_config_add_systemd --template="exporter.service" --service="$app-exporter" yunohost service add $app-exporter --log="/var/log/$app/$app-exporter.log" -ynh_use_logrotate --non-append --logfile="/var/log/$app/$app-backend.log" -ynh_use_logrotate --logfile="/var/log/$app/$app-exporter.log" +ynh_config_add_logrotate "/var/log/$app/$app-backend.log" +ynh_config_add_logrotate "/var/log/$app/$app-exporter.log" #================================================= # RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...) #================================================= # UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Updating database configuration..." -ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";" --database=$db_name +ynh_script_progression "Updating database configuration..." +ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";" -ynh_script_progression --message="Updating a configuration file..." +ynh_script_progression "Updating configuration..." -ynh_add_config --template="config.js" --destination="$install_dir/frontend/js/config.js" -chmod 755 "$install_dir/frontend/js/config.js" -chown $app:www-data "$install_dir/frontend/js/config.js" +ynh_config_add --template="config.js" --destination="$install_dir/frontend/js/config.js" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 755 "$install_dir/frontend/js/config.js" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:www-data "$install_dir/frontend/js/config.js" -ynh_add_config --template="environ" --destination="$install_dir/backend/environ" -chmod 400 "$install_dir/backend/environ" -chown $app:$app "$install_dir/backend/environ" +ynh_config_add --template="environ" --destination="$install_dir/backend/environ" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/backend/environ" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:$app "$install_dir/backend/environ" -ynh_add_config --template="exporter.env" --destination="$install_dir/exporter/.env" -chmod 400 "$install_dir/exporter/.env" -chown $app:$app "$install_dir/exporter/.env" +ynh_config_add --template="exporter.env" --destination="$install_dir/exporter/.env" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/exporter/.env" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:$app "$install_dir/exporter/.env" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name=$app-backend --action="start" --log_path="/var/log/$app/$app-backend.log" --line_match="welcome to penpot" +ynh_systemctl --service=$app-backend --action="start" --log_path="/var/log/$app/$app-backend.log" --wait_until="welcome to penpot" -ynh_systemd_action --service_name=$app-exporter --action="start" --log_path="/var/log/$app/$app-exporter.log" --line_match="redis connection established" +ynh_systemctl --service=$app-exporter --action="start" --log_path="/var/log/$app/$app-exporter.log" --wait_until="redis connection established" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last +ynh_script_progression "Upgrade of $app completed"