1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/fittrackee_ynh.git synced 2024-09-03 18:36:16 +02:00

upgrade helpers to v2.1

This commit is contained in:
Thomas 2024-06-23 08:56:30 +02:00 committed by GitHub
parent 48465e582a
commit c6e1b18aa6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 121 additions and 198 deletions

View file

@ -37,5 +37,4 @@ STATICMAP_SUBDOMAINS=''
# Weather # Weather
# available weather API providers: darksky, visualcrossing # available weather API providers: darksky, visualcrossing
WEATHER_API_PROVIDER=__WEATHER_API_PROVIDER__ WEATHER_API_PROVIDER=__WEATHER_API_PROVIDER__
WEATHER_API_KEY=__WEATHER_API_KEY__ WEATHER_API_KEY=__WEATHER_API_KEY__

View file

@ -1,11 +1,9 @@
[Unit] [Unit]
Description=__APP__ service Description=__APP__ service
After=network.target After=network.target
After=postgresql.service After=postgresql.service
After=redis.service After=redis.service
[Service] [Service]
Type=simple Type=simple
Restart=always Restart=always
@ -31,7 +29,6 @@ Environment="WEATHER_API_KEY="
WorkingDirectory=__INSTALL_DIR__/ WorkingDirectory=__INSTALL_DIR__/
ExecStart=__INSTALL_DIR__/venv/bin/gunicorn -b 127.0.0.1:__PORT__ "fittrackee:create_app()" --error-logfile /var/log/__APP__/__APP__.log ExecStart=__INSTALL_DIR__/venv/bin/gunicorn -b 127.0.0.1:__PORT__ "fittrackee:create_app()" --error-logfile /var/log/__APP__/__APP__.log
# Denying access to capabilities that should not be relevant for webapps # Denying access to capabilities that should not be relevant for webapps
# Doc: https://man7.org/linux/man-pages/man7/capabilities.7.html # Doc: https://man7.org/linux/man-pages/man7/capabilities.7.html
CapabilityBoundingSet=~CAP_RAWIO CAP_MKNOD CapabilityBoundingSet=~CAP_RAWIO CAP_MKNOD

View file

@ -5,7 +5,6 @@ After=network.target
After=postgresql.service After=postgresql.service
After=redis.service After=redis.service
[Service] [Service]
Type=simple Type=simple
Restart=always Restart=always
@ -28,10 +27,6 @@ Environment="REDIS_URL="
WorkingDirectory=__INSTALL_DIR__/ WorkingDirectory=__INSTALL_DIR__/
ExecStart=__INSTALL_DIR__/venv/bin/flask worker --processes 2 ExecStart=__INSTALL_DIR__/venv/bin/flask worker --processes 2
NoNewPrivileges=yes NoNewPrivileges=yes
PrivateTmp=yes PrivateTmp=yes
PrivateDevices=yes PrivateDevices=yes

View file

@ -19,7 +19,8 @@ admindoc = "https://samr1.github.io/FitTrackee"
code = "https://github.com/SamR1/FitTrackee" code = "https://github.com/SamR1/FitTrackee"
[integration] [integration]
yunohost = ">= 11.2.12" yunohost = ">= 11.2.15"
helpers_version = "2.1"
architectures = "all" architectures = "all"
multi_instance = true multi_instance = true
@ -33,7 +34,6 @@ ram.runtime = "50M"
[install] [install]
[install.domain] [install.domain]
# this is a generic question - ask strings are automatically handled by Yunohost's core
type = "domain" type = "domain"
[install.init_main_permission] [install.init_main_permission]
@ -41,7 +41,6 @@ ram.runtime = "50M"
default = "visitors" default = "visitors"
[install.admin] [install.admin]
# this is a generic question - ask strings are automatically handled by Yunohost's core
type = "user" type = "user"
[install.password] [install.password]

View file

@ -1,48 +1,39 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# 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 ../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 NGINX CONFIGURATION # BACKUP THE NGINX CONFIGURATION
#================================================= #=================================================
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# BACKUP SYSTEMD # BACKUP SYSTEMD
#================================================= #=================================================
ynh_backup --src_path="/etc/systemd/system/${app}.service" ynh_backup "/etc/systemd/system/${app}.service"
ynh_backup --src_path="/etc/systemd/system/${app}_workers.service" ynh_backup "/etc/systemd/system/${app}_workers.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

@ -1,11 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -16,57 +10,48 @@ source /usr/share/yunohost/helpers
admin=$(ynh_user_get_info --username=$admin --key=username) admin=$(ynh_user_get_info --username=$admin --key=username)
admin_mail=$(ynh_user_get_info --username=$admin --key=mail) admin_mail=$(ynh_user_get_info --username=$admin --key=mail)
if [ -z "${weather_api_provider:-}" ]; then ynh_app_setting_set_default --key=weather_api_provider --value=$weather_provider
weather_api_provider=$weather_provider
ynh_app_setting_set --app=$app --key=weather_api_provider --value=$weather_api_provider
fi
if [ -z "${weather_api_key:-}" ]; then ynh_app_setting_set_default --key=weather_api_key --value=$weather_key
weather_api_key=$weather_key
ynh_app_setting_set --app=$app --key=weather_api_key --value=$weather_api_key
fi
if [ -z "${redis_db:-}" ]; then ynh_app_setting_set_default --key=redis_db --value=$(ynh_redis_get_free_db)
redis_db=$(ynh_redis_get_free_db)
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db"
fi
#=================================================
# STANDARD UPGRADE STEPS
#================================================= #=================================================
# 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 --action="stop" --service_name="${app}" ynh_systemctl --action="stop" --service="${app}"
ynh_systemd_action --action="stop" --service_name="${app}_workers"
ynh_systemctl --action="stop" --service="${app}_workers"
#================================================= #=================================================
# 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
#================================================= #=================================================
# MODIFY THE CONFIG FILE # MODIFY THE CONFIG FILE
#================================================= #=================================================
ynh_script_progression --message="Modifying a config file..." --weight=1 ynh_script_progression "Updating configuration..."
domain=$new_domain domain=$new_domain
ynh_add_config --template="../conf/.env.production" --destination="$install_dir/.env" ynh_config_add --template=".env.production" --destination="$install_dir/.env"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting the systemd services..." --weight=15 ynh_script_progression "Starting the systemd services..."
# Start a systemd service # Start a systemd service
ynh_systemd_action --service_name="${app}" --action="start" ynh_systemctl --service="${app}" --action="start"
ynh_systemd_action --service_name="${app}_workers" --action="start"
ynh_systemctl --service="${app}_workers" --action="start"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Upgrade of $app completed" --last ynh_script_progression "Upgrade of $app completed"

View file

@ -1,37 +1,29 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
admin=$(ynh_user_get_info --username=$admin --key=username) admin=$(ynh_user_get_info --username=$admin --key=username)
admin_mail=$(ynh_user_get_info --username=$admin --key=mail) admin_mail=$(ynh_user_get_info --username=$admin --key=mail)
ynh_app_setting_set --app=$app --key=weather_api_provider --value=$weather_api_provider ynh_app_setting_set --key=weather_api_provider --value=$weather_api_provider
ynh_app_setting_set --app=$app --key=weather_api_key --value=$weather_api_key ynh_app_setting_set --key=weather_api_key --value=$weather_api_key
# Configure redis # Configure redis
redis_db=$(ynh_redis_get_free_db) redis_db=$(ynh_redis_get_free_db)
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db" ynh_app_setting_set --key=redis_db --value="$redis_db"
# key for the .env __KEY__ # key for the .env __KEY__
key=$(ynh_string_random --length=45 | base64) key=$(ynh_string_random --length=45 | base64)
ynh_app_setting_set --app=$app --key=key --value=$key ynh_app_setting_set --key=key --value=$key
#================================================= #=================================================
# LOGROTATE # LOGROTATE
#================================================= #=================================================
ynh_script_progression --message="Configuring logrotate to manage application logfiles" --weight=1 ynh_script_progression "Configuring logrotate to manage application logfiles"
# Use logrotate to manage application logfile(s) # Use logrotate to manage application logfile(s)
ynh_use_logrotate --specific_user=$app ynh_config_add_logrotate
touch /var/log/$app/$app.log
touch /var/log/$app/${app}_workers.log
chown -R $app:www-data /var/log/$app/
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
@ -39,9 +31,9 @@ chown -R $app:www-data /var/log/$app/
# CONFIGURE THE INSTALL SCRIPT # CONFIGURE THE INSTALL SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Setting up source files..." --weight=64 ynh_script_progression "Setting up source files..."
ynh_add_config --template="../conf/.env.production" --destination="$install_dir/.env" ynh_config_add --template=".env.production" --destination="$install_dir/.env"
chmod 400 $install_dir/.env chmod 400 $install_dir/.env
chown -R $app:www-data "$install_dir" chown -R $app:www-data "$install_dir"
@ -49,85 +41,84 @@ chown -R $app:www-data "$install_dir"
#================================================= #=================================================
# INSTALL PYTHON DEPENDENCIES # INSTALL PYTHON DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Installing Python dependencies..." --weight=3 ynh_script_progression "Installing Python dependencies..."
if [ $YNH_ARCH == "armhf" ] || [ $YNH_ARCH == "armel" ] if [ $YNH_ARCH == "armhf" ] || [ $YNH_ARCH == "armel" ]
then then
# Install rustup is not already installed # Install rustup if not already installed
# We need this to be able to install cryptgraphy on ARM hardware # We need this to be able to install cryptgraphy on ARM hardware
export PATH="$PATH:$install_dir/.cargo/bin:$install_dir/.local/bin:/usr/local/sbin" export PATH="$PATH:$install_dir/.cargo/bin:$install_dir/.local/bin:/usr/local/sbin"
if [ -e $install_dir/.rustup ]; then if [ -e $install_dir/.rustup ]; then
sudo -u "$app" env PATH=$PATH rustup update ynh_exec_as_app PATH=$PATH rustup update
else else
sudo -u "$app" bash -c 'curl -sSf -L https://static.rust-lang.org/rustup.sh | sh -s -- -y --default-toolchain=stable --profile=minimal' ynh_exec_as_app bash -c 'curl -sSf -L https://static.rust-lang.org/rustup.sh | sh -s -- -y --default-toolchain=stable --profile=minimal'
fi fi
fi fi
pushd $install_dir pushd $install_dir
python3 -m venv $install_dir/venv python3 -m venv $install_dir/venv
source $install_dir/venv/bin/activate source $install_dir/venv/bin/activate
ynh_exec_warn_less pip install --upgrade pip wheel toml pyyaml ynh_hide_warnings pip install --upgrade pip wheel toml pyyaml
ynh_exec_warn_less pip install fittrackee=="$(ynh_app_upstream_version)" ynh_hide_warnings pip install fittrackee=="$(ynh_app_upstream_version)"
popd popd
#================================================= #=================================================
# INITIALIZE DATABASE # INITIALIZE DATABASE
#================================================= #=================================================
ynh_script_progression --message="Initializing database..." --weight=1 ynh_script_progression "Initializing database..."
set -a
set -a
source $install_dir/.env source $install_dir/.env
ynh_exec_warn_less $install_dir/venv/bin/ftcli db upgrade ynh_hide_warnings $install_dir/venv/bin/ftcli db upgrade
ynh_exec_warn_less $install_dir/venv/bin/ftcli users create $admin --email $admin_mail --password $password --lang $language ynh_hide_warnings $install_dir/venv/bin/ftcli users create $admin --email $admin_mail --password $password --lang $language
ynh_exec_warn_less $install_dir/venv/bin/ftcli users update $admin --set-admin true ynh_hide_warnings $install_dir/venv/bin/ftcli users update $admin --set-admin true
set +a set +a
#================================================= #=================================================
# 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 ..."
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=1 ynh_script_progression "Configuring NGINX web server..."
# Create a dedicated NGINX config # Create a dedicated NGINX config
ynh_add_nginx_config ynh_config_add_nginx
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
#================================================= #=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=1 ynh_script_progression "Configuring $app's systemd service..."
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config --service="${app}" --template="fittrackee.service" ynh_config_add_systemd --service="${app}" --template="fittrackee.service"
ynh_add_systemd_config --service="${app}_workers" --template="fittrackee_workers.service" ynh_config_add_systemd --service="${app}_workers" --template="fittrackee_workers.service"
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 ynh_script_progression "Integrating service in YunoHost..."
yunohost service add "${app}" --description="Fittrackee main service" --log="/var/log/$app/$app.log" yunohost service add "${app}" --description="Fittrackee main service" --log="/var/log/$app/$app.log"
yunohost service add "${app}_workers" --description="Fittrackee task queue service" --log="var/log/$app/${app}_workers.log" yunohost service add "${app}_workers" --description="Fittrackee task queue service" --log="var/log/$app/${app}_workers.log"
#=================================================
# GENERIC FINALIZATION
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting the systemd services..." --weight=15 ynh_script_progression "Starting the systemd services..."
# Start a systemd service # Start a systemd service
ynh_systemd_action --service_name="${app}" --action="start" ynh_systemctl --service="${app}" --action="start"
ynh_systemd_action --service_name="${app}_workers" --action="start" ynh_systemctl --service="${app}_workers" --action="start"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Installation of $app completed" --last ynh_script_progression "Installation of $app completed"

View file

@ -1,20 +1,14 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading installation settings..." ynh_script_progression "Loading installation settings..."
redis_db=$(ynh_app_setting_get --app=$app --key=redis_db) redis_db=$(ynh_app_setting_get --key=redis_db)
#================================================= #=================================================
# STANDARD REMOVE # STANDARD REMOVE
@ -23,9 +17,9 @@ redis_db=$(ynh_app_setting_get --app=$app --key=redis_db)
#================================================= #=================================================
# 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 >/dev/null if ynh_hide_warnings yunohost service status $app >/dev/null
then then
ynh_script_progression --message="Removing $app services integration..." --weight=1 ynh_script_progression "Removing $app services integration..."
yunohost service remove $app yunohost service remove $app
yunohost service remove ${app}_workers yunohost service remove ${app}_workers
fi fi
@ -33,21 +27,21 @@ fi
#================================================= #=================================================
# STOP AND REMOVE SERVICE # STOP AND REMOVE SERVICE
#================================================= #=================================================
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1 ynh_script_progression "Stopping and removing the systemd service..."
# Remove the dedicated systemd config # Remove the dedicated systemd config
ynh_remove_systemd_config --service="${app}" ynh_config_remove_systemd"${app}"
ynh_remove_systemd_config --service="${app}_workers" ynh_config_remove_systemd"${app}_workers"
#================================================= #=================================================
# REMOVE VARIOUS FILES # REMOVE VARIOUS FILES
#================================================= #=================================================
ynh_script_progression --message="Removing various files..." --weight=5 ynh_script_progression "Removing various files..."
# Remove the dedicated NGINX config # Remove the dedicated NGINX config
ynh_remove_nginx_config ynh_config_remove_nginx
ynh_remove_logrotate ynh_config_remove_logrotate
# Remove the redis database # Remove the redis database
ynh_redis_remove_db "$redis_db" ynh_redis_remove_db "$redis_db"
@ -56,4 +50,4 @@ ynh_redis_remove_db "$redis_db"
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Removal of $app completed" --last ynh_script_progression "Removal of $app completed"

View file

@ -1,50 +1,42 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# 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 ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_name=$(ynh_app_setting_get --key=db_name)
#================================================= #=================================================
# STANDARD RESTORATION STEPS # STANDARD RESTORATION STEPS
#================================================= #=================================================
# RESTORE LOGROTATE # RESTORE LOGROTATE
#================================================= #=================================================
ynh_script_progression --message="Configuring logrotate to manage application logfiles" --weight=1 ynh_script_progression "Configuring logrotate to manage application logfiles"
# Use logrotate to manage application logfile(s) # Use logrotate to manage application logfile(s)
ynh_use_logrotate --specific_user=$app ynh_config_add_logrotate
touch /var/log/$app/$app.log
touch /var/log/$app/${app}_workers.log
chown -R $app:www-data /var/log/$app/
#================================================= #=================================================
# RESTORE THE NGINX CONFIGURATION # RESTORE THE NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1 ynh_script_progression "Restoring the NGINX web server configuration..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf"
#================================================= #=================================================
# 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_file_as_root --file="./db.sql" --database=$db_name ynh_psql_db_shell < "./db.sql"
#================================================= #=================================================
# 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 400 $install_dir/.env chmod 400 $install_dir/.env
chown -R $app: "$install_dir" chown -R $app: "$install_dir"
@ -52,10 +44,10 @@ chown -R $app: "$install_dir"
#================================================= #=================================================
# RESTORE SYSTEMD # RESTORE SYSTEMD
#================================================= #=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 ynh_script_progression "Restoring $app's systemd service..."
ynh_restore_file --origin_path="/etc/systemd/system/${app}.service" ynh_restore "/etc/systemd/system/${app}.service"
ynh_restore_file --origin_path="/etc/systemd/system/${app}_workers.service" ynh_restore "/etc/systemd/system/${app}_workers.service"
systemctl enable "${app}.service" --quiet systemctl enable "${app}.service" --quiet
systemctl enable "${app}_workers.service" --quiet systemctl enable "${app}_workers.service" --quiet
@ -63,7 +55,7 @@ systemctl enable "${app}_workers.service" --quiet
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 ynh_script_progression "Integrating service in YunoHost..."
yunohost service add "${app}" --description="Fittrackee main service" --log="/var/log/$app/$app.log" yunohost service add "${app}" --description="Fittrackee main service" --log="/var/log/$app/$app.log"
yunohost service add "${app}_workers" --description="Fittrackee task queue service" --log="var/log/$app/${app}_workers.log" yunohost service add "${app}_workers" --description="Fittrackee task queue service" --log="var/log/$app/${app}_workers.log"
@ -71,22 +63,21 @@ yunohost service add "${app}_workers" --description="Fittrackee task queue servi
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression "Starting $app's systemd service..."
ynh_systemd_action --service_name="${app}" --action="start" ynh_systemctl --service="${app}" --action="start"
ynh_systemd_action --service_name="${app}_workers" --action="start"
ynh_systemctl --service="${app}_workers" --action="start"
#=================================================
# GENERIC FINALIZATION
#================================================= #=================================================
# 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

@ -1,28 +1,16 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# ENSURE DOWNWARD COMPATIBILITY # ENSURE DOWNWARD COMPATIBILITY
#================================================= #=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 ynh_script_progression "Ensuring downward compatibility..."
if [ -z "${weather_api_provider:-}" ]; then ynh_app_setting_set_default --key=weather_api_provider --value=$weather_provider
weather_api_provider=$weather_provider
ynh_app_setting_set --app=$app --key=weather_api_provider --value=$weather_api_provider
fi
if [ -z "${weather_api_key:-}" ]; then ynh_app_setting_set_default --key=weather_api_key --value=$weather_key
weather_api_key=$weather_key
ynh_app_setting_set --app=$app --key=weather_api_key --value=$weather_api_key
fi
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
@ -31,26 +19,19 @@ fi
admin=$(ynh_user_get_info --username=$admin --key=username) admin=$(ynh_user_get_info --username=$admin --key=username)
admin_mail=$(ynh_user_get_info --username=$admin --key=mail) admin_mail=$(ynh_user_get_info --username=$admin --key=mail)
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# STANDARD UPGRADE STEPS
#================================================= #=================================================
# 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 --action="stop" --service_name="${app}" ynh_systemctl --action="stop" --service="${app}"
ynh_systemd_action --action="stop" --service_name="${app}_workers"
ynh_systemctl --action="stop" --service="${app}_workers"
#================================================= #=================================================
# INSTALL DEPENDENCIES # INSTALL DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Installing dependencies..." --weight=23 ynh_script_progression "Installing dependencies..."
chmod -R o-rwx "$install_dir" chmod -R o-rwx "$install_dir"
chown -R $app: "$install_dir" chown -R $app: "$install_dir"
@ -58,72 +39,70 @@ chown -R $app: "$install_dir"
#================================================= #=================================================
# CONFIGURE THE INSTALL SCRIPT # CONFIGURE THE INSTALL SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Installing service script..." --weight=1 ynh_script_progression "Installing service script..."
redis_db=$(ynh_redis_get_free_db) redis_db=$(ynh_redis_get_free_db)
ynh_add_config --template="../conf/.env.production" --destination="$install_dir/.env" ynh_config_add --template=".env.production" --destination="$install_dir/.env"
chmod 400 $install_dir/.env chmod 400 $install_dir/.env
chown $app: "$install_dir/.env" chown $app: "$install_dir/.env"
#================================================= #=================================================
# INSTALL PYTHON DEPENDENCIES # INSTALL PYTHON DEPENDENCIES
#================================================= #=================================================
ynh_script_progression --message="Installing Python dependencies..." --weight=3 ynh_script_progression "Installing Python dependencies..."
if [ $YNH_ARCH == "armhf" ] || [ $YNH_ARCH == "armel" ] if [ $YNH_ARCH == "armhf" ] || [ $YNH_ARCH == "armel" ]
then then
# Install rustup is not already installed # Install rustup is not already installed
# We need this to be able to install cryptgraphy on ARM hardware # We need this to be able to install cryptgraphy on ARM hardware
export PATH="$PATH:$install_dir/.cargo/bin:$install_dir/.local/bin:/usr/local/sbin" export PATH="$PATH:$install_dir/.cargo/bin:$install_dir/.local/bin:/usr/local/sbin"
if [ -e $install_dir/.rustup ]; then if [ -e $install_dir/.rustup ]; then
sudo -u "$app" env PATH=$PATH rustup update ynh_exec_as_app PATH=$PATH rustup update
else else
sudo -u "$app" bash -c 'curl -sSf -L https://static.rust-lang.org/rustup.sh | sh -s -- -y --default-toolchain=stable --profile=minimal' ynh_exec_as_app bash -c 'curl -sSf -L https://static.rust-lang.org/rustup.sh | sh -s -- -y --default-toolchain=stable --profile=minimal'
fi fi
fi fi
pushd $install_dir pushd $install_dir
python3 -m venv $install_dir/venv python3 -m venv $install_dir/venv
source $install_dir/venv/bin/activate source $install_dir/venv/bin/activate
ynh_exec_warn_less pip install --upgrade pip wheel toml pyyaml ynh_hide_warnings pip install --upgrade pip wheel toml pyyaml
ynh_exec_warn_less pip install fittrackee=="$(ynh_app_upstream_version)" ynh_hide_warnings pip install fittrackee=="$(ynh_app_upstream_version)"
popd popd
#================================================= #=================================================
# Update DATABASE # Update DATABASE
#================================================= #=================================================
ynh_script_progression --message="Upgrading database..." --weight=1 ynh_script_progression "Upgrading database..."
set -a set -a
source $install_dir/.env source $install_dir/.env
ynh_exec_warn_less $install_dir/venv/bin/ftcli db upgrade ynh_hide_warnings $install_dir/venv/bin/ftcli db upgrade
set +a set +a
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1 ynh_script_progression "Upgrading NGINX web server configuration..."
# Create a dedicated NGINX config # Create a dedicated NGINX config
ynh_add_nginx_config ynh_config_add_nginx
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
#================================================= #=================================================
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 ynh_script_progression "Upgrading systemd configuration..."
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config --service="${app}" --template="fittrackee.service" ynh_config_add_systemd --service="${app}" --template="fittrackee.service"
ynh_add_systemd_config --service="${app}_workers" --template="fittrackee_workers.service" ynh_config_add_systemd --service="${app}_workers" --template="fittrackee_workers.service"
#=================================================
# GENERIC FINALIZATION
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 ynh_script_progression "Integrating service in YunoHost..."
yunohost service add "${app}" --description="Fittrackee main service" --log="/var/log/$app/$app.log" yunohost service add "${app}" --description="Fittrackee main service" --log="/var/log/$app/$app.log"
yunohost service add "${app}_workers" --description="Fittrackee task queue service" --log="var/log/$app/${app}_workers.log" yunohost service add "${app}_workers" --description="Fittrackee task queue service" --log="var/log/$app/${app}_workers.log"
@ -131,14 +110,15 @@ yunohost service add "${app}_workers" --description="Fittrackee task queue servi
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting the systemd services..." --weight=15 ynh_script_progression "Starting the systemd services..."
# Start a systemd service # Start a systemd service
ynh_systemd_action --service_name="${app}" --action="start" ynh_systemctl --service="${app}" --action="start"
ynh_systemd_action --service_name="${app}_workers" --action="start"
ynh_systemctl --service="${app}_workers" --action="start"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Upgrade of $app completed" --last ynh_script_progression "Upgrade of $app completed"

View file

@ -19,4 +19,5 @@ test_format = 1.0
test_upgrade_from.5b6ccd1.name = "0.8.0" test_upgrade_from.5b6ccd1.name = "0.8.0"
test_upgrade_from.6c23ccf.name = "0.8.1" test_upgrade_from.6c23ccf.name = "0.8.1"
test_upgrade_from.2c6b69d.name = "0.8.3" test_upgrade_from.2c6b69d.name = "0.8.3"
test_upgrade_from.48465e5.name = "helpers v1"