1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mastodon_ynh.git synced 2024-09-03 19:46:02 +02:00

Update scripts

This commit is contained in:
Tagadda 2023-07-08 19:19:03 +02:00
parent ec7d94005e
commit a0da3375f2
4 changed files with 104 additions and 187 deletions

View file

@ -11,22 +11,10 @@ source ynh_install_ruby__2
source ynh_add_swap
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
admin_mail=$(ynh_user_get_info --username=$admin --key=mail)
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing Ruby and NodeJS..." --weight=1
ynh_exec_warn_less ynh_install_ruby --ruby_version=$ruby_version
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
# APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC)
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
@ -38,15 +26,13 @@ ynh_setup_source --dest_dir="$install_dir/live"
chown -R $app:www-data "$install_dir"
#=================================================
# NGINX CONFIGURATION
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
ynh_script_progression --message="Installing Ruby and NodeJS..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
ynh_exec_warn_less ynh_install_ruby --ruby_version=$ruby_version
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
#=================================================
# SPECIFIC SETUP
#=================================================
# ADD SWAP IF NEEDED
#=================================================
@ -136,37 +122,32 @@ chmod 400 "$config"
chown $app:$app "$config"
#=================================================
# SETUP SYSTEMD
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=1
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
# Create a dedicated NGINX config using the conf/nginx.conf template
ynh_add_nginx_config
# Create a dedicated systemd config
ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service"
yunohost service add "$app-web" --description="$app web service"
ynh_add_systemd_config --service="$app-sidekiq" --template="mastodon-sidekiq.service"
yunohost service add "$app-sidekiq" --description="$app sidekiq service"
ynh_add_systemd_config --service="$app-streaming" --template="mastodon-streaming.service"
yunohost service add "$app-streaming" --description="$app streaming service"
#=================================================
# SETUP THE CRON FILE
#=================================================
ynh_script_progression --message="Setuping the cron file..." --weight=1
# Create a cron file
ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app"
#=================================================
# GENERIC FINALIZATION
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add "$app-web" --description="$app web service"
yunohost service add "$app-sidekiq" --description="$app sidekiq service"
yunohost service add "$app-streaming" --description="$app streaming service"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_script_progression --message="Starting all systemd services..." --weight=1
ynh_systemd_action --service_name=${app}-web --action="start" --log_path=systemd --line_match="Listening on"
ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=systemd --line_match="Schedules Loaded"

View file

@ -12,10 +12,11 @@ source ynh_add_swap
source /usr/share/yunohost/helpers
#=================================================
# STANDARD REMOVE
# REMOVE SYSTEM CONFIGURATIONS
#=================================================
# REMOVE SERVICE INTEGRATION IN YUNOHOST
# REMOVE SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1
# 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-web" >/dev/null
@ -36,53 +37,24 @@ then
yunohost service remove "$app-streaming"
fi
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1
# Remove the dedicated systemd config
ynh_remove_systemd_config --service="$app-web"
ynh_remove_systemd_config --service="$app-sidekiq"
ynh_remove_systemd_config --service="$app-streaming"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1
# Remove the dedicated NGINX config
ynh_remove_nginx_config
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing Ruby and NodeJS..." --weight=1
# Remove a cron file
ynh_secure_remove --file="/etc/cron.d/$app"
# Remove metapackage and its dependencies
ynh_remove_ruby
ynh_remove_nodejs
#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE VARIOUS FILES
#=================================================
ynh_script_progression --message="Removing various files..." --weight=1
# Remove a cron file
ynh_secure_remove --file="/etc/cron.d/$app"
# Remove swap
ynh_del_swap
#=================================================
# GENERIC FINALIZATION
#=================================================
# ...
#=================================================
#=================================================
# END OF SCRIPT
#=================================================

View file

@ -25,23 +25,6 @@ chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling Ruby and NodeJS..." --weight=1
ynh_exec_warn_less ynh_install_ruby --ruby_version=$ruby_version
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
#=================================================
# 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"
#=================================================
# RESTORE THE POSTGRESQL DATABASE
#=================================================
@ -66,6 +49,14 @@ fi
ynh_script_progression --message="Adding $swap_needed Mo to swap..." --weight=1
ynh_add_swap --size=$swap_needed
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling Ruby and NodeJS..." --weight=1
ynh_exec_warn_less ynh_install_ruby --ruby_version=$ruby_version
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
#=================================================
# BUILD APP
#=================================================
@ -79,46 +70,35 @@ pushd "$install_dir/live"
popd
#=================================================
# RESTORE VARIOUS FILES
# RESTORE SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Restoring various files..." --weight=1
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1
ynh_restore_file --origin_path="/etc/cron.d/$app"
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore_file --origin_path="/etc/systemd/system/$app-web.service"
ynh_restore_file --origin_path="/etc/systemd/system/$app-sidekiq.service"
ynh_restore_file --origin_path="/etc/systemd/system/$app-streaming.service"
systemctl enable "$app-web" "$app-sidekiq" "$app-streaming" --quiet
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add "$app-web" --description="$app web service"
yunohost service add "$app-sidekiq" --description="$app sidekiq service"
yunohost service add "$app-streaming" --description="$app streaming service"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=${app}-web --action="start" --log_path=systemd --line_match="Listening on"
ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=systemd --line_match="Schedules Loaded"
ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=systemd --line_match="Worker 1 now listening"
ynh_restore_file --origin_path="/etc/cron.d/$app"
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1
ynh_systemd_action --service_name=${app}-web --action="start" --log_path=systemd --line_match="Listening on"
ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=systemd --line_match="Schedules Loaded"
ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=systemd --line_match="Worker 1 now listening"
ynh_systemd_action --service_name=nginx --action=reload

View file

@ -11,32 +11,13 @@ source ynh_install_ruby__2
source ynh_add_swap
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading settings..." --weight=1
upgrade_type=$(ynh_check_app_version_changed)
admin_mail=$(ynh_user_get_info --username=$admin --key='mail')
config="$install_dir/live/.env.production"
#=================================================
# CHECK VERSION
#=================================================
ynh_script_progression --message="Checking version..." --weight=1
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name=${app}-web --action="stop" --log_path=systemd --line_match="Stopped"
ynh_systemd_action --service_name=${app}-sidekiq --action="stop" --log_path=systemd --line_match="Stopped"
ynh_systemd_action --service_name=${app}-streaming --action="stop" --log_path=systemd --line_match="Stopped"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
@ -81,39 +62,14 @@ fi
ynh_remove_extra_repo
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..." --weight=1
ynh_systemd_action --service_name=${app}-web --action="stop" --log_path=systemd --line_match="Stopped"
ynh_systemd_action --service_name=${app}-sidekiq --action="stop" --log_path=systemd --line_match="Stopped"
ynh_systemd_action --service_name=${app}-streaming --action="stop" --log_path=systemd --line_match="Stopped"
# Download Mastodon
ynh_setup_source --dest_dir="$install_dir/live" --keep="public/system/"
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
fi
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading Ruby and NodeJS..." --weight=1
ynh_exec_warn_less ynh_install_ruby --ruby_version=$ruby_version
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# SPECIFIC UPGRADE
#=================================================
# ADD SWAP IF NEEDED
#=================================================
@ -131,9 +87,35 @@ ynh_script_progression --message="Adding $swap_needed Mo to swap..."
ynh_add_swap --size=$swap_needed
#=================================================
# BUILD APP
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Building app..." --weight=1
ynh_script_progression --message="Upgrading Ruby and NodeJS..." --weight=1
ynh_exec_warn_less ynh_install_ruby --ruby_version=$ruby_version
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
#=================================================
# "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD...)
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..." --weight=1
# Download Mastodon
ynh_setup_source --dest_dir="$install_dir/live" --keep="public/system/"
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
fi
#=================================================
# BUILD ASSETS
#=================================================
ynh_script_progression --message="Building assets..." --weight=1
pushd "$install_dir/live"
ynh_use_ruby
@ -147,10 +129,29 @@ pushd "$install_dir/live"
ynh_exec_as $app $ynh_node_load_PATH yarn install --pure-lockfile
ynh_exec_warn_less ynh_exec_as $app RAILS_ENV=production $ynh_ruby_load_path $ld_preload bin/bundle exec rails assets:clean
ynh_exec_warn_less ynh_exec_as $app RAILS_ENV=production $ynh_ruby_load_path $ld_preload bin/bundle exec rails assets:precompile
ynh_exec_warn_less ynh_exec_as $app RAILS_ENV=production $ynh_ruby_load_path $ld_preload bin/bundle exec rails db:migrate
ynh_exec_warn_less ynh_exec_as $app RAILS_ENV=production $ynh_ruby_load_path $ld_preload bin/tootctl cache clear
popd
#=================================================
# REAPPLY SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
ynh_add_nginx_config
# Create a dedicated systemd config
ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service"
yunohost service add "$app-web" --description="$app web service"
ynh_add_systemd_config --service="$app-sidekiq" --template="mastodon-sidekiq.service"
yunohost service add "$app-sidekiq" --description="$app sidekiq service"
ynh_add_systemd_config --service="$app-streaming" --template="mastodon-streaming.service"
yunohost service add "$app-streaming" --description="$app streaming service"
ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app"
#=================================================
# RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...)
#=================================================
# UPDATE A CONFIG FILE
#=================================================
@ -164,32 +165,15 @@ chmod 400 "$config"
chown $app:$app "$config"
#=================================================
# SETUP SYSTEMD
# APPLY MIGRATIONS
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
ynh_script_progression --message="Applying migrations..." --weight=1
# Create a dedicated systemd config
ynh_add_systemd_config --service="$app-web" --template="mastodon-web.service"
ynh_add_systemd_config --service="$app-sidekiq" --template="mastodon-sidekiq.service"
ynh_add_systemd_config --service="$app-streaming" --template="mastodon-streaming.service"
#=================================================
# SETUP THE CRON FILE
#=================================================
ynh_script_progression --message="Setuping the cron file..." --weight=1
ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app"
#=================================================
# GENERIC FINALIZATION
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add "$app-web" --description="$app web service"
yunohost service add "$app-sidekiq" --description="$app sidekiq service"
yunohost service add "$app-streaming" --description="$app streaming service"
pushd "$install_dir/live"
ynh_use_ruby
ynh_exec_warn_less ynh_exec_as $app RAILS_ENV=production $ynh_ruby_load_path $ld_preload bin/bundle exec rails db:migrate
ynh_exec_warn_less ynh_exec_as $app RAILS_ENV=production $ynh_ruby_load_path $ld_preload bin/tootctl cache clear
popd
#=================================================
# START SYSTEMD SERVICE