diff --git a/scripts/backup b/scripts/backup index b914d0a..da46623 100644 --- a/scripts/backup +++ b/scripts/backup @@ -32,6 +32,7 @@ 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) #================================================= # STANDARD BACKUP STEPS diff --git a/scripts/change_url b/scripts/change_url index c92e307..b062d9b 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -34,6 +34,7 @@ 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=db_pwd) +unicorn_workers=$(ynh_app_setting_get --app=$app --key=unicorn_workers) #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP @@ -151,11 +152,6 @@ $rake_exec posts:rebake ynh_print_info --message="Starting a systemd service..." # Start a systemd service -if [ -n "$(uname -m | grep arm)" ] ; then - unicorn_workers=2 -else - unicorn_workers=3 -fi ynh_systemd_action --service_name=$app --action="start" --log_path="$final_path/log/unicorn.stderr.log" --line_match="INFO -- : worker=$((unicorn_workers-1)) ready" #================================================= diff --git a/scripts/install b/scripts/install index 453e0c2..a65fa11 100644 --- a/scripts/install +++ b/scripts/install @@ -312,6 +312,8 @@ else additional_env="" 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" ynh_add_systemd_config diff --git a/scripts/restore b/scripts/restore index 35d674e..1b8f079 100644 --- a/scripts/restore +++ b/scripts/restore @@ -144,6 +144,7 @@ if [ -n "$(uname -m | grep arm)" ] ; then else unicorn_workers=3 fi +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" #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index abd31f5..29543da 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -24,6 +24,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) redis_db=$(ynh_app_setting_get --app=$app --key=redis_db) +unicorn_workers=$(ynh_app_setting_get --app=$app --key=unicorn_workers) # Check memory requirements check_memory_requirements_upgrade @@ -35,6 +36,25 @@ ynh_print_info --message="Checking version..." upgrade_type=$(ynh_check_app_version_changed) +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= +ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 + +# If db_name 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 + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -286,16 +306,7 @@ ynh_print_info --message="Configuring a systemd service..." ynh_replace_string --match_string="__RBENVROOT__" --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 - additional_env="UNICORN_WORKERS=2" - unicorn_workers=2 -else - additional_env="" - unicorn_workers=3 -fi - +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" ynh_add_systemd_config @@ -341,11 +352,6 @@ fi #================================================= ynh_print_info --message="Starting a systemd service..." -if [ -n "$(uname -m | grep arm)" ] ; then - unicorn_workers=2 -else - unicorn_workers=3 -fi # Wait for discourse to be fully started ynh_systemd_action --service_name=$app --action="start" --log_path="$final_path/log/unicorn.stderr.log" --line_match="INFO -- : worker=$((unicorn_workers-1)) ready"