1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/fab-manager_ynh.git synced 2024-09-03 18:36:16 +02:00
This commit is contained in:
YunoHost Bot 2024-08-30 20:53:17 +00:00 committed by GitHub
commit 0f2c440707
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 152 additions and 171 deletions

View file

@ -7,7 +7,7 @@ Type=simple
User=__APP__ User=__APP__
WorkingDirectory=__INSTALL_DIR__ WorkingDirectory=__INSTALL_DIR__
Environment="__LD_PRELOAD__" Environment="__LD_PRELOAD__"
Environment="__YNH_RUBY_LOAD_PATH__" Environment="PATH=__PATH_WITH_RUBY__"
Environment="RAILS_ENV=production" Environment="RAILS_ENV=production"
ExecStartPre=-rm -f __INSTALL_DIR__/tmp/pids/server.pid ExecStartPre=-rm -f __INSTALL_DIR__/tmp/pids/server.pid
ExecStart=__INSTALL_DIR__/bin/bundle exec rails s puma -p __PORT__ -b 127.0.0.1 ExecStart=__INSTALL_DIR__/bin/bundle exec rails s puma -p __PORT__ -b 127.0.0.1

View file

@ -7,7 +7,7 @@ Type=simple
User=__APP__ User=__APP__
WorkingDirectory=__INSTALL_DIR__ WorkingDirectory=__INSTALL_DIR__
Environment="__LD_PRELOAD__" Environment="__LD_PRELOAD__"
Environment="__YNH_RUBY_LOAD_PATH__" Environment="PATH=__PATH_WITH_RUBY__"
Environment="RAILS_ENV=production" Environment="RAILS_ENV=production"
ExecStart=__INSTALL_DIR__/bin/bundle exec sidekiq -C __INSTALL_DIR__/config/sidekiq.yml ExecStart=__INSTALL_DIR__/bin/bundle exec sidekiq -C __INSTALL_DIR__/config/sidekiq.yml
TimeoutSec=15 TimeoutSec=15

View file

@ -19,7 +19,8 @@ admindoc = "http://doc.fab.mn"
code = "https://github.com/sleede/fab-manager" code = "https://github.com/sleede/fab-manager"
[integration] [integration]
yunohost = ">= 11.2.12" yunohost = ">= 11.2.18"
helpers_version = "2.1"
architectures = "all" architectures = "all"
multi_instance = false multi_instance = false
ldap = false ldap = false
@ -55,6 +56,7 @@ ram.runtime = "50M"
allow_email = true allow_email = true
[resources.install_dir] [resources.install_dir]
group = "www-data:r-x"
[resources.data_dir] [resources.data_dir]

View file

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
#================================================= #=================================================
# COMMON VARIABLES # COMMON VARIABLES AND CUSTOM HELPERS
#================================================= #=================================================
ruby_version="2.6.10" ruby_version="2.6.10"
@ -23,53 +23,40 @@ else
ld_preload="" ld_preload=""
fi fi
#=================================================
# PERSONAL HELPERS
#=================================================
fabmanager_build_ruby() { fabmanager_build_ruby() {
pushd "$install_dir" pushd "$install_dir"
ynh_use_ruby
ynh_exec_warn_less $ynh_gem install "bundler:$bundler_version" ynh_hide_warnings gem install "bundler:$bundler_version"
ynh_exec_warn_less bin/bundle config --global frozen 1 ynh_hide_warnings bin/bundle config --global frozen 1
ynh_exec_warn_less bin/bundle config set --local without 'development test doc' ynh_hide_warnings bin/bundle config set --local without 'development test doc'
ynh_exec_warn_less bin/bundle install ynh_hide_warnings bin/bundle install
ynh_exec_warn_less bin/bundle binstubs --all ynh_hide_warnings bin/bundle binstubs --all
popd popd
} }
fabmanager_seed_db() { fabmanager_seed_db() {
pushd "$install_dir" pushd "$install_dir"
ynh_replace_string --match_string="DateTime.current" --replace_string="DateTime.current - 1.days" --target_file="$install_dir/db/seeds.rb" ynh_replace --match="DateTime.current" --replace="DateTime.current - 1.days" --file="$install_dir/db/seeds.rb"
ynh_exec_warn_less ynh_exec_as "$app" env RAILS_ENV=production "$ynh_ruby_load_path" $ld_preload \ ynh_hide_warnings ynh_exec_as_app RAILS_ENV=production ruby_load_path" $ld_preload \
bin/bundle exec rake db:seed ADMIN_EMAIL="$admin_mail" ADMIN_PASSWORD="$password" bin/bundle exec rake db:seed ADMIN_EMAIL="$admin_mail" ADMIN_PASSWORD="$password"
popd popd
} }
fabmanager_migrate_db() { fabmanager_migrate_db() {
pushd "$install_dir" pushd "$install_dir"
ynh_psql_execute_as_root --database="$db_name" --sql="ALTER USER $db_user WITH SUPERUSER;" ynh_psql_db_shell <<< "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_hide_warnings ynh_exec_as_app RAILS_ENV=production 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;" ynh_psql_db_shell <<< "ALTER USER $db_user WITH NOSUPERUSER;"
popd popd
} }
fabmanager_build_ui() { fabmanager_build_ui() {
pushd "$install_dir" pushd "$install_dir"
ynh_use_nodejs
ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" yarn install ynh_hide_warnings ynh_exec_as_app 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_hide_warnings ynh_exec_as_app RAILS_ENV=production 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_hide_warnings ynh_exec_as_app RAILS_ENV=production 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_hide_warnings ynh_exec_as_app RAILS_ENV=production 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 ynh_hide_warnings ynh_exec_as_app node_load_PATH" yarn cache clean --all
popd popd
} }
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================

View file

@ -8,41 +8,38 @@
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= ynh_print_info "Declaring files to be backed up..."
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
#================================================= #=================================================
# BACKUP THE APP MAIN DIR # BACKUP THE APP MAIN DIR
#================================================= #=================================================
ynh_backup --src_path="$install_dir" ynh_backup "$install_dir"
#================================================= #=================================================
# BACKUP THE DATA DIR # BACKUP THE DATA DIR
#================================================= #=================================================
ynh_backup --src_path="$data_dir" --is_big ynh_backup "$data_dir"
#================================================= #=================================================
# BACKUP THE SYSTEM CONFIGURATION # BACKUP THE SYSTEM CONFIGURATION
#================================================= #=================================================
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup --src_path="/etc/systemd/system/$app-app.service" ynh_backup "/etc/systemd/system/$app-app.service"
ynh_backup --src_path="/etc/systemd/system/$app-worker.service" ynh_backup "/etc/systemd/system/$app-worker.service"
#================================================= #=================================================
# BACKUP THE POSTGRESQL DATABASE # BACKUP THE POSTGRESQL DATABASE
#================================================= #=================================================
ynh_print_info --message="Backing up the PostgreSQL database..." ynh_print_info "Backing up the PostgreSQL database..."
ynh_psql_dump_db --database="$db_name" > db.sql ynh_psql_dump_db > db.sql
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -16,40 +16,38 @@ admin_mail=$(ynh_user_get_info --username="$admin" --key=mail)
#================================================= #=================================================
# STOP SYSTEMD SERVICE # STOP SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_script_progression "Stopping $app's systemd service..."
ynh_systemd_action --service_name="${app}-app" --action="stop" --log_path=systemd ynh_systemctl --service="${app}-app" --action="stop" --log_path=systemd
ynh_systemd_action --service_name="${app}-worker" --action="stop" --log_path=systemd ynh_systemctl --service="${app}-worker" --action="stop" --log_path=systemd
#================================================= #=================================================
# MODIFY URL IN NGINX CONF # MODIFY URL IN NGINX CONF
#================================================= #=================================================
ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 ynh_script_progression "Updating NGINX web server configuration..."
ynh_change_url_nginx_config ynh_config_change_url_nginx
#================================================= #=================================================
# UPDATE A CONFIG FILE # UPDATE A CONFIG FILE
#================================================= #=================================================
ynh_script_progression --message="Updating a configuration file..." --weight=1 ynh_script_progression "Updating configuration..."
ynh_add_config --template="secrets.yml" --destination="$install_dir/config/secrets.yml" ynh_config_add --template="secrets.yml" --destination="$install_dir/config/secrets.yml"
chmod 400 "$install_dir/config/secrets.yml" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/config/secrets.yml"
chown "$app:$app" "$install_dir/config/secrets.yml" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app:$app" "$install_dir/config/secrets.yml"
#=================================================
# GENERIC FINALISATION
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression "Starting $app's systemd service..."
# Start a systemd service # Start a systemd service
ynh_systemd_action --service_name="${app}-app" --action="start" --log_path=systemd ynh_systemctl --service="${app}-app" --action="start" --log_path=systemd
ynh_systemd_action --service_name="${app}-worker" --action="start" --log_path=systemd --line_match="Schedules Loaded" ynh_systemctl --service="${app}-worker" --action="start" --log_path=systemd --wait_until="Schedules Loaded"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Change of URL completed for $app" --last ynh_script_progression "Change of URL completed for $app"

View file

@ -14,59 +14,58 @@ source /usr/share/yunohost/helpers
admin_mail=$(ynh_user_get_info --username="$admin" --key=mail) admin_mail=$(ynh_user_get_info --username="$admin" --key=mail)
secret_key_base=$(ynh_string_random --length=30) secret_key_base=$(ynh_string_random --length=30)
ynh_app_setting_set --app="$app" --key="secret_key_base" --value="$secret_key_base" ynh_app_setting_set --key="secret_key_base" --value="$secret_key_base"
#================================================= #=================================================
# INSTALL DEPENDENCIES # INSTALL DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Installing NodeJS..." --weight=1 ynh_script_progression "Installing NodeJS..."
ynh_exec_warn_less ynh_install_nodejs --nodejs_version="$nodejs_version" ynh_nodejs_install
ynh_script_progression --message="Installing Ruby..." --weight=4 ynh_script_progression "Installing Ruby..."
ynh_exec_warn_less ynh_install_ruby --ruby_version="$ruby_version" ynh_ruby_install
#================================================= #=================================================
# CREATE A POSTGRESQL DATABASE # CREATE A POSTGRESQL DATABASE
#================================================= #=================================================
ynh_script_progression --message="Configuring $app's PostgreSQL database..." --weight=1 ynh_script_progression "Configuring $app's PostgreSQL database..."
ynh_psql_execute_as_root --database="$db_name" --sql="ALTER USER $db_user WITH SUPERUSER;" ynh_psql_db_shell <<< "ALTER USER $db_user WITH SUPERUSER;"
ynh_psql_execute_as_root --database="$db_name" --sql="CREATE EXTENSION IF NOT EXISTS unaccent;" ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS unaccent;"
ynh_psql_execute_as_root --database="$db_name" --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS pg_trgm;"
ynh_psql_execute_as_root --database="$db_name" --sql="CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;" ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;"
ynh_psql_execute_as_root --database="$db_name" --sql="ALTER USER $db_user WITH NOSUPERUSER;" ynh_psql_db_shell <<< "ALTER USER $db_user WITH NOSUPERUSER;"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_script_progression --message="Setting up source files..." --weight=1 ynh_script_progression "Setting up source files..."
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir" ynh_setup_source --dest_dir="$install_dir"
chmod -R o-rwx "$install_dir" #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
chown -R "$app:www-data" "$install_dir" #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:www-data" "$install_dir"
chmod -R o-rwx "$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 # ADD A CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=1 ynh_script_progression "Adding $app's configuration..."
ynh_add_config --template="secrets.yml" --destination="$install_dir/config/secrets.yml" ynh_config_add --template="secrets.yml" --destination="$install_dir/config/secrets.yml"
chmod 400 "$install_dir/config/secrets.yml" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/config/secrets.yml"
chown "$app:$app" "$install_dir/config/secrets.yml" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app:$app" "$install_dir/config/secrets.yml"
ynh_add_config --template="database.yml" --destination="$install_dir/config/database.yml" ynh_config_add --template="database.yml" --destination="$install_dir/config/database.yml"
chmod 400 "$install_dir/config/database.yml" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/config/database.yml"
chown "$app:$app" "$install_dir/config/database.yml" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app:$app" "$install_dir/config/database.yml"
#================================================= #=================================================
# BUILD APP # BUILD APP
#================================================= #=================================================
ynh_script_progression --message="Building app..." --weight=7 ynh_script_progression "Building app..."
fabmanager_build_ruby fabmanager_build_ruby
@ -75,32 +74,32 @@ fabmanager_seed_db
fabmanager_build_ui fabmanager_build_ui
ynh_secure_remove --file="$install_dir/.cache" ynh_safe_rm "$install_dir/.cache"
#================================================= #=================================================
# SYSTEM CONFIGURATION # SYSTEM CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 ynh_script_progression "Adding system configurations related to $app..."
# Create a dedicated NGINX config # Create a dedicated NGINX config
ynh_add_nginx_config ynh_config_add_nginx
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config --service="$app-app" --template="fab-manager-app.service" ynh_config_add_systemd --service="$app-app" --template="fab-manager-app.service"
yunohost service add "$app-app" --description="$app app service" yunohost service add "$app-app" --description="$app app service"
ynh_add_systemd_config --service="$app-worker" --template="fab-manager-worker.service" ynh_config_add_systemd --service="$app-worker" --template="fab-manager-worker.service"
yunohost service add "$app-worker" --description="$app worker service" yunohost service add "$app-worker" --description="$app worker service"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting $app's systemd service..." --weight=1 ynh_script_progression "Starting $app's systemd service..."
ynh_systemd_action --service_name="${app}-app" --action="start" --log_path=systemd ynh_systemctl --service="${app}-app" --action="start" --log_path=systemd
ynh_systemd_action --service_name="${app}-worker" --action="start" --log_path=systemd --line_match="Schedules Loaded" ynh_systemctl --service="${app}-worker" --action="start" --log_path=systemd --wait_until="Schedules Loaded"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Installation of $app completed" --last ynh_script_progression "Installation of $app completed"

View file

@ -10,29 +10,29 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# REMOVE SYSTEM CONFIGURATIONS # REMOVE SYSTEM CONFIGURATIONS
#================================================= #=================================================
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 ynh_script_progression "Removing system configurations related to $app..."
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`) # Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
if ynh_exec_warn_less yunohost service status "$app-app" >/dev/null; then if ynh_hide_warnings yunohost service status "$app-app" >/dev/null; then
yunohost service remove "$app-app" yunohost service remove "$app-app"
fi fi
if ynh_exec_warn_less yunohost service status "$app-worker" >/dev/null; then if ynh_hide_warnings yunohost service status "$app-worker" >/dev/null; then
yunohost service remove "$app-worker" yunohost service remove "$app-worker"
fi fi
# Remove the dedicated systemd config # Remove the dedicated systemd config
ynh_remove_systemd_config --service="$app-app" ynh_config_remove_systemd"$app-app"
ynh_remove_systemd_config --service="$app-worker" ynh_config_remove_systemd"$app-worker"
# Remove the dedicated NGINX config # Remove the dedicated NGINX config
ynh_remove_nginx_config ynh_config_remove_nginx
ynh_remove_ruby ynh_ruby_remove
ynh_remove_nodejs ynh_nodejs_remove
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Removal of $app completed" --last ynh_script_progression "Removal of $app completed"

View file

@ -11,28 +11,27 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# INSTALL DEPENDENCIES # INSTALL DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Reinstalling NodeJS..." --weight=1 ynh_script_progression "Reinstalling NodeJS..."
ynh_exec_warn_less ynh_install_nodejs --nodejs_version="$nodejs_version" ynh_nodejs_install
ynh_script_progression --message="Reinstalling Ruby..." --weight=4 ynh_script_progression "Reinstalling Ruby..."
ynh_exec_warn_less ynh_install_ruby --ruby_version="$ruby_version" ynh_ruby_install
#================================================= #=================================================
# RESTORE THE APP MAIN DIR # RESTORE THE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=1 ynh_script_progression "Restoring the app main directory..."
ynh_restore_file --origin_path="$install_dir" ynh_restore "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:www-data "$install_dir"
#================================================= #=================================================
# RESTORE THE DATA DIRECTORY # RESTORE THE DATA DIRECTORY
#================================================= #=================================================
ynh_script_progression --message="Restoring the data directory..." --weight=1 ynh_script_progression "Restoring the data directory..."
ynh_restore_file --origin_path="$data_dir" --not_mandatory ynh_restore "$data_dir"
chmod -R o-rwx "$data_dir" chmod -R o-rwx "$data_dir"
chown -R "$app:www-data" "$data_dir" chown -R "$app:www-data" "$data_dir"
@ -40,20 +39,20 @@ chown -R "$app:www-data" "$data_dir"
#================================================= #=================================================
# RESTORE THE POSTGRESQL DATABASE # RESTORE THE POSTGRESQL DATABASE
#================================================= #=================================================
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1 ynh_script_progression "Restoring the PostgreSQL database..."
ynh_psql_execute_as_root --database="$db_name" --sql="ALTER USER $db_user WITH SUPERUSER;" ynh_psql_db_shell <<< "ALTER USER $db_user WITH SUPERUSER;"
ynh_psql_execute_as_root --database="$db_name" --sql="CREATE EXTENSION IF NOT EXISTS unaccent;" ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS unaccent;"
ynh_psql_execute_as_root --database="$db_name" --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS pg_trgm;"
ynh_psql_execute_as_root --database="$db_name" --sql="CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;" ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;"
ynh_psql_execute_as_root --database="$db_name" --sql="ALTER USER $db_user WITH NOSUPERUSER;" ynh_psql_db_shell <<< "ALTER USER $db_user WITH NOSUPERUSER;"
ynh_psql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < ./db.sql ynh_psql_db_shell < ./db.sql
#================================================= #=================================================
# BUILD APP # BUILD APP
#================================================= #=================================================
ynh_script_progression --message="Building app..." --weight=7 ynh_script_progression "Building app..."
fabmanager_build_ruby fabmanager_build_ruby
@ -62,12 +61,12 @@ fabmanager_build_ui
#================================================= #=================================================
# RESTORE SYSTEM CONFIGURATIONS # RESTORE SYSTEM CONFIGURATIONS
#================================================= #=================================================
ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 ynh_script_progression "Restoring system configurations related to $app..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore_file --origin_path="/etc/systemd/system/$app-app.service" ynh_restore "/etc/systemd/system/$app-app.service"
ynh_restore_file --origin_path="/etc/systemd/system/$app-worker.service" ynh_restore "/etc/systemd/system/$app-worker.service"
systemctl enable "$app-app" "$app-worker" --quiet systemctl enable "$app-app" "$app-worker" --quiet
yunohost service add "$app-app" --description="$app app service" yunohost service add "$app-app" --description="$app app service"
yunohost service add "$app-worker" --description="$app worker service" yunohost service add "$app-worker" --description="$app worker service"
@ -75,20 +74,20 @@ yunohost service add "$app-worker" --description="$app worker service"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting $app's systemd service..." --weight=1 ynh_script_progression "Starting $app's systemd service..."
ynh_systemd_action --service_name="${app}-app" --action="start" --log_path=systemd ynh_systemctl --service="${app}-app" --action="start" --log_path=systemd
ynh_systemd_action --service_name="${app}-worker" --action="start" --log_path=systemd --line_match="Schedules Loaded" ynh_systemctl --service="${app}-worker" --action="start" --log_path=systemd --wait_until="Schedules Loaded"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_script_progression "Reloading NGINX web server..."
ynh_systemd_action --service_name=nginx --action=reload ynh_systemctl --service=nginx --action=reload
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Restoration completed for $app" --last ynh_script_progression "Restoration completed for $app"

View file

@ -16,70 +16,69 @@ admin_mail=$(ynh_user_get_info --username="$admin" --key=mail)
#================================================= #=================================================
# STOP SYSTEMD SERVICE # STOP SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Stopping $app's systemd service..." --weight=1 ynh_script_progression "Stopping $app's systemd service..."
ynh_systemd_action --service_name="${app}-app" --action="stop" --log_path=systemd ynh_systemctl --service="${app}-app" --action="stop" --log_path=systemd
ynh_systemd_action --service_name="${app}-worker" --action="stop" --log_path=systemd ynh_systemctl --service="${app}-worker" --action="stop" --log_path=systemd
#================================================= #=================================================
# ENSURE DOWNWARD COMPATIBILITY # ENSURE DOWNWARD COMPATIBILITY
#================================================= #=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 ynh_script_progression "Ensuring downward compatibility..."
if ynh_exec_warn_less yunohost service status "$app" >/dev/null; then if ynh_hide_warnings yunohost service status "$app" >/dev/null; then
ynh_script_progression --message="Removing $app service integration..." ynh_script_progression "Removing $app service integration..."
yunohost service remove "$app" yunohost service remove "$app"
fi fi
ynh_remove_logrotate ynh_config_remove_logrotate
ynh_secure_remove --file="/etc/supervisor/conf.d/$app.conf" ynh_safe_rm "/etc/supervisor/conf.d/$app.conf"
ynh_secure_remove --file="/var/log/supervisor/$app-app-stderr.log" ynh_safe_rm "/var/log/supervisor/$app-app-stderr.log"
ynh_secure_remove --file="/var/log/supervisor/$app-app-stdout.log" ynh_safe_rm "/var/log/supervisor/$app-app-stdout.log"
ynh_secure_remove --file="/var/log/supervisor/$app-worker-stderr.log" ynh_safe_rm "/var/log/supervisor/$app-worker-stderr.log"
ynh_secure_remove --file="/var/log/supervisor/$app-worker-stdout.log" ynh_safe_rm "/var/log/supervisor/$app-worker-stdout.log"
#================================================= #=================================================
# INSTALL DEPENDENCIES # INSTALL DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Updating NodeJS..." --weight=1 ynh_script_progression "Updating NodeJS..."
ynh_exec_warn_less ynh_install_nodejs --nodejs_version="$nodejs_version" ynh_nodejs_install
ynh_script_progression --message="Updating Ruby..." --weight=4 ynh_script_progression "Updating Ruby..."
ynh_exec_warn_less ynh_install_ruby --ruby_version="$ruby_version" ynh_ruby_install
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_script_progression --message="Upgrading source files..." --weight=1 ynh_script_progression "Upgrading source files..."
# Download, check integrity, uncompress and patch the source from app.src # 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" ynh_setup_source --dest_dir="$install_dir" --full_replace --keep="config/secrets.yml config/database.yml"
chmod -R o-rwx "$install_dir"
chown -R "$app:www-data" "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:www-data" "$install_dir"
#================================================= #=================================================
# UPDATE A CONFIG FILE # UPDATE A CONFIG FILE
#================================================= #=================================================
ynh_script_progression --message="Updating a configuration file..." --weight=1 ynh_script_progression "Updating configuration..."
ynh_add_config --template="secrets.yml" --destination="$install_dir/config/secrets.yml" ynh_config_add --template="secrets.yml" --destination="$install_dir/config/secrets.yml"
chmod 400 "$install_dir/config/secrets.yml" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/config/secrets.yml"
chown "$app:$app" "$install_dir/config/secrets.yml" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app:$app" "$install_dir/config/secrets.yml"
ynh_add_config --template="database.yml" --destination="$install_dir/config/database.yml" ynh_config_add --template="database.yml" --destination="$install_dir/config/database.yml"
chmod 400 "$install_dir/config/database.yml" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/config/database.yml"
chown "$app:$app" "$install_dir/config/database.yml" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app:$app" "$install_dir/config/database.yml"
#================================================= #=================================================
# BUILD APP # BUILD APP
#================================================= #=================================================
ynh_script_progression --message="Building app..." --weight=7 ynh_script_progression "Building app..."
ynh_secure_remove --file="$install_dir/.cache" ynh_safe_rm "$install_dir/.cache"
ynh_secure_remove --file="$install_dir/node_modules" ynh_safe_rm "$install_dir/node_modules"
ynh_secure_remove --file="$install_dir/tmp/cache" ynh_safe_rm "$install_dir/tmp/cache"
fabmanager_build_ruby fabmanager_build_ruby
@ -90,27 +89,27 @@ fabmanager_build_ui
#================================================= #=================================================
# REAPPLY SYSTEM CONFIGURATIONS # REAPPLY SYSTEM CONFIGURATIONS
#================================================= #=================================================
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 ynh_script_progression "Upgrading system configurations related to $app..."
# Create a dedicated NGINX config # Create a dedicated NGINX config
ynh_add_nginx_config ynh_config_add_nginx
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config --service="$app-app" --template="fab-manager-app.service" ynh_config_add_systemd --service="$app-app" --template="fab-manager-app.service"
ynh_add_systemd_config --service="$app-worker" --template="fab-manager-worker.service" ynh_config_add_systemd --service="$app-worker" --template="fab-manager-worker.service"
yunohost service add "$app-app" --description="$app app service" yunohost service add "$app-app" --description="$app app service"
yunohost service add "$app-worker" --description="$app worker service" yunohost service add "$app-worker" --description="$app worker service"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting $app's systemd service..." --weight=1 ynh_script_progression "Starting $app's systemd service..."
ynh_systemd_action --service_name="${app}-app" --action="start" --log_path=systemd ynh_systemctl --service="${app}-app" --action="start" --log_path=systemd
ynh_systemd_action --service_name="${app}-worker" --action="start" --log_path=systemd --line_match="Schedules Loaded" ynh_systemctl --service="${app}-worker" --action="start" --log_path=systemd --wait_until="Schedules Loaded"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Upgrade of $app completed" --last ynh_script_progression "Upgrade of $app completed"