diff --git a/conf/app.src b/conf/app.src index e053788..a8392f7 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,5 +1,5 @@ -SOURCE_URL=https://github.com/standardnotes/syncing-server/archive/3.13.6.zip -SOURCE_SUM=9b68e74e34dba5949f740ef6ce3b88b9eee43e29a8eac8aa2d1b3987263eff72 +SOURCE_URL=https://github.com/standardnotes/syncing-server/archive/3.20.4.zip +SOURCE_SUM=A9FEBE8D31200580D2AEC3DF407F177F7A334C837386E7DD436F1754746A4EAA SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=zip SOURCE_IN_SUBDIR=true diff --git a/conf/env.sample b/conf/env.sample index d6a7f95..b6e20e6 100644 --- a/conf/env.sample +++ b/conf/env.sample @@ -11,7 +11,8 @@ EXPOSED_PORT=3000 # change this to "production" for production use, otherwise the access token time is very short and forces re-login RAILS_ENV=development RAILS_LOG_TO_STDOUT=false -RAILS_LOG_LEVEL=info # "debug" | "info" | "warn" | "error" | "fatal" +# Log Level options: "INFO" | "DEBUG" | "INFO" | "WARN" | "ERROR" | "FATAL" +RAILS_LOG_LEVEL=INFO #SQS_QUEUE=somequeue #SQS_QUEUE_LOW_PRIORITY=low_priority_queue #AWS_REGION=us-west1 @@ -63,6 +64,18 @@ EMAIL_ATTACHMENT_MAX_SIZE=10485760 # Revisions persistency REVISIONS_FREQUENCY=300 +# (Optional) Redis Cache for ephemeral sessions +REDIS_URL=redis://cache:6379 + +# (Optional) Change URLs to Internal DNS +#INTERNAL_DNS_REROUTE_ENABLED=false + +# (Optional) Auth Proxy JWT Secret +#AUTH_JWT_SECRET=changeme123 + +# (Optional) User Management Server - registration emails, subscriptions etc. +#USER_MANAGEMENT_SERVER= + # Sub-URI RAILS_RELATIVE_URL_ROOT=/ diff --git a/conf/systemd.service b/conf/systemd.service index 145c806..58e06c1 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -1,6 +1,8 @@ [Unit] Description=__APP__ service After=network.target +After=mysql.service +After=redis.service [Service] Type=simple diff --git a/manifest.json b/manifest.json index c7d9e3c..0018824 100644 --- a/manifest.json +++ b/manifest.json @@ -5,7 +5,7 @@ "description": { "en": "The Standard Notes syncing server. An end-to-end encrypted note-taking app." }, - "version": "3.13.6~ynh4", + "version": "3.20.4~ynh1", "url": "https://github.com/standardnotes/syncing-server", "license": "AGPL-3.0-or-later", "maintainer": { diff --git a/scripts/install b/scripts/install index 55325b4..63ac027 100755 --- a/scripts/install +++ b/scripts/install @@ -8,6 +8,7 @@ source _common.sh source ynh_install_ruby +source ynh_redis source /usr/share/yunohost/helpers #================================================= @@ -54,6 +55,8 @@ ynh_app_setting_set --app=$app --key=path --value=$path_url ynh_app_setting_set --app=$app --key=is_public --value=$is_public ynh_app_setting_set --app=$app --key=access_domain --value=$access_domain ynh_app_setting_set --app=$app --key=mail --value=$mail +redis_db=$(ynh_redis_get_free_db) +ynh_app_setting_set --app=$app --key=redis_db --value="$redis_db" #================================================= # STANDARD MODIFICATIONS @@ -148,6 +151,7 @@ ynh_replace_string --match_string="SMTP_PORT=.*$" --replace_string="SMTP_PORT=25 ynh_replace_string --match_string="SMTP_DOMAIN=.*$" --replace_string="SMTP_DOMAIN=localhost" --target_file="$config_file" ynh_replace_string --match_string="SMTP_STARTTLS=.*$" --replace_string="SMTP_STARTTLS=" --target_file="$config_file" ynh_replace_string --match_string="RAILS_SERVE_STATIC_FILES=.*$" --replace_string="RAILS_SERVE_STATIC_FILES=true" --target_file="$config_file" +ynh_replace_string --match_string="REDIS_URL.*$" --replace_string="REDIS_URL=redis://localhost:6379/$redis_db" --target_file="$config_file" ynh_replace_string --match_string="__MAIL__" --replace_string="$mail" --target_file="$final_path/live/app/mailers/application_mailer.rb" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/live/app/views/user_mailer/welcome.html.erb" @@ -164,7 +168,8 @@ pushd "$final_path/live" exec_as "$app" env PATH=$PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundle config set path 'vendor/bundle' exec_as "$app" env PATH=$PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundle config set with 'development' exec_as "$app" env PATH=$PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundle install - exec_as "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/$RUBY_VERSION/bin/bundle exec rails db:create db:migrate --quiet + exec_as "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/$RUBY_VERSION/bin/bundle exec rails db:migrate --quiet + exec_as "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/$RUBY_VERSION/bin/bundle exec rails db:seed --quiet # exec_as "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/$RUBY_VERSION/bin/bundle exec rails assets:precompile --quiet popd diff --git a/scripts/remove b/scripts/remove index 99575ef..90dcfbe 100755 --- a/scripts/remove +++ b/scripts/remove @@ -8,6 +8,7 @@ source _common.sh source ynh_install_ruby +source ynh_redis source /usr/share/yunohost/helpers #================================================= @@ -52,6 +53,13 @@ ynh_script_progression --message="Removing the MySQL database..." --weight=1 # Remove a database if it exists, along with the associated user ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name +##================================================= +## REMOVE REDIS DB +##================================================= +ynh_script_progression --message="Removing the Redis database..." --weight=1 + +ynh_redis_remove_db + #================================================= # REMOVE DEPENDENCIES #================================================= diff --git a/scripts/restore b/scripts/restore index 2f5ab51..5e401db 100755 --- a/scripts/restore +++ b/scripts/restore @@ -9,6 +9,7 @@ #Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source ../settings/scripts/ynh_install_ruby +source ../settings/scripts/ynh_redis source /usr/share/yunohost/helpers #================================================= @@ -36,6 +37,11 @@ db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) +redis_db=$(ynh_redis_get_free_db) +ynh_app_setting_set --app=$app --key=redis_db --value="$redis_db" + +config_file="$final_path/live/.env" + #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= @@ -109,6 +115,13 @@ ynh_script_progression --message="Restoring the MySQL database..." --weight=2 ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql +#================================================= +# SETUP REDIS DATABASE +#================================================= +ynh_script_progression --message="Setup Redis database..." --weight=2 + +ynh_replace_string --match_string=".*REDIS_URL.*$" --replace_string="REDIS_URL=redis://localhost:6379/$redis_db" --target_file="$config_file" + #================================================= # RESTORE SYSTEMD #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index b4ffdcf..780a40d 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -8,6 +8,7 @@ source _common.sh source ynh_install_ruby +source ynh_redis source /usr/share/yunohost/helpers #================================================= @@ -27,6 +28,9 @@ db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) port=$(ynh_app_setting_get --app=$app --key=port) access_domain=$(ynh_app_setting_get --app=$app --key=access_domain) mail=$(ynh_app_setting_get --app=$app --key=mail) +redis_db=$(ynh_app_setting_get --app=$app --key=redis_db) + +config_file="$final_path/live/.env" #================================================= # CHECK VERSION @@ -92,15 +96,21 @@ if [ -z "$mail" ]; then ynh_app_setting_set --app=$app --key=mail --value=$mail fi +# If redis_db doesn't exist, create it +if [ -z "$redis_db" ]; then + redis_db=$(ynh_redis_get_free_db) + ynh_app_setting_set --app=$app --key=redis_db --value="$redis_db" +fi + if ynh_compare_current_package_version --comparison lt --version "3.13.6~ynh4" then - # Add Variables to .env config file + # Add variables to .env config file echo -e "\ - \n# Public file server\ - \n# Empty is disabled\ - \n# Any value is enabled\ - \nRAILS_SERVE_STATIC_FILES=\ - " >> "$final_path/live/.env" +\n# Public file server\ +\n# Empty is disabled\ +\n# Any value is enabled\ +\nRAILS_SERVE_STATIC_FILES=\ +" >> "$config_file" # Apply Patch if [ -f "$YNH_CWD/../sources/patches/app-01-add-mail.patch" ] @@ -111,6 +121,33 @@ then fi fi +if ynh_compare_current_package_version --comparison lt --version "3.20.4~ynh1" +then + # Add variables to .env config file + echo -e "\ +\n# (Optional) Redis Cache for ephemeral sessions\ +\nREDIS_URL=redis://cache:6379\ +\n\ +\n# (Optional) Change URLs to Internal DNS\ +\n#INTERNAL_DNS_REROUTE_ENABLED=false\ +\n\ +\n# (Optional) Auth Proxy JWT Secret\ +\n#AUTH_JWT_SECRET=changeme123\ +\n\ +\n# (Optional) User Management Server - registration emails, subscriptions etc.\ +\n#USER_MANAGEMENT_SERVER=\ +" >> "$config_file" + + # Change variables to .env config file + ynh_replace_string \ + --match_string="RAILS_LOG_LEVEL=.*$" \ + --replace_string='# Log Level options: "INFO" | "DEBUG" | "INFO" | "WARN" | "ERROR" | "FATAL"\nRAILS_LOG_LEVEL=INFO' \ + --target_file="$config_file" + + ynh_replace_string --match_string="REDIS_URL.*$" --replace_string="REDIS_URL=redis://localhost:6379/$redis_db" --target_file="$config_file" + +fi + #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -233,7 +270,8 @@ then exec_as "$app" env PATH=$PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundle config set path 'vendor/bundle' exec_as "$app" env PATH=$PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundle config set with 'development' exec_as "$app" env PATH=$PATH /opt/rbenv/versions/$RUBY_VERSION/bin/bundle install - exec_as "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/$RUBY_VERSION/bin/bundle exec rails db:create db:migrate --quiet + exec_as "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/$RUBY_VERSION/bin/bundle exec rails db:migrate --quiet + exec_as "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/$RUBY_VERSION/bin/bundle exec rails db:seed --quiet # exec_as "$app" env PATH=$PATH RAILS_ENV=production /opt/rbenv/versions/$RUBY_VERSION/bin/bundle exec rails assets:precompile --quiet popd fi diff --git a/scripts/ynh_redis b/scripts/ynh_redis new file mode 100644 index 0000000..5ab83fd --- /dev/null +++ b/scripts/ynh_redis @@ -0,0 +1,39 @@ +#!/bin/bash + +# get the first available redis database +# +# usage: ynh_redis_get_free_db +# | returns: the database number to use +ynh_redis_get_free_db() { + local result max db + result=$(redis-cli INFO keyspace) + + # get the num + max=$(cat /etc/redis/redis.conf | grep ^databases | grep -Eow "[0-9]+") + + db=0 + # default Debian setting is 15 databases + for i in $(seq 0 "$max") + do + if ! echo "$result" | grep -q "db$i" + then + db=$i + break 1 + fi + db=-1 + done + + test "$db" -eq -1 && ynh_die --message="No available Redis databases..." + + echo "$db" +} + +# Create a master password and set up global settings +# Please always call this script in install and restore scripts +# +# usage: ynh_redis_remove_db database +# | arg: database - the database to erase +ynh_redis_remove_db() { + local db=$1 + redis-cli -n "$db" flushall +}