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

Apply last example_ynh

This commit is contained in:
yalh76 2022-01-27 00:17:52 +01:00 committed by tituspijean
parent d81eef6493
commit eed0f9e003
No known key found for this signature in database
GPG key ID: EF3B0D7CC0A94720
8 changed files with 107 additions and 89 deletions

View file

@ -1,16 +1,16 @@
location ^~ __PATH__/ {
rewrite ^__PATH__/admin$ https://$host__PATH__/admin/ permanent;
rewrite ^__PATH__/ui$ https://$host__PATH__/ui/ permanent;
rewrite ^__PATH__/admin$ https://$host__PATH__/admin/ permanent;
rewrite ^__PATH__/ui$ https://$host__PATH__/ui/ permanent;
proxy_pass http://localhost:__PORT__/;
proxy_set_header Host $host;
proxy_redirect http:// https://;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass http://localhost:__PORT__/;
proxy_set_header Host $host;
proxy_redirect http:// https://;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
# Include SSOWAT user panel.
include conf.d/yunohost_panel.conf.inc;
}

View file

@ -13,6 +13,8 @@ StandardOutput=syslog
StandardError=inherit
# Sandboxing options to harden security
# Depending on specificities of your service/app, you may need to tweak these
# .. but this should be a good baseline
# Details for these options: https://www.freedesktop.org/software/systemd/man/systemd.exec.html
NoNewPrivileges=yes
PrivateTmp=yes

View file

@ -6,6 +6,7 @@
# IMPORT GENERIC HELPERS
#=================================================
# 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
@ -55,4 +56,4 @@ ynh_backup --src_path="/etc/systemd/system/$app.service"
# END OF SCRIPT
#=================================================
ynh_print_info --message="Backup script completed for Node-RED. (YunoHost will then actually copy those files to the archive)."
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -39,7 +39,7 @@ else
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=1
@ -87,19 +87,19 @@ ynh_script_progression --message="Updating NGINX web server configuration..." --
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
# Change the path in the nginx config file
# Change the path in the NGINX config file
if [ $change_path -eq 1 ]
then
# Make a backup of the original nginx config file if modified
# Make a backup of the original NGINX config file if modified
ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
# Set global variables for nginx helper
# Set global variables for NGINX helper
domain="$old_domain"
path_url="$new_path"
# Create a dedicated nginx config
# Create a dedicated NGINX config
ynh_add_nginx_config
fi
# Change the domain for nginx
# Change the domain for NGINX
if [ $change_domain -eq 1 ]
then
# Delete file checksum for the old conf file location
@ -127,6 +127,7 @@ chown -R $app: "$final_path/data/settings.js"
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start"
#=================================================
@ -140,4 +141,4 @@ ynh_systemd_action --service_name=nginx --action=reload
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Change of URL completed for Node-RED" --last
ynh_script_progression --message="Change of URL completed for $app" --last

View file

@ -24,6 +24,7 @@ domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
admin=$YNH_APP_ARG_ADMIN
is_public=$YNH_APP_ARG_IS_PUBLIC
app=$YNH_APP_INSTANCE_NAME
#=================================================
@ -52,16 +53,25 @@ ynh_app_setting_set --app=$app --key=path --value=$path_url
#=================================================
ynh_script_progression --message="Finding an available port..." --weight=1
# Find a free port
# Find an available port
port=$(ynh_find_port --port=1880)
ynh_app_setting_set --app=$app --key=port --value=$port
#=================================================
# INSTALL NODEJS
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..."
ynh_install_nodejs --nodejs_version=$nodejs_version
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=1
# Create a system user
ynh_system_user_create --username=$app --home_dir=$final_path
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
@ -72,13 +82,15 @@ ynh_app_setting_set --app=$app --key=final_path --value=$final_path
ynh_setup_source --dest_dir="$final_path"
#=================================================
# CREATE DEDICATED USER
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=1
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
# Create a system user
ynh_system_user_create --username=$app --home_dir=$final_path
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# SPECIFIC SETUP
#=================================================
# Install through npm
#=================================================
@ -93,16 +105,9 @@ pushd $final_path
popd
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# SPECIFIC SETUP
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..."
# Set up the settings file
mkdir -p $final_path/data
@ -133,8 +138,11 @@ ynh_script_progression --message="Configuring a systemd service..." --weight=1
ynh_add_systemd_config
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
# GENERIC FINALIZATION
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --description="Low-code programming for event-driven applications"
@ -184,4 +192,4 @@ ynh_systemd_action --service_name=nginx --action=reload
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of Node-RED completed" --last
ynh_script_progression --message="Installation of $app completed" --last

View file

@ -23,13 +23,13 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#=================================================
# STANDARD REMOVE
#=================================================
# REMOVE SERVICE FROM ADMIN PANEL
# REMOVE SERVICE INTEGRATION IN YUNOHOST
#=================================================
# Remove a service from the admin panel, added by `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 >/dev/null
then
ynh_script_progression --message="Removing Node-RED service..." --weight=1
ynh_script_progression --message="Removing $app service..." --weight=1
yunohost service remove $app
fi
@ -41,17 +41,10 @@ ynh_script_progression --message="Stopping and removing the systemd service..."
# Remove the dedicated systemd config
ynh_remove_systemd_config
#=================================================
# REMOVE NODEJS
#=================================================
ynh_script_progression --message="Removing NodeJS version requirement..." --weight=4
ynh_remove_nodejs
#=================================================
# REMOVE APP MAIN DIR
#=================================================
ynh_script_progression --message="Removing Node-RED main directory..." --weight=2
ynh_script_progression --message="Removing app main directory..." --weight=2
# Remove the app directory securely
ynh_secure_remove --file="$final_path"
@ -64,6 +57,13 @@ ynh_script_progression --message="Removing NGINX web server configuration..." --
# Remove the dedicated NGINX config
ynh_remove_nginx_config
#=================================================
# REMOVE DEPENDENCIES
#=================================================
ynh_script_progression --message="Removing dependencies..." --weight=4
ynh_remove_nodejs
#=================================================
# SPECIFIC REMOVE
#=================================================
@ -82,4 +82,4 @@ ynh_system_user_delete --username=$app
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of Node-RED completed" --last
ynh_script_progression --message="Removal of $app completed" --last

View file

@ -6,6 +6,7 @@
# IMPORT GENERIC HELPERS
#=================================================
# 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
@ -40,6 +41,7 @@ test ! -d $final_path \
#=================================================
# 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"
@ -54,7 +56,7 @@ ynh_system_user_create --username=$app --home_dir=$final_path
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring Node-RED main directory..." --weight=5
ynh_script_progression --message="Restoring the app main directory..." --weight=5
ynh_restore_file --origin_path="$final_path"
@ -69,8 +71,9 @@ chown -R $app: /var/log/$app
#=================================================
# SPECIFIC RESTORATION
#=================================================
# INSTALL NODEJS
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..."
ynh_install_nodejs --nodejs_version=$nodejs_version
@ -83,8 +86,9 @@ ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --description="Low-code programming for event-driven applications"
@ -108,4 +112,4 @@ ynh_systemd_action --service_name=nginx --action=reload
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for Node-RED" --last
ynh_script_progression --message="Restoration completed for $app" --last

View file

@ -24,23 +24,33 @@ port=$(ynh_app_setting_get --app=$app --key=port)
#=================================================
# CHECK VERSION
#=================================================
ynh_script_progression --message="Checking version..."
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up Node-RED before upgrading (may take a while)..." --weight=5
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=5
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# restore it if the upgrade fails
# 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"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
@ -103,10 +113,6 @@ if [[ -d "/etc/logrotate.d/$app" ]]; then
ynh_secure_remove --file="/var/log/$app"
fi
#=================================================
# CLOSING PORT
#=================================================
# In older versions of the package, the port serving the webui was opened to anyone,
# allowing direct access to Node-RED... let's close it.
if yunohost firewall list | grep -q "\- $port$"
@ -116,22 +122,12 @@ then
fi
#=================================================
# STANDARD UPGRADE STEPS
# CREATE DEDICATED USER
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
ynh_systemd_action --service_name=$app --action="stop"
#=================================================
# INSTALL NODEJS
#=================================================
if [ $(ynh_app_setting_get --app=$app --key=nodejs_version) != $nodejs_version ]; then
ynh_remove_nodejs
ynh_install_nodejs --nodejs_version=$nodejs_version
fi
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir=$final_path
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
@ -146,13 +142,25 @@ then
fi
#=================================================
# CREATE DEDICATED USER
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir=$final_path
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..."
if [ $(ynh_app_setting_get --app=$app --key=nodejs_version) != $nodejs_version ]; then
ynh_remove_nodejs
ynh_install_nodejs --nodejs_version=$nodejs_version
fi
#=================================================
# SPECIFIC UPGRADE
#=================================================
# Install through npm
#=================================================
@ -168,16 +176,9 @@ pushd $final_path
popd
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# SPECIFIC UPGRADE
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..."
# Set up the settings file
ynh_add_config --template="../conf/settings.js" --destination="$final_path/data/settings.js"
@ -198,8 +199,6 @@ ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
@ -212,8 +211,11 @@ chown -R $app: "$final_path"
chmod a-w "$final_path/data/settings.js"
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
# GENERIC FINALIZATION
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --description="Low-code programming for event-driven applications"
@ -235,4 +237,4 @@ ynh_systemd_action --service_name=nginx --action=reload
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of Node-RED completed" --last
ynh_script_progression --message="Upgrade of $app completed" --last