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

Upgrade paths/filename part III

now it works on my test system...
This commit is contained in:
Chris Vogel 2024-05-08 11:18:05 +02:00
parent b943dfa6f1
commit 6287cd7725
4 changed files with 73 additions and 42 deletions

View file

@ -35,28 +35,75 @@ flohmarkt_sym_data_dir="$( dirname $flohmarkt_data_dir )/$flohmarkt_filename"
## old filenames before 0.00~ynh5 - for reference and needed to
# migrate (see below)
flohmarkt_old_install="$install_dir/$app/"
flohmarkt_old_venv_dir="$install_dir/venv"
flohmarkt_old_log_dir="/var/log/$app/"
flohmarkt_old_logfile="$app"
flohmarkt_old_service="$app"
flohmarkt_old_install="/opt/flohmarkt"
flohmarkt_old_venv_dir="${flohmarkt_old_install}/venv"
flohmarkt_old_app_dir="${flohmarkt_old_install}/flohmarkt"
flohmarkt_old_log_dir="/var/log/flohmarkt/"
flohmarkt_old_logfile="flohmarkt"
flohmarkt_old_service="flohmarkt"
#=================================================
# PERSONAL HELPERS
#=================================================
# create venv
flohmarkt_ynh_create_venv() {
python3 -m venv --without-pip "$flohmarkt_venv_dir"
}
# install requirements.txt in venv
flohmarkt_ynh_venv_requirements() {
(
set +o nounset
source "$flohmarkt_venv_dir/bin/activate"
set -o nounset
set -x
$flohmarkt_venv_dir/bin/python3 -m ensurepip
$flohmarkt_venv_dir/bin/pip3 install -r "$flohmarkt_app_dir/requirements.txt"
)
}
# move files and directories to their new places
flohmarkt_ynh_upgrade_path_ynh5() {
# flohmarkt and couchdb are already stopped in upgrade script
# move install_dir
# move venv_dir
# move data_dir
# move systemd.service
# move logfiles
# move app_dir into new 'app' folder
mv "$flohmarkt_install/flohmarkt" "$flohmarkt_app_dir"
# yunohost seems to move the venv dir automatically, but this
# doesn't work, because the paths inside the venv are not adjusted
# delete the old, not working venv and create a new one:
ynh_secure_remove --file="$flohmarkt_venv_dir"
flohmarkt_ynh_create_venv
flohmarkt_ynh_venv_requirements
# remove old $install_dir
ynh_secure_remove --file="$flohmarkt_old_install"
# move logfile directory
mkdir -p "$flohmarkt_log_dir"
mv ${flohmarkt_old_log_dir}/${flohmarkt_old_logfile}.* "$flohmarkt_log_dir"
# update settings for above
false
# there's still some work open - see above
# @@ automatically done? maybe?
# remove systemd.service - will be generated newly by upgrade
# ynh_remove_systemd_config --service="$flohmarkt_old_service"
ynh_systemd_action --action=stop --service_name="$flohmarkt_old_service"
ynh_systemd_action --action=disable --service_name="$flohmarkt_old_service"
ynh_secure_remove --file="/etc/systemd/system/multi-user.target.wants/flohmarkt.service"
ynh_secure_remove --file="/etc/systemd/system/flohmarkt.service"
# funktioniert nicht? issue?
#ynh_systemd_action --action=daemon-reload
# DEBUG + systemctl daemon-reload flohmarkt
# WARNING Too many arguments.
systemctl daemon-reload
# unit flohmarkt is automatically appended and therefor this fails:
#ynh_systemd_action --action=reset-failed
systemctl reset-failed
# create symlinks
ln -s "$flohmarkt_install" "$flohmarkt_sym_install"
ln -s "$flohmarkt_data_dir" "$flohmarkt_sym_data_dir"
}
#=================================================

View file

@ -67,18 +67,8 @@ ynh_setup_source --dest_dir="$flohmarkt_app_dir"
# setup python environment for flohmarkt
ynh_secure_remove "$flohmarkt_venv_dir"
python3 -m venv --without-pip "$flohmarkt_venv_dir"
# install python dependencies
(
set +o nounset
source "$flohmarkt_venv_dir/bin/activate"
set -o nounset
set -x
$flohmarkt_venv_dir/bin/python3 -m ensurepip
$flohmarkt_venv_dir/bin/pip3 install -r "$flohmarkt_app_dir/requirements.txt"
)
flohmarkt_ynh_create_venv
flohmarkt_ynh_venv_requirements
# JwtSecret
# workaround for https://github.com/YunoHost/issues/issues/2379
@ -126,8 +116,6 @@ touch "$flohmarkt_logfile"
chmod 640 "$flohmarkt_logfile"
# start service
ynh_systemd_action --service_name=$flohmarkt_filename --action="start" --line_match='INFO: *Application startup complete.' --log_path="$flohmarkt_logfile" --timeout=30
# https://codeberg.org/flohmarkt/flohmarkt_ynh/issues/44
# --line_match="INFO: Application startup complete."
# SETUP FAIL2BAN
ynh_script_progression --message="Configuring Fail2Ban..." --weight=3

View file

@ -9,6 +9,10 @@ source /usr/share/yunohost/helpers
# UPGRADE_SAME
upgrade_type=$(ynh_check_app_version_changed)
# show variables - used from installed or from to be upgraded version?
# variables of the new upgrade version are used
# env
ynh_script_progression --message="Stopping flohmarkt and CouchDB..." --weight=5
# stop flohmarkt
ynh_systemd_action --service_name=$app --action="stop"
@ -18,8 +22,8 @@ ynh_systemd_action --service_name=couchdb --action="stop"
# Upgrade ynh4 → ynh5, change of paths and filenames
# https://matrix.to/#/!PauySEslPVuJCJCwlZ:matrix.org/$auU_rSL6MACt9wkyFGlCQbO8ivFlU0ztYW74TimZdcM?via=matrix.org&via=aria-net.org&via=sans-nuage.fr
# and follow-ups
if ynh_compare_current_package_version --comparision lt --version 0.00~ynh5 &&
( [[ $upgrade_type == UPGRADE_PACKAGE ]] || [[ $upgrade_type == UPGRADE_APP ]] )
if ynh_compare_current_package_version --comparison lt --version 0.00~ynh5 &&
( [[ "$upgrade_type" == UPGRADE_PACKAGE ]] || [[ "$upgrade_type" == UPGRADE_APP ]] )
then
flohmarkt_ynh_upgrade_path_ynh5
fi
@ -59,14 +63,7 @@ ynh_setup_source --dest_dir="$flohmarkt_app_dir/"
ynh_script_progression --message="Upgrading flohmarkt python dependencies..." --weight=6
# upgrade python environment / install new dependencies
(
set +o nounset
source "$flohmarkt_venv_dir/bin/activate"
set -o nounset
set -x
$flohmarkt_venv_dir/bin/python3 -m ensurepip
$flohmarkt_venv_dir/bin/pip3 install -r "$flohmarkt_app_dir/requirements.txt"
)
flohmarkt_ynh_venv_requirements
# upgrade flohmarkt.conf
ynh_script_progression --message="Upgrading flohmarkt configuration..." --weight=1
@ -107,6 +104,6 @@ ynh_add_fail2ban_config --logpath="$flohmarkt_logfile" --failregex='INFO: +<HOST
# start flohmarkt
ynh_script_progression --message="Starting flohmarkt..." --weight=3
ynh_systemd_action --service_name=$flohmarkt_filename --action="start" --line_match="INFO: Application startup complete."
ynh_systemd_action --service_name=$flohmarkt_filename --action="start" --line_match='INFO: *Application startup complete.' --log_path="$flohmarkt_logfile" --timeout=30
ynh_script_progression --message="Upgrade of $app completed" --last

View file

@ -1,10 +1,9 @@
test_format = 1.0
[default]
# still in development
# https://codeberg.org/ChriChri/flohmarkt_ynh/issues/4
# https://codeberg.org/ChriChri/flohmarkt_ynh/issues/11
exclude = ["install.multi", "change_url", "install_subdir"]
# changing the url of a fediverse instance doesn't make sense
# it'll break federation anyway so we do not offer it
exclude = ["change_url"]
args.password_couchdb_admin = "TestPasswordCouchDBadmin"
args.password_couchdb_flohmarkt = "TestPasswordCouchDBflohmarkt"