From e1ec0e97e1b4d253cda6d5d8b851b6a172db60a2 Mon Sep 17 00:00:00 2001 From: Chris Vogel Date: Thu, 30 May 2024 10:59:43 +0200 Subject: [PATCH] moved initialize_couchdb into _common.sh and replaced it in install and upgrade by a function call --- scripts/_common.sh | 16 ++++++++++++++++ scripts/change_url | 25 ------------------------- scripts/install | 13 ++----------- scripts/upgrade | 12 +----------- 4 files changed, 19 insertions(+), 47 deletions(-) delete mode 100644 scripts/change_url diff --git a/scripts/_common.sh b/scripts/_common.sh index 97b0b75..1c4abfc 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -120,6 +120,22 @@ flohmarkt_ynh_up_inst_couchdb() { --package="couchdb" } +# (re)initialise database during install and upgrade +flohmarkt_ynh_initialize_couchdb() { + # run in a sub shell to not source the venv activate to the rest of the script + ( + set +o nounset + source "$flohmarkt_venv_dir/bin/activate" + set -o nounset + # change directory to where flohmarkt.conf is located + cd $flohmarkt_app_dir + # initialize_couchdb seems to re-try on connect problems endlessly blocking the yunohost api + # give it 45 seconds to finish and then fail + # https://codeberg.org/ChriChri/flohmarkt_ynh/issues/13 + timeout 45 python3 initialize_couchdb.py $password_couchdb_admin + ) +} + flohmarkt_ynh_dump_couchdb() { ../settings/scripts/couchdb-dump/couchdb-dump.sh -b -H 127.0.0.1 -d "${app}" \ -q -u admin -p "${password_couchdb_admin}" -f "${YNH_CWD}/${app}.json" diff --git a/scripts/change_url b/scripts/change_url deleted file mode 100644 index 16e0f3c..0000000 --- a/scripts/change_url +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - -source _common.sh -source /usr/share/yunohost/helpers - -#================================================= -# STANDARD MODIFICATIONS -#================================================= -# MODIFY URL IN NGINX CONF -#================================================= -ynh_script_progression --message="Updating NGINX web server configuration..." --weight=2 - -ynh_change_url_nginx_config - -#================================================= -# END OF SCRIPT -#================================================= - -ynh_script_progression --message="Change of URL completed for $app" --last diff --git a/scripts/install b/scripts/install index 878252d..f22b933 100755 --- a/scripts/install +++ b/scripts/install @@ -17,7 +17,7 @@ then fi # INITIALIZE AND STORE SETTINGS -# todo: do we need to store the password un-encrypted somewhere on the system? +# TODO: do we need to store the password un-encrypted somewhere on the system? # → there's no way to get the admin password later if sometimes in the future deleting # the app will delete its specific database only (instead of the whole couchdb server as # of now in the earliest versions of the integration). @@ -76,16 +76,7 @@ ynh_add_config --template="../conf/flohmarkt.conf" --destination="$flohmarkt_app # setup couchdb ynh_script_progression --message="Setup couchdb database and user for flohmarkt..." --weight=2 flohmarkt_ynh_check_old_couchdb -( - set +o nounset - source "$flohmarkt_venv_dir/bin/activate" - set -o nounset - cd "$flohmarkt_app_dir" - # initialize_couchdb seems to re-try on connect problems endlessly blocking the yunohost api - # give it 45 seconds to finish and then fail - # https://codeberg.org/ChriChri/flohmarkt_ynh/issues/13 - timeout 45 python3 initialize_couchdb.py $password_couchdb_admin -) +flohmarkt_ynh_initialize_couchdb # SETUP LOGROTATE ynh_script_progression --message="Configuring log rotation..." --weight=2 diff --git a/scripts/upgrade b/scripts/upgrade index 8b9c0bc..36f9d60 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -59,17 +59,7 @@ ynh_script_progression --message="Upgrading flohmarkt configuration..." --weight ynh_add_config --template="../conf/flohmarkt.conf" --destination="$flohmarkt_app_dir/flohmarkt.conf" ynh_script_progression --message="Upgrading flohmarkt couchdb..." --weight=10 -# run initialize_couchdb.py -( - set +o nounset - source "$flohmarkt_venv_dir/bin/activate" - set -o nounset - cd "$flohmarkt_app_dir" - # initialize_couchdb seems to re-try on connect problems endlessly blocking the yunohost api - # give it 45 seconds to finish and then fail - # https://codeberg.org/ChriChri/flohmarkt_ynh/issues/13 - timeout 45 python3 initialize_couchdb.py $password_couchdb_admin $password_couchdb_flohmarkt -) +flohmarkt_ynh_initialize_couchdb # set file permissions for install dir flohmarkt_ynh_set_permission