mirror of
https://github.com/YunoHost-Apps/fab-manager_ynh.git
synced 2024-09-03 18:36:16 +02:00
Cleanup, move code to _common.sh
This commit is contained in:
parent
2d2857b72e
commit
6d4dbafd40
5 changed files with 114 additions and 348 deletions
|
@ -27,6 +27,45 @@ fi
|
|||
# PERSONAL HELPERS
|
||||
#=================================================
|
||||
|
||||
fabmanager_build_ruby() {
|
||||
pushd "$install_dir"
|
||||
ynh_use_ruby
|
||||
ynh_exec_warn_less "$ynh_gem" install "bundler:$bundler_version"
|
||||
ynh_exec_warn_less bin/bundle config --global frozen 1
|
||||
ynh_exec_warn_less bin/bundle config set --local without 'development test doc'
|
||||
ynh_exec_warn_less bin/bundle install
|
||||
ynh_exec_warn_less bin/bundle binstubs --all
|
||||
popd
|
||||
}
|
||||
|
||||
fabmanager_seed_db() {
|
||||
pushd "$install_dir"
|
||||
ynh_replace_string --match_string="DateTime.current" --replace_string="DateTime.current - 1.days" --target_file="$final_path/db/seeds.rb"
|
||||
ynh_exec_warn_less ynh_exec_as "$app" env RAILS_ENV=production "$ynh_ruby_load_path" "$ld_preload" \
|
||||
bin/bundle exec rake db:seed ADMIN_EMAIL="$admin_mail" ADMIN_PASSWORD="$password"
|
||||
popd
|
||||
}
|
||||
|
||||
fabmanager_migrate_db() {
|
||||
pushd "$install_dir"
|
||||
ynh_psql_execute_as_root --database="$db_name" --sql="ALTER USER $db_user WITH SUPERUSER;"
|
||||
ynh_exec_warn_less ynh_exec_as "$app" env RAILS_ENV=production "$ynh_ruby_load_path" "$ld_preload" bin/bundle exec rake db:migrate
|
||||
ynh_psql_execute_as_root --database="$db_name" --sql="ALTER USER $db_user WITH NOSUPERUSER;"
|
||||
popd
|
||||
}
|
||||
|
||||
fabmanager_build_ui() {
|
||||
pushd "$install_dir"
|
||||
ynh_use_nodejs
|
||||
ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" yarn install
|
||||
#ynh_exec_warn_less ynh_exec_as "$app" env RAILS_ENV=production "$ynh_ruby_load_path" $ld_preload yarn install
|
||||
#ynh_exec_warn_less ynh_exec_as "$app" env RAILS_ENV=production "$ynh_ruby_load_path" $ld_preload bin/webpack
|
||||
ynh_exec_warn_less ynh_exec_as "$app" env RAILS_ENV=production "$ynh_ruby_load_path" "$ld_preload" bin/bundle exec rake assets:precompile
|
||||
ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" yarn cache clean --all
|
||||
popd
|
||||
}
|
||||
|
||||
|
||||
#=================================================
|
||||
# EXPERIMENTAL HELPERS
|
||||
#=================================================
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC STARTING
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
@ -9,76 +7,14 @@
|
|||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# RETRIEVE ARGUMENTS
|
||||
#=================================================
|
||||
|
||||
#REMOVEME? old_domain=$YNH_APP_OLD_DOMAIN
|
||||
#REMOVEME? old_path=$YNH_APP_OLD_PATH
|
||||
|
||||
#REMOVEME? new_domain=$YNH_APP_NEW_DOMAIN
|
||||
#REMOVEME? new_path="/"
|
||||
|
||||
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1
|
||||
|
||||
#REMOVEME? # Needed for helper "ynh_add_nginx_config"
|
||||
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
|
||||
|
||||
# Add settings here as needed by your application
|
||||
#REMOVEME? language=$(ynh_app_setting_get --app=$app --key=language)
|
||||
#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
||||
#REMOVEME? db_user=$db_name
|
||||
#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
||||
#REMOVEME? data_dir=$(ynh_app_setting_get --app=$app --key=data_dir)
|
||||
#REMOVEME? secret_key_base=$(ynh_app_setting_get --app=$app --key=secret_key_base)
|
||||
|
||||
#=================================================
|
||||
# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP
|
||||
#=================================================
|
||||
#REMOVEME? ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=1
|
||||
|
||||
# Backup the current version of the app
|
||||
#REMOVEME? ynh_backup_before_upgrade
|
||||
#REMOVEME? ynh_clean_setup () {
|
||||
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
|
||||
#REMOVEME? ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
|
||||
|
||||
# Restore it if the upgrade fails
|
||||
#REMOVEME? ynh_restore_upgradebackup
|
||||
}
|
||||
# Exit if an error occurs during the execution of the script
|
||||
#REMOVEME? ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# CHECK WHICH PARTS SHOULD BE CHANGED
|
||||
#=================================================
|
||||
|
||||
#REMOVEME? change_domain=0
|
||||
#REMOVEME? if [ "$old_domain" != "$new_domain" ]
|
||||
then
|
||||
#REMOVEME? change_domain=1
|
||||
fi
|
||||
|
||||
#REMOVEME? change_path=0
|
||||
#REMOVEME? if [ "$old_path" != "$new_path" ]
|
||||
then
|
||||
#REMOVEME? change_path=1
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# STANDARD MODIFICATIONS
|
||||
#=================================================
|
||||
# STOP SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name=${app}-app --action="stop" --log_path=systemd --line_match="Stopped"
|
||||
ynh_systemd_action --service_name=${app}-worker --action="stop" --log_path=systemd --line_match="Stopped"
|
||||
ynh_systemd_action --service_name="${app}-app" --action="stop" --log_path=systemd --line_match="Stopped"
|
||||
ynh_systemd_action --service_name="${app}-worker" --action="stop" --log_path=systemd --line_match="Stopped"
|
||||
|
||||
#=================================================
|
||||
# MODIFY URL IN NGINX CONF
|
||||
|
@ -87,42 +23,14 @@ ynh_script_progression --message="Updating NGINX web server configuration..." --
|
|||
|
||||
ynh_change_url_nginx_config
|
||||
|
||||
#REMOVEME? nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
|
||||
|
||||
# Change the path in the NGINX config file
|
||||
if [ $change_path -eq 1 ]
|
||||
then
|
||||
# Make a backup of the original NGINX config file if modified
|
||||
#REMOVEME? ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
|
||||
# Set global variables for NGINX helper
|
||||
#REMOVEME? domain="$old_domain"
|
||||
#REMOVEME? path="$new_path"
|
||||
# Create a dedicated NGINX config
|
||||
#REMOVEME? ynh_add_nginx_config
|
||||
fi
|
||||
|
||||
# Change the domain for NGINX
|
||||
if [ $change_domain -eq 1 ]
|
||||
then
|
||||
# Delete file checksum for the old conf file location
|
||||
#REMOVEME? ynh_delete_file_checksum --file="$nginx_conf_path"
|
||||
#REMOVEME? mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
|
||||
# Store file checksum for the new config file location
|
||||
#REMOVEME? ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC MODIFICATIONS
|
||||
#=================================================
|
||||
# UPDATE A CONFIG FILE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Updating a configuration file..." --weight=1
|
||||
#REMOVEME?
|
||||
domain=$new_domain
|
||||
path=$new_path
|
||||
ynh_add_config --template="../conf/secrets.yml" --destination="$install_dir/config/secrets.yml"
|
||||
|
||||
ynh_add_config --template="secrets.yml" --destination="$install_dir/config/secrets.yml"
|
||||
chmod 400 "$install_dir/config/secrets.yml"
|
||||
chown $app:$app "$install_dir/config/secrets.yml"
|
||||
chown "$app:$app" "$install_dir/config/secrets.yml"
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALISATION
|
||||
|
@ -132,15 +40,8 @@ chown $app:$app "$install_dir/config/secrets.yml"
|
|||
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
||||
|
||||
# Start a systemd service
|
||||
ynh_systemd_action --service_name=${app}-app --action="start" --log_path=systemd --line_match="Listening on"
|
||||
ynh_systemd_action --service_name=${app}-worker --action="start" --log_path=systemd --line_match="Schedules Loaded"
|
||||
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
||||
|
||||
#REMOVEME? #REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
|
||||
ynh_systemd_action --service_name="${app}-app" --action="start" --log_path=systemd --line_match="Listening on"
|
||||
ynh_systemd_action --service_name="${app}-worker" --action="start" --log_path=systemd --line_match="Schedules Loaded"
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
|
|
|
@ -48,19 +48,8 @@ ynh_setup_source --dest_dir="$install_dir"
|
|||
chmod -R o-rwx "$install_dir"
|
||||
chown -R "$app:www-data" "$install_dir"
|
||||
|
||||
#=================================================
|
||||
# CREATE DATA DIRECTORY
|
||||
#=================================================
|
||||
ynh_script_progression --message="Creating a data directory..." --weight=1
|
||||
|
||||
#REMOVEME? data_dir=/home/yunohost.app/$app
|
||||
#REMOVEME? ynh_app_setting_set --app=$app --key=data_dir --value=$data_dir
|
||||
|
||||
mkdir -p $data_dir
|
||||
|
||||
chmod 750 "$data_dir"
|
||||
chmod -R o-rwx "$data_dir"
|
||||
chown -R $app:www-data "$data_dir"
|
||||
chown -R "$app:www-data" "$data_dir"
|
||||
|
||||
#=================================================
|
||||
# ADD A CONFIGURATION
|
||||
|
@ -69,37 +58,23 @@ ynh_script_progression --message="Adding a configuration file..." --weight=1
|
|||
|
||||
ynh_add_config --template="secrets.yml" --destination="$install_dir/config/secrets.yml"
|
||||
chmod 400 "$install_dir/config/secrets.yml"
|
||||
chown $app:$app "$install_dir/config/secrets.yml"
|
||||
chown "$app:$app" "$install_dir/config/secrets.yml"
|
||||
|
||||
ynh_add_config --template="database.yml" --destination="$install_dir/config/database.yml"
|
||||
chmod 400 "$install_dir/config/database.yml"
|
||||
chown $app:$app "$install_dir/config/database.yml"
|
||||
chown "$app:$app" "$install_dir/config/database.yml"
|
||||
|
||||
#=================================================
|
||||
# BUILD APP
|
||||
#=================================================
|
||||
ynh_script_progression --message="Building app..." --weight=1
|
||||
|
||||
pushd $install_dir
|
||||
ynh_use_ruby
|
||||
ynh_exec_warn_less $ynh_gem install "bundler:$bundler_version"
|
||||
ynh_exec_warn_less bin/bundle config --global frozen 1
|
||||
ynh_exec_warn_less bin/bundle config set --local without 'development test doc'
|
||||
ynh_exec_warn_less bin/bundle install
|
||||
ynh_exec_warn_less bin/bundle binstubs --all
|
||||
fabmanager_build_ruby
|
||||
|
||||
ynh_use_nodejs
|
||||
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install
|
||||
ynh_psql_execute_as_root --sql="ALTER USER $db_user WITH SUPERUSER;" --database="$db_name"
|
||||
ynh_exec_warn_less ynh_exec_as $app env RAILS_ENV=production $ynh_ruby_load_path $ld_preload bin/bundle exec rake db:migrate
|
||||
ynh_psql_execute_as_root --sql="ALTER USER $db_user WITH NOSUPERUSER;" --database="$db_name"
|
||||
ynh_replace_string --match_string="DateTime.current" --replace_string="DateTime.current - 1.days" --target_file="$install_dir/db/seeds.rb"
|
||||
ynh_exec_warn_less ynh_exec_as $app env RAILS_ENV=production $ynh_ruby_load_path $ld_preload bin/bundle exec rake db:seed ADMIN_EMAIL="$admin_mail" ADMIN_PASSWORD="$password"
|
||||
#ynh_exec_warn_less ynh_exec_as $app env RAILS_ENV=production $ynh_ruby_load_path $ld_preload yarn install
|
||||
#ynh_exec_warn_less ynh_exec_as $app env RAILS_ENV=production $ynh_ruby_load_path $ld_preload bin/webpack
|
||||
( ynh_exec_warn_less ynh_exec_as $app env RAILS_ENV=production $ynh_ruby_load_path $ld_preload bin/bundle exec rake assets:precompile )
|
||||
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn cache clean --all
|
||||
popd
|
||||
fabmanager_migrate_db
|
||||
fabmanager_seed_db
|
||||
|
||||
fabmanager_build_ui
|
||||
|
||||
ynh_secure_remove --file="$install_dir/.cache"
|
||||
|
||||
|
|
|
@ -9,6 +9,15 @@ source ../settings/scripts/_common.sh
|
|||
source ../settings/scripts/ynh_install_ruby__2
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# INSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
ynh_script_progression --message="Reinstalling NodeJS..." --weight=1
|
||||
ynh_exec_warn_less ynh_install_nodejs --nodejs_version="$nodejs_version"
|
||||
|
||||
ynh_script_progression --message="Reinstalling Ruby..." --weight=1
|
||||
ynh_exec_warn_less ynh_install_ruby --ruby_version="$ruby_version"
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE APP MAIN DIR
|
||||
#=================================================
|
||||
|
@ -16,7 +25,6 @@ ynh_script_progression --message="Restoring the app main directory..." --weight=
|
|||
|
||||
ynh_restore_file --origin_path="$install_dir"
|
||||
|
||||
chmod 750 "$install_dir"
|
||||
chmod -R o-rwx "$install_dir"
|
||||
chown -R $app:www-data "$install_dir"
|
||||
|
||||
|
@ -27,96 +35,52 @@ ynh_script_progression --message="Restoring the data directory..." --weight=1
|
|||
|
||||
ynh_restore_file --origin_path="$data_dir" --not_mandatory
|
||||
|
||||
mkdir -p $data_dir
|
||||
|
||||
chmod 750 "$data_dir"
|
||||
chmod -R o-rwx "$data_dir"
|
||||
chown -R $app:www-data "$data_dir"
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC RESTORATION
|
||||
#=================================================
|
||||
# REINSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
#REMOVEME? ynh_script_progression --message="Reinstalling dependencies..." --weight=1
|
||||
|
||||
# Define and install dependencies
|
||||
#REMOVEME? 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_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
|
||||
#REMOVEME? ynh_exec_warn_less ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1
|
||||
|
||||
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
chown -R "$app:www-data" "$data_dir"
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE POSTGRESQL DATABASE
|
||||
#=================================================
|
||||
#REMOVEME? ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1
|
||||
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1
|
||||
|
||||
#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
||||
#REMOVEME? ynh_psql_test_if_first_run
|
||||
#REMOVEME? ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
|
||||
ynh_psql_execute_as_root --sql="ALTER USER $db_user WITH SUPERUSER;" --database="$db_name"
|
||||
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS unaccent;" --database=$db_name
|
||||
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name
|
||||
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;" --database=$db_name
|
||||
ynh_psql_execute_as_root --sql="ALTER USER $db_user WITH NOSUPERUSER;" --database="$db_name"
|
||||
ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name
|
||||
ynh_psql_execute_as_root --database="$db_name" --sql="ALTER USER $db_user WITH SUPERUSER;"
|
||||
ynh_psql_execute_as_root --database="$db_name" --sql="CREATE EXTENSION IF NOT EXISTS unaccent;"
|
||||
ynh_psql_execute_as_root --database="$db_name" --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;"
|
||||
ynh_psql_execute_as_root --database="$db_name" --sql="CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;"
|
||||
ynh_psql_execute_as_root --database="$db_name" --sql="ALTER USER $db_user WITH NOSUPERUSER;"
|
||||
|
||||
ynh_psql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < ./db.sql
|
||||
|
||||
#=================================================
|
||||
# BUILD APP
|
||||
#=================================================
|
||||
ynh_script_progression --message="Building app..." --weight=1
|
||||
|
||||
pushd $install_dir
|
||||
ynh_use_ruby
|
||||
ynh_exec_warn_less $ynh_gem install "bundler:$bundler_version"
|
||||
ynh_exec_warn_less bin/bundle config --global frozen 1
|
||||
ynh_exec_warn_less bin/bundle config set --local without 'development test doc'
|
||||
ynh_exec_warn_less bin/bundle install
|
||||
ynh_exec_warn_less bin/bundle binstubs --all
|
||||
ynh_use_nodejs
|
||||
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install
|
||||
ynh_exec_warn_less ynh_exec_as $app env RAILS_ENV=production $ynh_ruby_load_path $ld_preload bin/bundle exec rake assets:precompile
|
||||
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn cache clean --all
|
||||
popd
|
||||
fabmanager_build_ruby
|
||||
|
||||
#REMOVEME? ynh_install_app_dependencies $pkg_dependencies
|
||||
#REMOVEME? ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
|
||||
#REMOVEME? ynh_secure_remove --file="$install_dir/.cache"
|
||||
fabmanager_build_ui
|
||||
|
||||
#=================================================
|
||||
# RESTORE SYSTEMD
|
||||
# RESTORE SYSTEM CONFIGURATIONS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
|
||||
ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1
|
||||
|
||||
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
ynh_restore_file --origin_path="/etc/systemd/system/$app-app.service"
|
||||
ynh_restore_file --origin_path="/etc/systemd/system/$app-worker.service"
|
||||
systemctl enable "$app-app" "$app-worker" --quiet
|
||||
|
||||
#=================================================
|
||||
# INTEGRATE SERVICE IN YUNOHOST
|
||||
#=================================================
|
||||
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
||||
|
||||
yunohost service add "$app-app" --description="$app app service"
|
||||
yunohost service add "$app-worker" --description="$app worker service"
|
||||
|
||||
#=================================================
|
||||
# START SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
||||
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name=${app}-app --action="start" --log_path=systemd --line_match="Listening on"
|
||||
ynh_systemd_action --service_name=${app}-worker --action="start" --log_path=systemd --line_match="Schedules Loaded"
|
||||
ynh_systemd_action --service_name="${app}-app" --action="start" --log_path=systemd --line_match="Listening on"
|
||||
ynh_systemd_action --service_name="${app}-worker" --action="start" --log_path=systemd --line_match="Schedules Loaded"
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
|
|
179
scripts/upgrade
179
scripts/upgrade
|
@ -1,7 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
@ -11,72 +9,22 @@ source ynh_install_ruby__2
|
|||
source ynh_supervisor
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1
|
||||
|
||||
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path)
|
||||
#REMOVEME? language=$(ynh_app_setting_get --app=$app --key=language)
|
||||
#REMOVEME? admin=$(ynh_app_setting_get --app=$app --key=admin)
|
||||
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
|
||||
#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
||||
#REMOVEME? db_user=$db_name
|
||||
#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
||||
#REMOVEME? data_dir=$(ynh_app_setting_get --app=$app --key=data_dir)
|
||||
#REMOVEME? secret_key_base=$(ynh_app_setting_get --app=$app --key=secret_key_base)
|
||||
#REMOVEME? port=$(ynh_app_setting_get --app=$app --key=port)
|
||||
|
||||
#=================================================
|
||||
# CHECK VERSION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Checking version..." --weight=1
|
||||
|
||||
upgrade_type=$(ynh_check_app_version_changed)
|
||||
|
||||
#=================================================
|
||||
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||
#=================================================
|
||||
#REMOVEME? ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
|
||||
|
||||
# Backup the current version of the app
|
||||
#REMOVEME? ynh_backup_before_upgrade
|
||||
#REMOVEME? ynh_clean_setup () {
|
||||
# Restore it if the upgrade fails
|
||||
#REMOVEME? ynh_restore_upgradebackup
|
||||
}
|
||||
# Exit if an error occurs during the execution of the script
|
||||
#REMOVEME? ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# STANDARD UPGRADE STEPS
|
||||
#=================================================
|
||||
# STOP SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
||||
ynh_script_progression --message="Stopping $app's systemd service..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name=${app}-app --action="stop" --log_path=systemd --line_match="Stopped"
|
||||
ynh_systemd_action --service_name=${app}-worker --action="stop" --log_path=systemd --line_match="Stopped"
|
||||
ynh_systemd_action --service_name="${app}-app" --action="stop" --log_path=systemd --line_match="Stopped"
|
||||
ynh_systemd_action --service_name="${app}-worker" --action="stop" --log_path=systemd --line_match="Stopped"
|
||||
|
||||
#=================================================
|
||||
# ENSURE DOWNWARD COMPATIBILITY
|
||||
#=================================================
|
||||
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
||||
|
||||
# Cleaning legacy permissions
|
||||
#REMOVEME? if ynh_legacy_permissions_exists; then
|
||||
#REMOVEME? ynh_legacy_permissions_delete_all
|
||||
|
||||
ynh_app_setting_delete --app=$app --key=is_public
|
||||
fi
|
||||
|
||||
if ynh_exec_warn_less yunohost service status $app >/dev/null
|
||||
then
|
||||
ynh_script_progression --message="Removing $app service integration..."
|
||||
yunohost service remove $app
|
||||
if ynh_exec_warn_less yunohost service status "$app" >/dev/null; then
|
||||
ynh_script_progression --message="Removing $app service integration..."
|
||||
yunohost service remove "$app"
|
||||
fi
|
||||
|
||||
ynh_remove_logrotate
|
||||
|
@ -89,58 +37,25 @@ ynh_secure_remove --file="/var/log/supervisor/$app-worker-stderr.log"
|
|||
ynh_secure_remove --file="/var/log/supervisor/$app-worker-stdout.log"
|
||||
|
||||
#=================================================
|
||||
# CREATE DEDICATED USER
|
||||
# INSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
#REMOVEME? ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
|
||||
ynh_script_progression --message="Updating NodeJS..." --weight=1
|
||||
ynh_exec_warn_less ynh_install_nodejs --nodejs_version="$nodejs_version"
|
||||
|
||||
# Create a dedicated user (if not existing)
|
||||
#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir"
|
||||
ynh_script_progression --message="Updating Ruby..." --weight=1
|
||||
ynh_exec_warn_less ynh_install_ruby --ruby_version="$ruby_version"
|
||||
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading source files..." --weight=1
|
||||
|
||||
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
||||
then
|
||||
ynh_script_progression --message="Upgrading source files..." --weight=1
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
ynh_setup_source --dest_dir="$install_dir" --full_replace=1 --keep="config/secrets.yml config/database.yml"
|
||||
|
||||
tmpdir="$(mktemp -d)"
|
||||
cp "$install_dir/config/secrets.yml" "$tmpdir/secrets.yml"
|
||||
cp "$install_dir/config/database.yml" "$tmpdir/database.yml"
|
||||
#REMOVEME? ynh_secure_remove --file="$install_dir"
|
||||
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
ynh_setup_source --dest_dir="$install_dir" --keep="config/secrets.yml config/database.yml"
|
||||
|
||||
cp -f "$tmpdir/secrets.yml" "$install_dir/config/secrets.yml"
|
||||
cp -f "$tmpdir/database.yml" "$install_dir/config/database.yml"
|
||||
ynh_secure_remove --file="$tmpdir"
|
||||
fi
|
||||
|
||||
chmod 750 "$install_dir"
|
||||
chmod -R o-rwx "$install_dir"
|
||||
chown -R $app:www-data "$install_dir"
|
||||
chown -R "$app:www-data" "$install_dir"
|
||||
|
||||
#=================================================
|
||||
# UPGRADE DEPENDENCIES
|
||||
#=================================================
|
||||
#REMOVEME? ynh_script_progression --message="Upgrading dependencies..." --weight=1
|
||||
|
||||
#REMOVEME? 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_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
|
||||
#REMOVEME? ynh_exec_warn_less ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
|
||||
|
||||
# Create a dedicated NGINX config
|
||||
ynh_add_nginx_config
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC UPGRADE
|
||||
#=================================================
|
||||
# UPDATE A CONFIG FILE
|
||||
#=================================================
|
||||
|
@ -148,76 +63,48 @@ ynh_script_progression --message="Updating a configuration file..." --weight=1
|
|||
|
||||
ynh_add_config --template="../conf/secrets.yml" --destination="$install_dir/config/secrets.yml"
|
||||
chmod 400 "$install_dir/config/secrets.yml"
|
||||
chown $app:$app "$install_dir/config/secrets.yml"
|
||||
chown "$app:$app" "$install_dir/config/secrets.yml"
|
||||
|
||||
ynh_add_config --template="../conf/database.yml" --destination="$install_dir/config/database.yml"
|
||||
chmod 400 "$install_dir/config/database.yml"
|
||||
chown $app:$app "$install_dir/config/database.yml"
|
||||
chown "$app:$app" "$install_dir/config/database.yml"
|
||||
|
||||
#=================================================
|
||||
# BUILD APP
|
||||
#=================================================
|
||||
ynh_script_progression --message="Building app..." --weight=1
|
||||
|
||||
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
||||
then
|
||||
pushd $install_dir
|
||||
#REMOVEME? ynh_secure_remove --file="$install_dir/.cache"
|
||||
#REMOVEME? ynh_secure_remove --file="$install_dir/node_modules"
|
||||
#REMOVEME? ynh_secure_remove --file="$install_dir/tmp/cache"
|
||||
ynh_use_ruby
|
||||
ynh_exec_warn_less $ynh_gem install "bundler:$bundler_version"
|
||||
ynh_exec_warn_less bin/bundle config --global frozen 1
|
||||
ynh_exec_warn_less bin/bundle config set --local without 'development test doc'
|
||||
ynh_exec_warn_less bin/bundle install
|
||||
ynh_exec_warn_less bin/bundle binstubs --all
|
||||
ynh_use_nodejs
|
||||
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install
|
||||
ynh_psql_execute_as_root --sql="ALTER USER $db_user WITH SUPERUSER;" --database="$db_name"
|
||||
ynh_exec_warn_less ynh_exec_as $app env RAILS_ENV=production $ynh_ruby_load_path $ld_preload bin/bundle exec rake db:migrate
|
||||
ynh_psql_execute_as_root --sql="ALTER USER $db_user WITH NOSUPERUSER;" --database="$db_name"
|
||||
ynh_exec_warn_less ynh_exec_as $app env RAILS_ENV=production $ynh_ruby_load_path $ld_preload bin/bundle exec rake assets:precompile
|
||||
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn cache clean --all
|
||||
popd
|
||||
fi
|
||||
ynh_secure_remove --file="$install_dir/.cache"
|
||||
ynh_secure_remove --file="$install_dir/node_modules"
|
||||
ynh_secure_remove --file="$install_dir/tmp/cache"
|
||||
|
||||
#REMOVEME? ynh_install_app_dependencies $pkg_dependencies
|
||||
#REMOVEME? ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
|
||||
#REMOVEME? ynh_secure_remove --file="$install_dir/.cache"
|
||||
fabmanager_build_ruby
|
||||
|
||||
fabmanager_migrate_db
|
||||
|
||||
fabmanager_build_ui
|
||||
|
||||
#=================================================
|
||||
# SETUP SYSTEMD
|
||||
# REAPPLY SYSTEM CONFIGURATIONS
|
||||
#=================================================
|
||||
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
|
||||
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
|
||||
|
||||
# Create a dedicated NGINX config
|
||||
ynh_add_nginx_config
|
||||
|
||||
# Create a dedicated systemd config
|
||||
ynh_add_systemd_config --service="$app-app" --template="fab-manager-app.service"
|
||||
ynh_add_systemd_config --service="$app-worker" --template="fab-manager-worker.service"
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# INTEGRATE SERVICE IN YUNOHOST
|
||||
#=================================================
|
||||
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
||||
|
||||
yunohost service add "$app-app" --description="$app app service"
|
||||
yunohost service add "$app-worker" --description="$app worker service"
|
||||
|
||||
#=================================================
|
||||
# START SYSTEMD SERVICE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
||||
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
|
||||
|
||||
ynh_systemd_action --service_name=${app}-app --action="start" --log_path=systemd --line_match="Listening on"
|
||||
ynh_systemd_action --service_name=${app}-worker --action="start" --log_path=systemd --line_match="Schedules Loaded"
|
||||
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
||||
|
||||
#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
|
||||
ynh_systemd_action --service_name="${app}-app" --action="start" --log_path=systemd --line_match="Listening on"
|
||||
ynh_systemd_action --service_name="${app}-worker" --action="start" --log_path=systemd --line_match="Schedules Loaded"
|
||||
|
||||
#=================================================
|
||||
# END OF SCRIPT
|
||||
|
|
Loading…
Add table
Reference in a new issue