From bcc065634b365c80e773ea6f6e8d30a79c682a07 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 19 Jun 2022 04:48:15 +0200 Subject: [PATCH] Apply last example_ynh --- conf/default.yml | 2 +- conf/nginx.conf | 41 +++++++++++++++-------------- conf/systemd.service | 5 ++-- manifest.json | 2 +- scripts/backup | 15 ++++++----- scripts/install | 62 ++++++++++++++++++++------------------------ scripts/remove | 37 +++++++++++++------------- scripts/restore | 26 ++++++++++--------- scripts/upgrade | 61 ++++++++++++++++++++++--------------------- 9 files changed, 125 insertions(+), 126 deletions(-) diff --git a/conf/default.yml b/conf/default.yml index a218f19..01a726b 100644 --- a/conf/default.yml +++ b/conf/default.yml @@ -138,7 +138,7 @@ id: 'aid' #proxyRemoteFiles: true # Sign to ActivityPub GET request (default: false) -# signToActivityPubGet: true +#signToActivityPubGet: true #allowedPrivateNetworks: [ # '127.0.0.1/32' diff --git a/conf/nginx.conf b/conf/nginx.conf index 7d01556..565b921 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,24 +1,25 @@ -location / { +#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; +location __PATH__/ { - proxy_pass http://127.0.0.1:__PORT__; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto https; - proxy_http_version 1.1; - proxy_redirect off; + proxy_pass http://127.0.0.1:__PORT__; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto https; + proxy_http_version 1.1; + proxy_redirect off; - # For WebSocket - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection $connection_upgrade; + # For WebSocket + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; - # Cache settings - #proxy_cache cache1; - proxy_cache_lock on; - proxy_cache_use_stale updating; - more_set_headers "X-Cache: $upstream_cache_status"; - # Change to upload limit - client_max_body_size 80m; - # Include SSOWAT user panel. - include conf.d/yunohost_panel.conf.inc; + # Cache settings + #proxy_cache cache1; + proxy_cache_lock on; + proxy_cache_use_stale updating; + more_set_headers "X-Cache: $upstream_cache_status"; + # Change to upload limit + client_max_body_size 80m; + # Include SSOWAT user panel. + include conf.d/yunohost_panel.conf.inc; } diff --git a/conf/systemd.service b/conf/systemd.service index 9bba845..19c3f16 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -1,12 +1,13 @@ [Unit] Description=Misskey: microblogging platform +After=network.target [Service] Type=simple User=__APP__ Group=__APP__ -WorkingDirectory=__FINALPATH__ -Environment="PATH=__ENV_PATH__" +WorkingDirectory=__FINALPATH__/ +Environment="__YNH_NODE_LOAD_PATH__" Environment="NODE_ENV=production" ExecStart=__YNH_NPM__ start TimeoutSec=60 diff --git a/manifest.json b/manifest.json index dbb80de..69e68fb 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Microblogging platform", "fr": "Platforme de Microblogging" }, - "version": "12.110.1~ynh1", + "version": "12.110.1~ynh2", "url": "https://misskey-hub.net/", "upstream": { "license": "AGPL-3.0", diff --git a/scripts/backup b/scripts/backup index 9315100..37a5e95 100755 --- a/scripts/backup +++ b/scripts/backup @@ -6,7 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -15,7 +15,6 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ### Remove this function if there's nothing to clean before calling the remove script. true } # Exit if an error occurs during the execution of the script @@ -50,17 +49,19 @@ ynh_backup --src_path="$final_path" ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= -# BACKUP SYSTEMD -#================================================= - -ynh_backup --src_path="/etc/systemd/system/$app.service" - +# SPECIFIC BACKUP #================================================= # BACKUP LOGROTATE #================================================= ynh_backup --src_path="/etc/logrotate.d/$app" +#================================================= +# BACKUP SYSTEMD +#================================================= + +ynh_backup --src_path="/etc/systemd/system/$app.service" + #================================================= # BACKUP THE POSTGRESQL DATABASE #================================================= diff --git a/scripts/install b/scripts/install index eedcf6a..48b0e52 100755 --- a/scripts/install +++ b/scripts/install @@ -14,8 +14,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ### Remove this function if there's nothing to clean before calling the remove script. - true + ynh_clean_check_starting } # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -72,23 +71,9 @@ ynh_app_setting_set --app=$app --key=port --value=$port ynh_script_progression --message="Installing dependencies..." --weight=3 ynh_install_nodejs --nodejs_version=$NODEJS_VERSION - ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies - ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" -#================================================= -# CREATE A POSTGRESQL DATABASE -#================================================= -ynh_script_progression --message="Creating a PostgreSQL database..." --weight=2 - -# Create postgresql database -db_name=$(ynh_sanitize_dbid --db_name=$app) -db_user=$db_name -ynh_app_setting_set --app=$app --key=db_name --value=$db_name -ynh_psql_test_if_first_run -ynh_psql_setup_db --db_user=$db_user --db_name=$db_name - #================================================= # CREATE DEDICATED USER #================================================= @@ -97,6 +82,17 @@ ynh_script_progression --message="Configuring system user..." --weight=2 # Create a system user ynh_system_user_create --username=$app --home_dir="$final_path" +#================================================= +# CREATE A POSTGRESQL DATABASE +#================================================= +ynh_script_progression --message="Creating a PostgreSQL database..." --weight=2 + +db_name=$(ynh_sanitize_dbid --db_name=$app) +db_user=$db_name +ynh_app_setting_set --app=$app --key=db_name --value=$db_name +ynh_psql_test_if_first_run +ynh_psql_setup_db --db_user=$db_user --db_name=$db_name + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -115,21 +111,11 @@ chown -R $app:www-data "$final_path" #================================================= ynh_script_progression --message="Configuring NGINX web server..." --weight=3 -# Create a dedicated nginx config +# Create a dedicated NGINX config ynh_add_nginx_config #================================================= -# SETUP SYSTEMD -#================================================= -ynh_script_progression --message="Configuring a systemd service..." --weight=1 - -env_path="$PATH" - -# Create a dedicated systemd config -ynh_add_systemd_config - -#================================================= -# STORE THE CONFIG FILE CHECKSUM +# ADD A CONFIGURATION #================================================= ynh_script_progression --message="Adding a configuration file..." --weight=1 @@ -140,17 +126,25 @@ ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db" ynh_add_config --template="../conf/default.yml" --destination="$final_path/.config/default.yml" #================================================= -# INSTALLING MISKKEY +# BUILD APP #================================================= -ynh_script_progression --message="Installing Misskey..." --weight=15 +ynh_script_progression --message="Building app..." --weight=15 pushd "$final_path" ynh_use_nodejs - ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH yarn add ts-node webpack - ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH NODE_ENV=production yarn build - ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH yarn run init + ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn add ts-node webpack + ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_ENV=production yarn build + ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn run init popd +#================================================= +# SETUP SYSTEMD +#================================================= +ynh_script_progression --message="Configuring a systemd service..." --weight=1 + +# Create a dedicated systemd config +ynh_add_systemd_config + #================================================= # SETUP LOGROTATE #================================================= @@ -172,7 +166,7 @@ yunohost service add $app --description="A interplanetary blogging platform" --l ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service -ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_match="All workers started" +ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="All workers started" #================================================= # SETUP SSOWAT diff --git a/scripts/remove b/scripts/remove index b21bea2..b4d4187 100755 --- a/scripts/remove +++ b/scripts/remove @@ -29,8 +29,8 @@ redis_db=$(ynh_app_setting_get --app=$app --key=redis_db) # REMOVE SERVICE INTEGRATION IN YUNOHOST #================================================= -# 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" >/dev/null +# 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 >/dev/null then ynh_script_progression --message="Removing $app service integration..." --weight=1 yunohost service remove $app @@ -42,7 +42,15 @@ fi ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1 # Remove the dedicated systemd config -ynh_remove_systemd_config --service="$app" +ynh_remove_systemd_config + +#================================================= +# REMOVE LOGROTATE CONFIGURATION +#================================================= +ynh_script_progression --message="Removing logrotate configuration..." --weight=1 + +# Remove the app-specific logrotate config +ynh_remove_logrotate #================================================= # REMOVE THE POSTGRESQL DATABASE @@ -50,7 +58,7 @@ ynh_remove_systemd_config --service="$app" ynh_script_progression --message="Removing the PostgreSQL database..." --weight=1 # Remove a database if it exists, along with the associated user -ynh_psql_remove_db --db_user="$db_user" --db_name="$db_name" +ynh_psql_remove_db --db_user=$db_user --db_name=$db_name #================================================= # REMOVE THE REDIS DATABASE @@ -59,16 +67,6 @@ ynh_script_progression --message="Removing the redis database..." --weight=1 ynh_redis_remove_db "$redis_db" -#================================================= -# REMOVE DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies..." --weight=1 - -# Remove metapackage and its dependencies -ynh_remove_app_dependencies - -ynh_remove_nodejs - #================================================= # REMOVE APP MAIN DIR #================================================= @@ -82,16 +80,17 @@ ynh_secure_remove --file="$final_path" #================================================= ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1 -# Remove the dedicated nginx config +# Remove the dedicated NGINX config ynh_remove_nginx_config #================================================= -# REMOVE LOGROTATE CONFIGURATION +# REMOVE DEPENDENCIES #================================================= -ynh_script_progression --message="Removing logrotate configuration..." --weight=1 +ynh_script_progression --message="Removing dependencies..." --weight=1 -# Remove the app-specific logrotate config -ynh_remove_logrotate +# Remove metapackage and its dependencies +ynh_remove_nodejs +ynh_remove_app_dependencies #================================================= # SPECIFIC REMOVE diff --git a/scripts/restore b/scripts/restore index 84399b8..50a0ea5 100755 --- a/scripts/restore +++ b/scripts/restore @@ -6,7 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -15,8 +15,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - #### Remove this function if there's nothing to clean before calling the remove script. - true + ynh_clean_check_starting } # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -44,11 +43,7 @@ test ! -d $final_path \ || ynh_die --message="There is already a directory: $final_path " #================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= - -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" - +# STANDARD RESTORATION STEPS #================================================= # RECREATE THE DEDICATED USER #================================================= @@ -77,11 +72,16 @@ ynh_script_progression --message="Reinstalling dependencies..." --weight=5 # Define and install dependencies ynh_install_nodejs --nodejs_version=$NODEJS_VERSION - ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies - 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..." + +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" + #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= @@ -118,10 +118,12 @@ yunohost service add $app --description="A interplanetary blogging platform" --l #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action=start --log_path="systemd" --line_match="All workers started" +ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="All workers started" #================================================= -# RELOAD NGINX AND PHP-FPM +# GENERIC FINALIZATION +#================================================= +# RELOAD NGINX #================================================= ynh_script_progression --message="Reloading NGINX web server..." --weight=1 diff --git a/scripts/upgrade b/scripts/upgrade index 5729eac..0c85b96 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -26,6 +26,7 @@ port=$(ynh_app_setting_get --app=$app --key=port) #================================================= # CHECK VERSION #================================================= +ynh_script_progression --message="Checking version..." upgrade_type=$(ynh_check_app_version_changed) @@ -46,12 +47,22 @@ ynh_script_progression --message="Backing up the app before upgrading (may take # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { - # restore it if the upgrade fails + ynh_clean_check_starting + # Restore it if the upgrade fails ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script ynh_abort_if_errors +#================================================= +# STANDARD UPGRADE STEPS +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." --weight=1 + +ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd --line_match="Stopped" + #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -77,15 +88,6 @@ if ynh_legacy_permissions_exists; then fi -#================================================= -# STANDARD UPGRADE STEPS -#================================================= -# STOP SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 - -ynh_systemd_action --service_name=$app --action=stop --log_path=systemd --line_match="Stopped" - #================================================= # CREATE DEDICATED USER #================================================= @@ -97,7 +99,7 @@ ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -# For now nothing will upgrade as I don't which files needs to be backed up before upgrade + if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_script_progression --message="Upgrading source files..." @@ -110,6 +112,15 @@ chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" +#================================================= +# UPGRADE DEPENDENCIES +#================================================= +ynh_script_progression --message="Upgrading dependencies..." --weight=5 + +ynh_install_nodejs --nodejs_version=$NODEJS_VERSION +ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies +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 #================================================= @@ -119,26 +130,16 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." - ynh_add_nginx_config #================================================= -# UPGRADE DEPENDENCIES -#================================================= -ynh_script_progression --message="Upgrading dependencies..." --weight=5 - -ynh_install_nodejs --nodejs_version=$NODEJS_VERSION - -ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies - -ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" - -#================================================= -# Updating process MISSKEY +# BUILD APP #================================================= +ynh_script_progression --message="Building app..." pushd "$final_path" ynh_use_nodejs - ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH yarn cleanall - ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH yarn install - ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH NODE_ENV=production yarn build - ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH yarn migrate + ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn cleanall + ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install + ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_ENV=production yarn build + ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn migrate popd #================================================= @@ -146,11 +147,11 @@ popd #================================================= ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 -env_path="$PATH" - # Create a dedicated systemd config ynh_add_systemd_config +#================================================= +# GENERIC FINALIZATION #================================================= # SETUP LOGROTATE #================================================= @@ -171,7 +172,7 @@ yunohost service add $app --description="A interplanetary blogging platform" --l #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_match="All workers started" +ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="All workers started" #================================================= # RELOAD NGINX