From e1bc8091cbfba54d2b0fe6acbef20bac4f5cf739 Mon Sep 17 00:00:00 2001 From: Jimmy Monin Date: Sat, 7 Apr 2018 11:56:54 +0200 Subject: [PATCH] Minor refactoring and fixes --- scripts/_common.sh | 13 ++++++----- scripts/install | 58 +++++++++++++++++++++++----------------------- 2 files changed, 36 insertions(+), 35 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index f545a42..7f92068 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -244,7 +244,12 @@ ynh_delete_file_checksum () { ynh_app_setting_delete $app $checksum_setting_name } -#!/bin/bash + +ynh_clean_check_starting_systemd () { + # Stop the execution of tail. + kill -s 15 $pid_tail 2>&1 + ynh_secure_remove "$templog" 2>&1 +} # Start or restart a service and follow its booting # @@ -258,11 +263,7 @@ ynh_check_starting_systemd () { local service_name="${2:-$app}" local timeout=${3:-300} - ynh_clean_check_starting_systemd () { - # Stop the execution of tail. - kill -s 15 $pid_tail 2>&1 - ynh_secure_remove "$templog" 2>&1 - } + echo "Starting of $service_name" >&2 systemctl stop $service_name diff --git a/scripts/install b/scripts/install index 251b8e6..acbed4b 100644 --- a/scripts/install +++ b/scripts/install @@ -71,7 +71,7 @@ ynh_install_app_dependencies "$pkg_dependencies" db_name=$(ynh_sanitize_dbid $app) db_pwd=$(ynh_string_random) ynh_app_setting_set $app db_name $db_name -ynh_app_setting_set $app psqlpwd $db_pwd +ynh_app_setting_set $app db_pwd $db_pwd ynh_psql_test_if_first_run ynh_psql_create_db $db_name $db_name $db_pwd # Set extensions @@ -95,8 +95,6 @@ ynh_setup_source "$final_path/plugins/discourse-ldap-auth" ldap-auth # Reference: https://meta.discourse.org/t/subfolder-support-with-docker/30507?u=falco&source_topic_id=54191 if [ "$path_url" != "/" ] ; then - # ynh_replace_string 'proxy_pass http://unix:__FINALPATH__/tmp/sockets/puma.sock;' 'rewrite ^/(.*)$ __PATH__/$1 break; proxy_pass http://unix:__FINALPATH__/tmp/sockets/puma.sock;' ../conf/nginx.conf - # ynh_replace_string 'etag off;' 'etag off; location __PATH__ { rewrite ^__PATH__/?(.*)$ /$1; }' ../conf/nginx.conf ynh_replace_string '$proxy_add_x_forwarded_for' '$http_your_original_ip_header' ../conf/nginx.conf fi @@ -119,42 +117,44 @@ ynh_system_user_create $app "$final_path" #================================================= # Configure database -cp $final_path/config/discourse_defaults.conf $final_path/config/discourse.conf -#ynh_replace_string "db_host =" "db_host = localhost" "$final_path/config/discourse.conf" -ynh_replace_string "db_name = discourse" "db_name = $db_name" "$final_path/config/discourse.conf" -ynh_replace_string "db_username = discourse" "db_username = $db_name" "$final_path/config/discourse.conf" -ynh_replace_string "db_password =" "db_password = $db_pwd" "$final_path/config/discourse.conf" +discourse_config_file="$final_path/config/discourse.conf" +cp $final_path/config/discourse_defaults.conf $discourse_config_file +ynh_replace_string "db_name = discourse" "db_name = $db_name" "$discourse_config_file" +ynh_replace_string "db_username = discourse" "db_username = $db_name" "$discourse_config_file" +ynh_replace_string "db_password =" "db_password = $db_pwd" "$discourse_config_file" # Configure hostname -ynh_replace_string "hostname = \"www.example.com\"" "hostname = \"$domain\"" "$final_path/config/discourse.conf" -ynh_replace_string "relative_url_root =" "relative_url_root = ${path_url%/}" "$final_path/config/discourse.conf" +ynh_replace_string "hostname = \"www.example.com\"" "hostname = \"$domain\"" "$discourse_config_file" +ynh_replace_string "relative_url_root =" "relative_url_root = ${path_url%/}" "$discourse_config_file" # Serve static assets (i.e. images, js, etc.) -ynh_replace_string "serve_static_assets = false" "serve_static_assets = true" "$final_path/config/discourse.conf" +ynh_replace_string "serve_static_assets = false" "serve_static_assets = true" "$discourse_config_file" # Configure e-mail server admin_mail=$(ynh_user_get_info "$admin" mail) -ynh_replace_string "developer_emails =" "developer_emails = $admin_mail" "$final_path/config/discourse.conf" -ynh_replace_string "smtp_address =" "smtp_address = localhost" "$final_path/config/discourse.conf" -ynh_replace_string "smtp_domain =" "smtp_domain = $domain" "$final_path/config/discourse.conf" -ynh_replace_string "smtp_enable_start_tls = true" "smtp_enable_start_tls = false" "$final_path/config/discourse.conf" +ynh_replace_string "developer_emails =" "developer_emails = $admin_mail" "$discourse_config_file" +ynh_replace_string "smtp_address =" "smtp_address = localhost" "$discourse_config_file" +ynh_replace_string "smtp_domain =" "smtp_domain = $domain" "$discourse_config_file" +ynh_replace_string "smtp_enable_start_tls = true" "smtp_enable_start_tls = false" "$discourse_config_file" # Calculate and store the config file checksum -ynh_store_file_checksum "$final_path/config/discourse.conf" +ynh_store_file_checksum "$discourse_config_file" -# Configure LDAP plugins -ynh_replace_string "adfs.example.com" "localhost" "$final_path/plugins/discourse-ldap-auth/config/settings.yml" -ynh_replace_string "dc=example,dc=com" "ou=users,dc=yunohost,dc=org" "$final_path/plugins/discourse-ldap-auth/config/settings.yml" -ynh_replace_string "sAMAccountName" "uid" "$final_path/plugins/discourse-ldap-auth/config/settings.yml" +# Configure LDAP plugin +ldap_config_file="$final_path/plugins/discourse-ldap-auth/config/settings.yml" +ynh_replace_string "adfs.example.com" "localhost" "$ldap_config_file" +ynh_replace_string "dc=example,dc=com" "ou=users,dc=yunohost,dc=org" "$ldap_config_file" +ynh_replace_string "sAMAccountName" "uid" "$ldap_config_file" +ynh_store_file_checksum "$ldap_config_file" #================================================= # SETUP PUMA, A RUBY SERVER #================================================= - -ynh_replace_string "#{APP_ROOT}/log/puma" "/var/log/$app/puma" "$final_path/config/puma.rb" -ynh_replace_string "/home/discourse" "/var/www" "$final_path/config/puma.rb" -ynh_replace_string "daemonize true" "daemonize false" "$final_path/config/puma.rb" +puma_config_file="$final_path/config/puma.rb" +ynh_replace_string "#{APP_ROOT}/log/puma" "/var/log/$app/puma" "$puma_config_file" +ynh_replace_string "/home/discourse" "/var/www" "$puma_config_file" +ynh_replace_string "daemonize true" "daemonize false" "$puma_config_file" # Calculate and store the config file checksum -ynh_store_file_checksum "$final_path/config/puma.rb" +ynh_store_file_checksum "$puma_config_file" # Set a secret value cp ../conf/secrets.yml "$final_path/config/secrets.yml" @@ -166,13 +166,13 @@ ynh_store_file_checksum "$final_path/config/secrets.yml" chown -R $app: $final_path -# # Install puma with gem +# Install puma with gem (cd "$final_path" -# # Install bundler, a gems installer +# Install bundler, a gems installer gem install bundler -# # Install without documentation +# Install without documentation exec_as $app echo "gem: --no-ri --no-rdoc" >> "$final_path/.gemrc" -# # Install dependencies +# Install dependencies exec_as $app bundle install --path vendor/bundle --without development test postgresql) #=================================================