diff --git a/README.md b/README.md index e935771..b017685 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ It shall NOT be edited by hand. # Discourse for YunoHost -[![Integration level](https://dash.yunohost.org/integration/discourse.svg)](https://dash.yunohost.org/appci/app/discourse) ![](https://ci-apps.yunohost.org/ci/badges/discourse.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/discourse.maintain.svg) +[![Integration level](https://dash.yunohost.org/integration/discourse.svg)](https://dash.yunohost.org/appci/app/discourse) ![Working status](https://ci-apps.yunohost.org/ci/badges/discourse.status.svg) ![Maintenance status](https://ci-apps.yunohost.org/ci/badges/discourse.maintain.svg) [![Install Discourse with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=discourse) *[Lire ce readme en français.](./README_fr.md)* @@ -21,15 +21,13 @@ Discourse is the 100% open source discussion platform built for the next decade - discussion forum - long-form chat room - - **Shipped version:** 2.9.0~ynh1 **Demo:** https://try.discourse.org ## Screenshots -![](./doc/screenshots/screenshot.png) +![Screenshot of Discourse](./doc/screenshots/screenshot.png) ## Disclaimers / important information @@ -112,20 +110,21 @@ systemctl restart discourse ## Documentation and resources -* Official app website: http://Discourse.org -* Upstream app code repository: https://github.com/discourse/discourse -* YunoHost documentation for this app: https://yunohost.org/app_discourse -* Report a bug: https://github.com/YunoHost-Apps/discourse_ynh/issues +* Official app website: +* Upstream app code repository: +* YunoHost documentation for this app: +* Report a bug: ## Developer info Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/discourse_ynh/tree/testing). To try the testing branch, please proceed like that. -``` + +``` bash sudo yunohost app install https://github.com/YunoHost-Apps/discourse_ynh/tree/testing --debug or sudo yunohost app upgrade discourse -u https://github.com/YunoHost-Apps/discourse_ynh/tree/testing --debug ``` -**More info regarding app packaging:** https://yunohost.org/packaging_apps \ No newline at end of file +**More info regarding app packaging:** diff --git a/README_fr.md b/README_fr.md index cc20add..ab2b1d1 100644 --- a/README_fr.md +++ b/README_fr.md @@ -1,10 +1,14 @@ + + # Discourse pour YunoHost -[![Niveau d'intégration](https://dash.yunohost.org/integration/discourse.svg)](https://dash.yunohost.org/appci/app/discourse) ![](https://ci-apps.yunohost.org/ci/badges/discourse.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/discourse.maintain.svg) +[![Niveau d'intégration](https://dash.yunohost.org/integration/discourse.svg)](https://dash.yunohost.org/appci/app/discourse) ![Statut du fonctionnement](https://ci-apps.yunohost.org/ci/badges/discourse.status.svg) ![Statut de maintenance](https://ci-apps.yunohost.org/ci/badges/discourse.maintain.svg) [![Installer Discourse avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=discourse) *[Read this readme in english.](./README.md)* -*[Lire ce readme en français.](./README_fr.md)* > *Ce package vous permet d'installer Discourse rapidement et simplement sur un serveur YunoHost. Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour savoir comment l'installer et en profiter.* @@ -17,14 +21,13 @@ Discourse est la plate-forme de discussion 100% open source construite pour la p - forum de discussion - salle de discussion - **Version incluse :** 2.9.0~ynh1 **Démo :** https://try.discourse.org ## Captures d'écran -![](./doc/screenshots/screenshot.png) +![Capture d'écran de Discourse](./doc/screenshots/screenshot.png) ## Avertissements / informations importantes @@ -126,20 +129,21 @@ systemctl restart discourse ## Documentations et ressources -* Site officiel de l'app : http://Discourse.org -* Dépôt de code officiel de l'app : https://github.com/discourse/discourse -* Documentation YunoHost pour cette app : https://yunohost.org/app_discourse -* Signaler un bug : https://github.com/YunoHost-Apps/discourse_ynh/issues +* Site officiel de l'app : +* Dépôt de code officiel de l'app : +* Documentation YunoHost pour cette app : +* Signaler un bug : ## Informations pour les développeurs Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/discourse_ynh/tree/testing). Pour essayer la branche testing, procédez comme suit. -``` + +``` bash sudo yunohost app install https://github.com/YunoHost-Apps/discourse_ynh/tree/testing --debug ou sudo yunohost app upgrade discourse -u https://github.com/YunoHost-Apps/discourse_ynh/tree/testing --debug ``` -**Plus d'infos sur le packaging d'applications :** https://yunohost.org/packaging_apps \ No newline at end of file +**Plus d'infos sur le packaging d'applications :** diff --git a/check_process b/check_process index 303ed57..54a01b8 100644 --- a/check_process +++ b/check_process @@ -2,8 +2,8 @@ ; Manifest domain="domain.tld" path="/path" - admin="john" is_public=1 + admin="john" ; Checks pkg_linter=1 setup_sub_dir=1 diff --git a/conf/app.src b/conf/app.src index 088a75a..ca1d52e 100644 --- a/conf/app.src +++ b/conf/app.src @@ -3,3 +3,5 @@ SOURCE_SUM=d6672744e1e2f47afe3b3a23ca0eeb1263e799692b9091cc2287e50b6d97c64e SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true +SOURCE_FILENAME= +SOURCE_EXTRACT=true diff --git a/conf/discourse_defaults.conf b/conf/discourse_defaults.conf index 110f9c8..a6a5abe 100644 --- a/conf/discourse_defaults.conf +++ b/conf/discourse_defaults.conf @@ -44,7 +44,7 @@ db_backup_port = 5432 db_name = __DB_NAME__ # username accessing database -db_username = __DB_NAME__ +db_username = __DB_USER__ # password used to access the db db_password = __DB_PWD__ diff --git a/conf/nginx.conf b/conf/nginx.conf index d9b5922..5c95f86 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -29,7 +29,7 @@ #sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; location __PATH__/ { - alias __FINALPATH__/public/; + alias __FINALPATH__/public/ ; proxy_hide_header ETag; # auth_basic on; @@ -199,7 +199,7 @@ location __PATH__/downloads/ { internal; - alias __FINALPATH__/public/; + alias __FINALPATH__/public/ ; } location @__NAME__ { diff --git a/conf/systemd.service b/conf/systemd.service index 3e35b20..6af31d1 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -14,7 +14,8 @@ Environment=RAILS_ENV=production Environment=UNICORN_SIDEKIQS=1 Environment=LD_PRELOAD=__LIBJEMALLOC__ Environment=UNICORN_LISTENER=__FINALPATH__/tmp/sockets/unicorn.sock -ExecStart=__RBENV_ROOT__/shims/bundle exec unicorn --config config/unicorn.conf.rb -E production +Environment="__YNH_RUBY_LOAD_PATH__" +ExecStart=__FINALPATH__/bin/bundle exec unicorn --config config/unicorn.conf.rb -E production Restart=always RestartSec=10 @@ -25,7 +26,7 @@ RestartSec=10 NoNewPrivileges=yes PrivateTmp=yes PrivateDevices=yes -RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 +RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 AF_NETLINK RestrictNamespaces=yes RestrictRealtime=yes DevicePolicy=closed diff --git a/manifest.json b/manifest.json index 931aaab..0b12605 100644 --- a/manifest.json +++ b/manifest.json @@ -28,7 +28,7 @@ "nginx" ], "arguments": { - "install" : [ + "install": [ { "name": "domain", "type": "domain" @@ -39,14 +39,14 @@ "example": "/forum", "default": "/forum" }, - { - "name": "admin", - "type": "user" - }, { "name": "is_public", "type": "boolean", "default": true + }, + { + "name": "admin", + "type": "user" } ] } diff --git a/scripts/_common.sh b/scripts/_common.sh index f5580ab..d96fd12 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,8 +5,9 @@ #================================================= pkg_dependencies="g++ libjemalloc1|libjemalloc2 libjemalloc-dev zlib1g-dev libreadline-dev libpq-dev libssl-dev libyaml-dev libcurl4-dev libapr1-dev libxslt1-dev libxml2-dev vim imagemagick postgresql postgresql-server-dev-all postgresql-contrib optipng jhead jpegoptim gifsicle brotli" +build_pkg_dependencies="" -RUBY_VERSION="2.7.2" +ruby_version="2.7.2" #================================================= # PERSONAL HELPERS @@ -163,6 +164,12 @@ rbenv_install_dir="/opt/rbenv" ruby_version_path="$rbenv_install_dir/versions" # RBENV_ROOT is the directory of rbenv, it needs to be loaded as a environment variable. export RBENV_ROOT="$rbenv_install_dir" +export rbenv_root="$rbenv_install_dir" + +ruby_dependencies="" +build_ruby_dependencies="libjemalloc-dev curl build-essential libreadline-dev zlib1g-dev libsqlite3-dev libssl-dev libxml2-dev libxslt-dev autoconf automake bison libtool" +pkg_dependencies="$pkg_dependencies $ruby_dependencies" +build_pkg_dependencies="$build_pkg_dependencies $build_ruby_dependencies" # Load the version of Ruby for an app, and set variables. # @@ -187,9 +194,9 @@ export RBENV_ROOT="$rbenv_install_dir" # Finally, to start a Ruby service with the correct version, 2 solutions # Either the app is dependent of Ruby or gem, but does not called it directly. # In such situation, you need to load PATH -# `Environment="__YNH_RUBY_LOAD_ENV_PATH__"` +# `Environment="__YNH_RUBY_LOAD_PATH__"` # `ExecStart=__FINALPATH__/my_app` -# You will replace __YNH_RUBY_LOAD_ENV_PATH__ with $ynh_ruby_load_path +# You will replace __YNH_RUBY_LOAD_PATH__ with $ynh_ruby_load_path # # Or Ruby start the app directly, then you don't need to load the PATH variable # `ExecStart=__YNH_RUBY__ my_app run` @@ -201,7 +208,7 @@ export RBENV_ROOT="$rbenv_install_dir" # # usage: ynh_use_ruby # -# Requires YunoHost version 2.7.12 or higher. +# Requires YunoHost version 3.2.2 or higher. ynh_use_ruby () { ruby_version=$(ynh_app_setting_get --app=$app --key=ruby_version) @@ -246,7 +253,7 @@ ynh_use_ruby () { # usage: ynh_install_ruby --ruby_version=ruby_version # | arg: -v, --ruby_version= - Version of ruby to install. # -# Requires YunoHost version 2.7.12 or higher. +# Requires YunoHost version 3.2.2 or higher. ynh_install_ruby () { # Declare an array to define the options of this helper. local legacy_args=v diff --git a/scripts/backup b/scripts/backup index 1f4c370..37a5e95 100644 --- a/scripts/backup +++ b/scripts/backup @@ -15,7 +15,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ynh_clean_check_starting + true } # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -30,7 +30,6 @@ 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) -unicorn_workers=$(ynh_app_setting_get --app=$app --key=unicorn_workers) #================================================= # DECLARE DATA AND CONF FILES TO BACKUP diff --git a/scripts/change_url b/scripts/change_url index 0c3c61e..8082d74 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -43,6 +43,7 @@ ynh_script_progression --message="Backing up the app before changing its URL (ma # 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" @@ -114,6 +115,9 @@ fi #================================================= # SPECIFIC MODIFICATIONS #================================================= +# UPDATE A CONFIG FILE +#================================================= +ynh_script_progression --message="Updating a config file..." discourse_config_file="$final_path/config/discourse.conf" # Configure hostname @@ -133,13 +137,11 @@ ynh_use_ruby exec_login_as $app RAILS_ENV=production bin/bundle exec script/discourse remap ${old_path%/}/uploads ${new_path%/}/uploads <<< "YES # " -rake_exec="exec_login_as $app RAILS_ENV=production bin/rake" - # Regenerate assets -ynh_exec_warn_less $rake_exec assets:precompile +ynh_exec_warn_less exec_login_as $app RAILS_ENV=production bin/rake assets:precompile # Regenerate all forum posts -ynh_exec_warn_less $rake_exec posts:rebake +ynh_exec_warn_less exec_login_as $app RAILS_ENV=production bin/rake posts:rebake #================================================= # GENERIC FINALISATION diff --git a/scripts/install b/scripts/install index 3dcb2f0..ec8382d 100644 --- a/scripts/install +++ b/scripts/install @@ -14,7 +14,6 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - # Clean remainings not handled by remove script ynh_clean_check_starting } # Exit if an error occurs during the execution of the script @@ -26,8 +25,8 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH -admin=$YNH_APP_ARG_ADMIN is_public=$YNH_APP_ARG_IS_PUBLIC +admin=$YNH_APP_ARG_ADMIN email=$(ynh_user_get_info --username="$admin" --key=mail) app=$YNH_APP_INSTANCE_NAME @@ -67,10 +66,8 @@ ynh_app_setting_set --app=$app --key=email --value=$email #================================================= ynh_script_progression --message="Installing dependencies..." -ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies -ynh_exec_warn_less ynh_install_ruby --ruby_version=$RUBY_VERSION - -# Install Yarn +ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies $build_pkg_dependencies +ynh_exec_warn_less ynh_install_ruby --ruby_version=$ruby_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" #================================================= @@ -94,6 +91,7 @@ ynh_psql_setup_db --db_user=$db_user --db_name=$db_name # Set extensions ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS hstore;" --database=$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 @@ -138,9 +136,9 @@ ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # SPECIFIC SETUP #================================================= -# CONFIGURE DISCOURSE +# ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Configuring Discourse..." +ynh_script_progression --message="Adding a configuration file..." # Configure redis redis_db=$(ynh_redis_get_free_db) @@ -165,11 +163,6 @@ ynh_script_progression --message="Setting up Unicorn..." secret="$(ynh_string_random)" ynh_add_config --template="../conf/secrets.yml" --destination="$final_path/config/secrets.yml" -# Set permissions to app files -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" - pushd "$final_path" ynh_use_ruby # Install bundler, a gems installer @@ -203,9 +196,11 @@ fi #================================================= ynh_script_progression --message="Preparing the database..." -rake_exec="exec_login_as $app RAILS_ENV=production bin/rake" -ynh_exec_warn_less $rake_exec db:migrate -ynh_exec_warn_less $rake_exec assets:precompile +ynh_exec_warn_less exec_login_as $app RAILS_ENV=production bin/rake db:migrate +ynh_exec_warn_less exec_login_as $app RAILS_ENV=production bin/rake assets:precompile + +ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies +ynh_package_autoremove #================================================= # POPULATE THE DATABASE @@ -234,7 +229,7 @@ ynh_script_progression --message="Creating Discourse admin user..." # Create a random password admin_pwd=$(ynh_string_random) -$rake_exec admin:create <<< "$email +exec_login_as $app RAILS_ENV=production bin/rake admin:create <<< "$email $admin_pwd $admin_pwd y @@ -248,7 +243,7 @@ ynh_script_progression --message="Configuring plugins..." # Patch ldap-auth plugin dependency (omniauth-ldap) to fix it when using domain subfolder # (Can only do that now because we are patching dependencies which have just been downloaded) # Patch applied: https://github.com/omniauth/omniauth-ldap/pull/16 -(cd $final_path/plugins/discourse-ldap-auth/gems/${RUBY_VERSION}/gems/omniauth-ldap*/ +(cd $final_path/plugins/discourse-ldap-auth/gems/${ruby_version}/gems/omniauth-ldap*/ patch -p1 < $YNH_CWD/../conf/ldap-auth-fix-subfolder.patch) #================================================= @@ -256,8 +251,6 @@ patch -p1 < $YNH_CWD/../conf/ldap-auth-fix-subfolder.patch) #================================================= ynh_script_progression --message="Configuring a systemd service..." -ynh_replace_string --match_string="__RBENV_ROOT__" --replace_string="$RBENV_ROOT" --target_file="../conf/systemd.service" - # We assume for the moment that ARM devices are only dual core, so # we restrict the number of workers to 2 (the default is 3) if [ -n "$(uname -m | grep arm)" ] ; then @@ -268,9 +261,7 @@ else unicorn_workers=3 fi ynh_app_setting_set --app=$app --key=unicorn_workers --value=$unicorn_workers - -ynh_replace_string --match_string="__ADDITIONAL_ENV__" --replace_string="$additional_env" --target_file="../conf/systemd.service" -ynh_replace_string --match_string="__LIBJEMALLOC__" --replace_string="$(ldconfig -p | grep libjemalloc | awk 'END {print $NF}')" --target_file="../conf/systemd.service" +libjemalloc="$(ldconfig -p | grep libjemalloc | awk 'END {print $NF}')" ynh_add_systemd_config #================================================= diff --git a/scripts/remove b/scripts/remove index 9f8a08c..a604496 100644 --- a/scripts/remove +++ b/scripts/remove @@ -43,6 +43,14 @@ 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 THE POSTGRESQL DATABASE #================================================= @@ -51,13 +59,6 @@ ynh_script_progression --message="Removing the PostgreSQL database..." # Remove a database if it exists, along with the associated user ynh_psql_remove_db --db_user="$db_user" --db_name="$db_name" -#================================================= -# REMOVE RUBY -#================================================= -ynh_script_progression --message="Removing Ruby..." - -ynh_remove_ruby - #================================================= # REMOVE THE REDIS DATABASE #================================================= @@ -65,14 +66,6 @@ ynh_script_progression --message="Removing the redis database..." ynh_redis_remove_db "$redis_db" -#================================================= -# REMOVE DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies..." - -# Remove metapackage and its dependencies -ynh_remove_app_dependencies - #================================================= # REMOVE APP MAIN DIR #================================================= @@ -90,12 +83,13 @@ ynh_script_progression --message="Removing NGINX web server configuration..." ynh_remove_nginx_config #================================================= -# REMOVE LOGROTATE CONFIGURATION +# REMOVE DEPENDENCIES #================================================= -ynh_script_progression --message="Removing logrotate configuration..." +ynh_script_progression --message="Removing dependencies..." -# Remove the app-specific logrotate config -ynh_remove_logrotate +# Remove metapackage and its dependencies +ynh_remove_ruby +ynh_remove_app_dependencies #================================================= # GENERIC FINALIZATION diff --git a/scripts/restore b/scripts/restore index bbb474f..20d5d23 100644 --- a/scripts/restore +++ b/scripts/restore @@ -39,7 +39,8 @@ db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) #================================================= ynh_script_progression --message="Validating restoration parameters..." -test ! -d $final_path || ynh_die --message="There is already a directory: $final_path " +test ! -d $final_path \ + || ynh_die --message="There is already a directory: $final_path " if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then : @@ -84,8 +85,20 @@ chown -R $app:www-data "$final_path" ynh_script_progression --message="Reinstalling dependencies..." # Define and install dependencies -ynh_install_app_dependencies $pkg_dependencies 2>/dev/null -ynh_install_ruby --ruby_version=$RUBY_VERSION 2>/dev/null +ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies $build_pkg_dependencies +ynh_exec_warn_less ynh_install_ruby --ruby_version=$ruby_version + +#================================================= +# RESTORE THE POSTGRESQL DATABASE +#================================================= +ynh_script_progression --message="Restoring the PostgreSQL database..." + +ynh_psql_test_if_first_run +db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) +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 hstore;" --database=$db_name +ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name +ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name" #================================================= # REINSTALL BUNDLE GEM @@ -97,18 +110,8 @@ pushd "$final_path" ynh_gem install bundler popd -#================================================= -# RESTORE THE POSTGRESQL DATABASE -#================================================= -ynh_script_progression --message="Restoring the PostgreSQL database..." - -ynh_psql_test_if_first_run -ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd -# Set extensions -ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS hstore;" --database=$db_name -ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name -# Restore dump -ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name" +ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies +ynh_package_autoremove #================================================= # RESTORE SYSTEMD @@ -118,6 +121,13 @@ ynh_script_progression --message="Restoring the systemd configuration..." 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..." + +ynh_restore_file --origin_path="/etc/logrotate.d/$app" + #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= @@ -139,13 +149,6 @@ ynh_app_setting_set --app=$app --key=unicorn_workers --value=$unicorn_workers ynh_systemd_action --service_name=$app --action="start" --log_path="$final_path/log/unicorn.stderr.log" --line_match="INFO -- : worker=$((unicorn_workers-1)) ready" sleep 60 -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the logrotate configuration..." - -ynh_restore_file --origin_path="/etc/logrotate.d/$app" - #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 1af1721..1ffabd2 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -21,6 +21,7 @@ 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 db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) redis_db=$(ynh_app_setting_get --app=$app --key=redis_db) unicorn_workers=$(ynh_app_setting_get --app=$app --key=unicorn_workers) @@ -40,32 +41,6 @@ ynh_script_progression --message="Checking version..." upgrade_type=$(ynh_check_app_version_changed) -#================================================= -# ENSURE DOWNWARD COMPATIBILITY -#================================================= -ynh_script_progression --message="Ensuring downward compatibility..." - -# If unicorn_workers doesn't exist, create it -if [ -z "$unicorn_workers" ] -then - # We assume for the moment that ARM devices are only dual core, so - # we restrict the number of workers to 2 (the default is 3) - if [ -n "$(uname -m | grep arm)" ] - then - unicorn_workers=2 - else - unicorn_workers=3 - fi - ynh_app_setting_set --app=$app --key=unicorn_workers --value=$unicorn_workers -fi - -# Cleaning legacy permissions -if ynh_legacy_permissions_exists; then - ynh_legacy_permissions_delete_all - - ynh_app_setting_delete --app=$app --key=is_public -fi - #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -97,6 +72,32 @@ ynh_script_progression --message="Stopping a systemd service..." ynh_systemd_action --service_name=$app --action="stop" --log_path="$final_path/log/unicorn.stderr.log" +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= +ynh_script_progression --message="Ensuring downward compatibility..." + +# If unicorn_workers doesn't exist, create it +if [ -z "$unicorn_workers" ] +then + # We assume for the moment that ARM devices are only dual core, so + # we restrict the number of workers to 2 (the default is 3) + if [ -n "$(uname -m | grep arm)" ] + then + unicorn_workers=2 + else + unicorn_workers=3 + fi + ynh_app_setting_set --app=$app --key=unicorn_workers --value=$unicorn_workers +fi + +# Cleaning legacy permissions +if ynh_legacy_permissions_exists; then + ynh_legacy_permissions_delete_all + + ynh_app_setting_delete --app=$app --key=is_public +fi + #================================================= # CREATE DEDICATED USER #================================================= @@ -191,19 +192,19 @@ ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= ynh_script_progression --message="Upgrading dependencies..." -ynh_install_app_dependencies $pkg_dependencies 2>/dev/null -ynh_install_ruby --ruby_version=$RUBY_VERSION 2>/dev/null +ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies $build_pkg_dependencies +ynh_exec_warn_less ynh_install_ruby --ruby_version=$ruby_version ynh_use_ruby #================================================= # SPECIFIC UPGRADE #================================================= -# CONFIGURE DISCOURSE +# UPDATE A CONFIG FILE #================================================= if [ "$upgrade_type" == "UPGRADE_APP" ] then - ynh_script_progression --message="Configuring Discourse..." + ynh_script_progression --message="Updating a config file..." ynh_add_config --template="../conf/discourse_defaults.conf" --destination="$final_path/config/discourse.conf" chmod 400 "$final_path/config/discourse.conf" @@ -272,11 +273,13 @@ if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_script_progression --message="Preparing the database..." - rake_exec="exec_login_as $app RAILS_ENV=production bin/rake" - ynh_exec_warn_less $rake_exec db:migrate - ynh_exec_warn_less $rake_exec assets:precompile + ynh_exec_warn_less exec_login_as $app RAILS_ENV=production bin/rake db:migrate + ynh_exec_warn_less exec_login_as $app RAILS_ENV=production bin/rake assets:precompile fi +ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies +ynh_package_autoremove + #================================================= # CONFIGURE PLUGINS #================================================= @@ -289,7 +292,7 @@ then # (Can only do that now because we are patching dependencies which have just been downloaded) # Patch applied: https://github.com/omniauth/omniauth-ldap/pull/16 ( - cd $final_path/plugins/discourse-ldap-auth/gems/${RUBY_VERSION}/gems/omniauth-ldap*/ + cd $final_path/plugins/discourse-ldap-auth/gems/${ruby_version}/gems/omniauth-ldap*/ patch -p1 < $YNH_CWD/../conf/ldap-auth-fix-subfolder.patch ) fi @@ -302,11 +305,8 @@ if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_script_progression --message="Configuring a systemd service..." - ynh_replace_string --match_string="__RBENV_ROOT__" --replace_string="$RBENV_ROOT" --target_file="../conf/systemd.service" - additional_env="UNICORN_WORKERS=$unicorn_workers" - ynh_replace_string --match_string="__ADDITIONAL_ENV__" --replace_string="$additional_env" --target_file="../conf/systemd.service" - ynh_replace_string --match_string="__LIBJEMALLOC__" --replace_string="$(ldconfig -p | grep libjemalloc | awk 'END {print $NF}')" --target_file="../conf/systemd.service" + libjemalloc="$(ldconfig -p | grep libjemalloc | awk 'END {print $NF}')" ynh_add_systemd_config fi