#!/bin/bash #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # STOP SYSTEMD SERVICE #================================================= ynh_script_progression "Stopping $app's systemd service..." ynh_systemctl --service=$app --action="stop" #================================================= # MODIFY URL IN NGINX CONF #================================================= ynh_script_progression "Updating NGINX web server configuration..." ynh_config_change_url_nginx #================================================= # UPDATE A CONFIG FILE #================================================= ynh_script_progression "Updating a config file..." discourse_config_file="$install_dir/config/discourse.conf" old_relative_url_root="${old_path%/}" new_relative_url_root="${new_path%/}" # Configure hostname ynh_replace --match="hostname = .*" --replace="hostname = \"$new_domain\"" --file="$discourse_config_file" ynh_replace --match="relative_url_root = .*" --replace="relative_url_root = ${new_path%/}" --file="$discourse_config_file" ynh_replace --match="smtp_domain = .*" --replace="smtp_domain = $new_domain" --file="$discourse_config_file" # Calculate and store the config file checksum ynh_store_file_checksum "$discourse_config_file" # Change URL setting ynh_psql_db_shell \ <<< "UPDATE site_settings SET value = replace(value, '$old_relative_url_root/images/', '$new_relative_url_root/images/'); UPDATE site_settings SET value = '${new_path}' WHERE name='long_polling_base_url';" # Remap URLs in forum posts ynh_exec_as_app --login RAILS_ENV=production bin/bundle exec script/discourse remap "$old_relative_url_root/uploads" "$new_relative_url_root/uploads" <<< "YES # " # Regenerate assets ynh_hide_warnings ynh_exec_as_app --login RAILS_ENV=production bin/rake assets:precompile # Regenerate all forum posts ynh_hide_warnings ynh_exec_as_app --login RAILS_ENV=production bin/rake posts:rebake #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression "Starting $app's systemd service..." # Start a systemd service ynh_systemctl --service="$app" --action="start" --log_path="$install_dir/log/unicorn.stderr.log" --wait_until="INFO -- : worker=$((unicorn_workers-1)) ready" #================================================= # END OF SCRIPT #================================================= ynh_script_progression "Change of URL completed for $app"