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

cleanup, applying template

This commit is contained in:
Salamandar 2024-03-24 20:52:46 +01:00
parent 68cab1761b
commit 79865d0fc3
5 changed files with 135 additions and 187 deletions

View file

@ -1,7 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#================================================= #=================================================
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
@ -22,23 +20,13 @@ ynh_print_info --message="Declaring files to be backed up..."
ynh_backup --src_path="$install_dir" ynh_backup --src_path="$install_dir"
#================================================= #=================================================
# BACKUP THE NGINX CONFIGURATION # BACKUP THE SYSTEM CONFIGURATION
#================================================= #=================================================
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP LOGROTATE
#=================================================
ynh_backup --src_path="/etc/logrotate.d/$app" ynh_backup --src_path="/etc/logrotate.d/$app"
#=================================================
# BACKUP SYSTEMD
#=================================================
ynh_backup --src_path="/etc/systemd/system/$app-web.service" ynh_backup --src_path="/etc/systemd/system/$app-web.service"
ynh_backup --src_path="/etc/systemd/system/$app-sidekiq.service" ynh_backup --src_path="/etc/systemd/system/$app-sidekiq.service"
ynh_backup --src_path="/etc/systemd/system/$app-streaming.service" ynh_backup --src_path="/etc/systemd/system/$app-streaming.service"
@ -49,6 +37,8 @@ ynh_backup --src_path="/etc/systemd/system/$app-streaming.service"
ynh_backup --src_path="/etc/cron.d/$app" ynh_backup --src_path="/etc/cron.d/$app"
ynh_backup --src_path="/var/log/$app/"
#================================================= #=================================================
# BACKUP THE POSTGRESQL DATABASE # BACKUP THE POSTGRESQL DATABASE
#================================================= #=================================================

View file

@ -1,7 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#================================================= #=================================================
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
@ -11,7 +9,11 @@ source ynh_install_ruby__2
source ynh_add_swap source ynh_add_swap
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
admin_mail=$(ynh_user_get_info --username=$admin --key=mail) #=================================================
# INITIALIZE AND STORE SETTINGS
#=================================================
admin_mail=$(ynh_user_get_info --username="$admin" --key=mail)
# Initialize config_panel settings :< # Initialize config_panel settings :<
max_toot_chars="500" max_toot_chars="500"
@ -25,46 +27,37 @@ max_image_size="8388608"
max_video_size="41943040" max_video_size="41943040"
max_emoji_size="51200" max_emoji_size="51200"
max_remote_emoji_size="204800" max_remote_emoji_size="204800"
ynh_app_setting_set --app=$app --key=max_toot_chars --value=$max_toot_chars ynh_app_setting_set --app="$app" --key="max_toot_chars" --value="$max_toot_chars"
ynh_app_setting_set --app=$app --key=max_pinned_toots --value=$max_pinned_toots ynh_app_setting_set --app="$app" --key="max_pinned_toots" --value="$max_pinned_toots"
ynh_app_setting_set --app=$app --key=max_bio_chars --value=$max_bio_chars ynh_app_setting_set --app="$app" --key="max_bio_chars" --value="$max_bio_chars"
ynh_app_setting_set --app=$app --key=max_profile_fields --value=$max_profile_fields ynh_app_setting_set --app="$app" --key="max_profile_fields" --value="$max_profile_fields"
ynh_app_setting_set --app=$app --key=max_display_name_chars --value=$max_display_name_chars ynh_app_setting_set --app="$app" --key="max_display_name_chars" --value="$max_display_name_chars"
ynh_app_setting_set --app=$app --key=max_poll_options --value=$max_poll_options ynh_app_setting_set --app="$app" --key="max_poll_options" --value="$max_poll_options"
ynh_app_setting_set --app=$app --key=max_poll_option_chars --value=$max_poll_option_chars ynh_app_setting_set --app="$app" --key="max_poll_option_chars" --value="$max_poll_option_chars"
ynh_app_setting_set --app=$app --key=max_image_size --value=$max_image_size ynh_app_setting_set --app="$app" --key="max_image_size" --value="$max_image_size"
ynh_app_setting_set --app=$app --key=max_video_size --value=$max_video_size ynh_app_setting_set --app="$app" --key="max_video_size" --value="$max_video_size"
ynh_app_setting_set --app=$app --key=max_emoji_size --value=$max_emoji_size ynh_app_setting_set --app="$app" --key="max_emoji_size" --value="$max_emoji_size"
ynh_app_setting_set --app=$app --key=max_remote_emoji_size --value=$max_remote_emoji_size ynh_app_setting_set --app="$app" --key="max_remote_emoji_size" --value="$max_remote_emoji_size"
# Set `service` settings to support `yunohost app shell` command # Set `service` settings to support `yunohost app shell` command
ynh_app_setting_set --app="$app" --key=service --value="$app-web.service" ynh_app_setting_set --app="$app" --key=service --value="$app-web.service"
# Find an available port redis_namespace=${app}_production
port_web=$(ynh_find_port --port=3000) ynh_app_setting_set --app="$app" --key=redis_namespace --value="$redis_namespace"
ynh_app_setting_set --app=$app --key=port_web --value=$port_web
port_stream=$(ynh_find_port --port=4000) secret_key_base=$(ynh_string_random --length=128)
ynh_app_setting_set --app=$app --key=port_stream --value=$port_stream ynh_app_setting_set --app="$app" --key=secret_key_base --value="$secret_key_base"
#================================================= otp_secret=$(ynh_string_random --length=128)
# APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC) ynh_app_setting_set --app="$app" --key=otp_secret --value="$otp_secret"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=1
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir/live"
chown -R $app:www-data "$install_dir"
#================================================= #=================================================
# INSTALL DEPENDENCIES # INSTALL DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Installing Ruby and NodeJS..." --weight=1 ynh_script_progression --message="Installing Ruby..." --weight=1
ynh_exec_warn_less ynh_install_ruby --ruby_version=$ruby_version ynh_exec_warn_less ynh_install_ruby --ruby_version=$ruby_version
ynh_script_progression --message="Installing NodeJS..." --weight=1
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
#================================================= #=================================================
@ -84,6 +77,16 @@ ynh_script_progression --message="Adding $swap_needed Mo to swap..." --weight=1
ynh_add_swap --size=$swap_needed ynh_add_swap --size=$swap_needed
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=1
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir/live"
chown -R "$app:www-data" "$install_dir"
#================================================= #=================================================
# ADD A CONFIGURATION # ADD A CONFIGURATION
#================================================= #=================================================
@ -93,22 +96,13 @@ config="$install_dir/live/.env.production"
language="$(echo $language | head -c 2)" language="$(echo $language | head -c 2)"
redis_namespace=${app}_production
ynh_app_setting_set --app="$app" --key=redis_namespace --value="$redis_namespace"
secret_key_base=$(ynh_string_random --length=128)
ynh_app_setting_set --app="$app" --key=secret_key_base --value="$secret_key_base"
otp_secret=$(ynh_string_random --length=128)
ynh_app_setting_set --app="$app" --key=otp_secret --value="$otp_secret"
# We need rake to build vapid keys, we generate them later once the app is installed # We need rake to build vapid keys, we generate them later once the app is installed
vapid_private_key="" vapid_private_key=""
vapid_public_key="" vapid_public_key=""
ynh_add_config --template=".env.production.sample" --destination="$config" ynh_add_config --template=".env.production.sample" --destination="$config"
chmod 400 "$config" chmod 400 "$config"
chown $app:$app "$config" chown "$app:$app" "$config"
ynh_replace_string --match_string="registrations_mode: 'open'" --replace_string="registrations_mode: 'none'" --target_file="$install_dir/live/config/settings.yml" ynh_replace_string --match_string="registrations_mode: 'open'" --replace_string="registrations_mode: 'none'" --target_file="$install_dir/live/config/settings.yml"
ynh_replace_string --match_string="min_invite_role: 'admin'" --replace_string="min_invite_role: 'none'" --target_file="$install_dir/live/config/settings.yml" ynh_replace_string --match_string="min_invite_role: 'admin'" --replace_string="min_invite_role: 'none'" --target_file="$install_dir/live/config/settings.yml"
@ -116,7 +110,7 @@ ynh_replace_string --match_string="min_invite_role: 'admin'" --replace_string="m
ynh_store_file_checksum --file="$install_dir/live/config/settings.yml" ynh_store_file_checksum --file="$install_dir/live/config/settings.yml"
chmod 400 "$install_dir/live/config/settings.yml" chmod 400 "$install_dir/live/config/settings.yml"
chown $app:$app "$install_dir/live/config/settings.yml" chown "$app:$app" "$install_dir/live/config/settings.yml"
#================================================= #=================================================
# BUILD APP # BUILD APP
@ -128,21 +122,22 @@ pushd "$install_dir/live"
ynh_use_ruby ynh_use_ruby
ynh_gem update --system ynh_gem update --system
ynh_gem install bundler --no-document ynh_gem install bundler --no-document
ynh_exec_as $app $ynh_ruby_load_path $ld_preload bin/bundle config deployment 'true' ynh_exec_as "$app" "$ynh_ruby_load_path" "$ld_preload" bin/bundle config deployment 'true'
ynh_exec_as $app $ynh_ruby_load_path $ld_preload bin/bundle config without 'development test' ynh_exec_as "$app" "$ynh_ruby_load_path" "$ld_preload" bin/bundle config without 'development test'
ynh_exec_as $app $ynh_ruby_load_path $ld_preload bin/bundle config set force_ruby_platform true ynh_exec_as "$app" "$ynh_ruby_load_path" "$ld_preload" bin/bundle config set force_ruby_platform true
ynh_exec_as $app $ynh_ruby_load_path $ld_preload bin/bundle install -j$(getconf _NPROCESSORS_ONLN) ynh_exec_as "$app" "$ynh_ruby_load_path" "$ld_preload" bin/bundle install -j$(getconf _NPROCESSORS_ONLN)
# Building assets # Building assets
ynh_use_nodejs ynh_use_nodejs
corepack enable corepack enable
yarn install yarn install
echo "SAFETY_ASSURED=1">> $config echo "SAFETY_ASSURED=1">> "$config"
ynh_exec_warn_less ynh_exec_as $app RAILS_ENV=production $ynh_ruby_load_path $ld_preload bin/bundle exec rails db:migrate --quiet ynh_exec_warn_less ynh_exec_as "$app" RAILS_ENV=production "$ynh_ruby_load_path" "$ld_preload" bin/bundle exec rails db:migrate --quiet
ynh_exec_warn_less ynh_exec_as $app RAILS_ENV=production $ynh_ruby_load_path $ld_preload bin/bundle exec rails assets:precompile --quiet ynh_exec_warn_less ynh_exec_as "$app" RAILS_ENV=production "$ynh_ruby_load_path" "$ld_preload" bin/bundle exec rails assets:precompile --quiet
# Generate vapid keys # Generate vapid keys
ynh_exec_warn_less ynh_exec_as $app RAILS_ENV=production $ynh_ruby_load_path $ld_preload bin/bundle exec rake mastodon:webpush:generate_vapid_key > key.txt ynh_exec_warn_less ynh_exec_as "$app" RAILS_ENV=production "$ynh_ruby_load_path" "$ld_preload" bin/bundle exec rake mastodon:webpush:generate_vapid_key > key.txt
# Create the first admin user # Create the first admin user
ynh_exec_warn_less ynh_exec_as $app RAILS_ENV=production $ynh_ruby_load_path $ld_preload bin/tootctl accounts create "$admin" --email="$admin_mail" --confirmed --role=Owner > /dev/null ynh_exec_warn_less ynh_exec_as "$app" RAILS_ENV=production "$ynh_ruby_load_path" "$ld_preload" bin/tootctl accounts create "$admin" --email="$admin_mail" --confirmed --role=Owner > /dev/null
popd popd
# Re-generate config with vapid keys # Re-generate config with vapid keys
@ -178,9 +173,8 @@ yunohost service add "$app-streaming" --description="$app streaming service"
ynh_add_config --template="cron" --destination="/etc/cron.d/$app" ynh_add_config --template="cron" --destination="/etc/cron.d/$app"
# Use logrotate to manage application logfile(s) # Use logrotate to manage application logfile(s)
mkdir -p /var/log/$app
chown $app:$app /var/log/$app
ynh_use_logrotate ynh_use_logrotate
chown "$app:$app" "/var/log/$app"
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
@ -189,9 +183,9 @@ ynh_use_logrotate
#================================================= #=================================================
ynh_script_progression --message="Starting all systemd services..." --weight=1 ynh_script_progression --message="Starting all systemd services..." --weight=1
ynh_systemd_action --service_name=${app}-web --action="start" --log_path=/var/log/$app/$app-web.log --line_match="Listening on" ynh_systemd_action --service_name="${app}-web" --action="start" --log_path="/var/log/$app/$app-web.log" --line_match="Listening on"
ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=/var/log/$app/$app-sidekiq.log --line_match="Schedules Loaded" ynh_systemd_action --service_name="${app}-sidekiq" --action="start" --log_path="/var/log/$app/$app-sidekiq.log" --line_match="Schedules Loaded"
ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=/var/log/$app/$app-streaming.log --line_match="Streaming API now listening" ynh_systemd_action --service_name="${app}-streaming" --action="start" --log_path="/var/log/$app/$app-streaming.log" --line_match="Streaming API now listening"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT

View file

@ -1,7 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#================================================= #=================================================
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
@ -11,29 +9,21 @@ source ynh_install_ruby__2
source ynh_add_swap source ynh_add_swap
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#=================================================
# REMOVE SYSTEM CONFIGURATIONS
#================================================= #=================================================
# REMOVE SYSTEMD SERVICE # REMOVE SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 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`) # 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 if ynh_exec_warn_less yunohost service status "$app-web" >/dev/null; then
then
ynh_script_progression --message="Removing $app-web service integration..." --weight=1
yunohost service remove "$app-web" yunohost service remove "$app-web"
fi fi
if ynh_exec_warn_less yunohost service status "$app-sidekiq" >/dev/null if ynh_exec_warn_less yunohost service status "$app-sidekiq" >/dev/null; then
then
ynh_script_progression --message="Removing $app-sidekiq service integration..." --weight=1
yunohost service remove "$app-sidekiq" yunohost service remove "$app-sidekiq"
fi fi
if ynh_exec_warn_less yunohost service status "$app-streaming" >/dev/null if ynh_exec_warn_less yunohost service status "$app-streaming" >/dev/null; then
then
ynh_script_progression --message="Removing $app-streaming service integration..." --weight=1
yunohost service remove "$app-streaming" yunohost service remove "$app-streaming"
fi fi

View file

@ -1,7 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#================================================= #=================================================
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
@ -13,25 +11,13 @@ source ../settings/scripts/ynh_add_swap
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# STANDARD RESTORATION STEPS # INSTALL DEPENDENCIES
#================================================= #=================================================
# RESTORE THE APP MAIN DIR ynh_script_progression --message="Reinstalling Ruby..." --weight=1
#================================================= ynh_exec_warn_less ynh_install_ruby --ruby_version="$ruby_version"
ynh_script_progression --message="Restoring the app main directory..." --weight=1
ynh_restore_file --origin_path="$install_dir" ynh_script_progression --message="Reinstalling NodeJS..." --weight=1
ynh_exec_warn_less ynh_install_nodejs --nodejs_version="$nodejs_version"
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
#=================================================
# RESTORE THE POSTGRESQL DATABASE
#=================================================
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1
ynh_psql_execute_as_root --sql="ALTER USER $db_user CREATEDB;"
ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name"
#================================================= #=================================================
# ADD SWAP IF NEEDED # ADD SWAP IF NEEDED
@ -51,35 +37,39 @@ ynh_script_progression --message="Adding $swap_needed Mo to swap..." --weight=1
ynh_add_swap --size=$swap_needed ynh_add_swap --size=$swap_needed
#================================================= #=================================================
# REINSTALL DEPENDENCIES # RESTORE THE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Reinstalling Ruby and NodeJS..." --weight=1 ynh_script_progression --message="Restoring the app main directory..." --weight=1
ynh_exec_warn_less ynh_install_ruby --ruby_version=$ruby_version ynh_restore_file --origin_path="$install_dir"
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_script_progression --message="Installing Yarn dependencies..." --weight=10 chmod -R o-rwx "$install_dir"
chown -R "$app:www-data" "$install_dir"
pushd "$install_dir/live" #=================================================
ynh_use_nodejs # RESTORE THE POSTGRESQL DATABASE
corepack enable #=================================================
yarn install ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1
popd
ynh_psql_execute_as_root --sql="ALTER USER $db_user CREATEDB;"
ynh_psql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < ./db.sql
#================================================= #=================================================
# BUILD APP # BUILD APP
#================================================= #=================================================
ynh_script_progression --message="Building app..." --weight=1 ynh_script_progression --message="Rebuilding app..." --weight=1
pushd "$install_dir/live" pushd "$install_dir/live"
ynh_use_ruby ynh_use_ruby
ynh_gem update --system ynh_gem update --system
ynh_gem install bundler --no-document ynh_gem install bundler --no-document
ynh_exec_as $app $ynh_ruby_load_path $ld_preload bin/bundle install --redownload -j$(getconf _NPROCESSORS_ONLN) ynh_exec_as "$app" "$ynh_ruby_load_path" "$ld_preload" bin/bundle install --redownload -j"$(nproc)"
ynh_use_nodejs
corepack enable
yarn install
popd popd
#=================================================
# RESTORE SYSTEM CONFIGURATIONS
#================================================= #=================================================
# RESTORE THE PHP-FPM CONFIGURATION # RESTORE THE PHP-FPM CONFIGURATION
#================================================= #=================================================
@ -98,20 +88,18 @@ yunohost service add "$app-streaming" --description="$app streaming service"
ynh_restore_file --origin_path="/etc/cron.d/$app" ynh_restore_file --origin_path="/etc/cron.d/$app"
mkdir -p /var/log/$app ynh_restore_file --origin_path="/var/log/$app/"
chown -R $app:$app /var/log/$app
ynh_restore_file --origin_path="/etc/logrotate.d/$app" ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#=================================================
# GENERIC FINALIZATION
#================================================= #=================================================
# RELOAD NGINX AND THE APP SERVICE # RELOAD NGINX AND THE APP SERVICE
#================================================= #=================================================
ynh_script_progression --message="Reloading NGINX web server and $app's service..." --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=/var/log/$app/$app-web.log --line_match="Listening on" ynh_systemd_action --service_name="${app}-web" --action="start" --log_path="/var/log/$app/$app-web.log" --line_match="Listening on"
ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=/var/log/$app/$app-sidekiq.log --line_match="Schedules Loaded" ynh_systemd_action --service_name="${app}-sidekiq" --action="start" --log_path="/var/log/$app/$app-sidekiq.log" --line_match="Schedules Loaded"
ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=/var/log/$app/$app-streaming.log --line_match="Streaming API now listening" ynh_systemd_action --service_name="${app}-streaming" --action="start" --log_path="/var/log/$app/$app-streaming.log" --line_match="Streaming API now listening"
ynh_systemd_action --service_name=nginx --action=reload ynh_systemd_action --service_name=nginx --action=reload

View file

@ -1,7 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#================================================= #=================================================
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
@ -11,11 +9,8 @@ source ynh_install_ruby__2
source ynh_add_swap source ynh_add_swap
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
upgrade_type=$(ynh_check_app_version_changed)
config="$install_dir/live/.env.production" config="$install_dir/live/.env.production"
#=================================================
# STANDARD UPGRADE STEPS
#================================================= #=================================================
# ENSURE DOWNWARD COMPATIBILITY # ENSURE DOWNWARD COMPATIBILITY
#================================================= #=================================================
@ -35,9 +30,9 @@ ynh_remove_extra_repo
#================================================= #=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name=${app}-web --action="stop" --log_path=/var/log/$app/$app-web.log --line_match="Goodbye" ynh_systemd_action --service_name="${app}-web" --action="stop" --log_path="/var/log/$app/$app-web.log" --line_match="Goodbye"
ynh_systemd_action --service_name=${app}-sidekiq --action="stop" --log_path=/var/log/$app/$app-sidekiq.log --line_match="Bye" ynh_systemd_action --service_name="${app}-sidekiq" --action="stop" --log_path="/var/log/$app/$app-sidekiq.log" --line_match="Bye"
ynh_systemd_action --service_name=${app}-streaming --action="stop" --log_path=/var/log/$app/$app-streaming.log --line_match="exiting" ynh_systemd_action --service_name="${app}-streaming" --action="stop" --log_path="/var/log/$app/$app-streaming.log" --line_match="exiting"
# Rename the database to match packaging v2 defaults db_name (`$app_production` to `$app`) # Rename the database to match packaging v2 defaults db_name (`$app_production` to `$app`)
if [[ $db_name = *'_production' ]]; then if [[ $db_name = *'_production' ]]; then
@ -65,28 +60,34 @@ ynh_add_swap --size=$swap_needed
#================================================= #=================================================
# UPGRADE DEPENDENCIES # UPGRADE DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Upgrading Ruby and NodeJS..." --weight=1 ynh_script_progression --message="Upgrading Ruby..." --weight=1
ynh_exec_warn_less ynh_install_ruby --ruby_version=$ruby_version ynh_exec_warn_less ynh_install_ruby --ruby_version=$ruby_version
ynh_script_progression --message="Upgrading NodeJS..." --weight=1
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_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 # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_script_progression --message="Upgrading source files..." --weight=1
if [ "$upgrade_type" == "UPGRADE_APP" ] # Download Mastodon
then ynh_setup_source --dest_dir="$install_dir/live" --keep="public/system/"
ynh_script_progression --message="Upgrading source files..." --weight=1
# Download Mastodon chmod -R o-rwx "$install_dir"
ynh_setup_source --dest_dir="$install_dir/live" --keep="public/system/" chown -R "$app:www-data" "$install_dir"
chmod 750 "$install_dir" #=================================================
chmod -R o-rwx "$install_dir" # UPDATE A CONFIG FILE
chown -R $app:www-data "$install_dir" #=================================================
fi ynh_script_progression --message="Updating a config file..." --weight=1
language="$(echo $language | head -c 2)"
ynh_add_config --template=".env.production.sample" --destination="$config"
chmod 400 "$config"
chown "$app:$app" "$config"
#================================================= #=================================================
# BUILD ASSETS # BUILD ASSETS
@ -97,19 +98,30 @@ pushd "$install_dir/live"
ynh_use_ruby ynh_use_ruby
ynh_gem update --system ynh_gem update --system
ynh_gem install bundler --no-document ynh_gem install bundler --no-document
ynh_exec_as $app $ynh_ruby_load_path $ld_preload bin/bundle config deployment 'true' ynh_exec_as "$app" "$ynh_ruby_load_path" "$ld_preload" bin/bundle config deployment 'true'
ynh_exec_as $app $ynh_ruby_load_path $ld_preload bin/bundle config without 'development test' ynh_exec_as "$app" "$ynh_ruby_load_path" "$ld_preload" bin/bundle config without 'development test'
ynh_exec_as $app $ynh_ruby_load_path $ld_preload bin/bundle config set force_ruby_platform true --quiet ynh_exec_as "$app" "$ynh_ruby_load_path" "$ld_preload" bin/bundle config set force_ruby_platform true --quiet
ynh_exec_as $app $ynh_ruby_load_path $ld_preload bin/bundle install -j$(getconf _NPROCESSORS_ONLN) ynh_exec_as "$app" "$ynh_ruby_load_path" "$ld_preload" bin/bundle install -j$(getconf _NPROCESSORS_ONLN)
ynh_use_nodejs ynh_use_nodejs
corepack enable corepack enable
yarn install yarn install
if [ -d "$install_dir/live/public/assets" ]; then if [ -d "$install_dir/live/public/assets" ]; then
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:clean
fi fi
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 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/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 ynh_exec_warn_less ynh_exec_as "$app" RAILS_ENV=production "$ynh_ruby_load_path" "$ld_preload" bin/tootctl cache clear
popd
#=================================================
# APPLY MIGRATIONS
#=================================================
ynh_script_progression --message="Applying migrations..." --weight=1
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 popd
#================================================= #=================================================
@ -134,43 +146,17 @@ yunohost service add "$app-streaming" --description="$app streaming service"
ynh_add_config --template="cron" --destination="/etc/cron.d/$app" ynh_add_config --template="cron" --destination="/etc/cron.d/$app"
# Use logrotate to manage app-specific logfile(s) # Use logrotate to manage app-specific logfile(s)
mkdir -p /var/log/$app
chown $app:$app /var/log/$app
ynh_use_logrotate --non-append ynh_use_logrotate --non-append
chown "$app:$app" "/var/log/$app"
#=================================================
# RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...)
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a config file..." --weight=1
language="$(echo $language | head -c 2)"
ynh_add_config --template=".env.production.sample" --destination="$config"
chmod 400 "$config"
chown $app:$app "$config"
#=================================================
# APPLY MIGRATIONS
#=================================================
ynh_script_progression --message="Applying migrations..." --weight=1
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 # 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}-web --action="start" --log_path=/var/log/$app/$app-web.log --line_match="Listening on" ynh_systemd_action --service_name="${app}-web" --action="start" --log_path="/var/log/$app/$app-web.log" --line_match="Listening on"
ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=/var/log/$app/$app-sidekiq.log --line_match="Schedules Loaded" ynh_systemd_action --service_name="${app}-sidekiq" --action="start" --log_path="/var/log/$app/$app-sidekiq.log" --line_match="Schedules Loaded"
ynh_systemd_action --service_name=${app}-streaming --action="start" --log_path=/var/log/$app/$app-streaming.log --line_match="Streaming API now listening" ynh_systemd_action --service_name="${app}-streaming" --action="start" --log_path="/var/log/$app/$app-streaming.log" --line_match="Streaming API now listening"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT