1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/flohmarkt_ynh.git synced 2024-09-03 18:36:30 +02:00
This commit is contained in:
Chris Vogel 2024-04-22 14:37:16 +02:00
parent 8521aca433
commit 2efa2305df

View file

@ -1,90 +1,104 @@
#!/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
# UPGRADE_PACKAGE if only the YunoHost package has changed
# UPGRADE_APP if the upstream app version has changed
# DOWNGRADE
# UPGRADE_SAME
upgrade_type=$(ynh_check_app_version_changed) upgrade_type=$(ynh_check_app_version_changed)
#================================================= ynh_script_progression --message="Stopping flohmarkt and CouchDB..." --weight=5
# NGINX CONFIGURATION # stop flohmarkt
#================================================= ynh_systemd_action --service_name=$app --action="stop"
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2 # stop couchdb
ynh_systemd_action --service_name=couchdb --action="stop"
# Create a dedicated NGINX config # upgrade couchdb
ynh_add_nginx_config ynh_script_progression --message="Upgrading CouchDB..." --weight=50
echo "\
couchdb couchdb/mode select standalone
couchdb couchdb/mode seen true
couchdb couchdb/bindaddress string 127.0.0.1
couchdb couchdb/bindaddress seen true
couchdb couchdb/cookie string $password
couchdb couchdb/adminpass password $password
couchdb couchdb/adminpass seen true
couchdb couchdb/adminpass_again password $password
couchdb couchdb/adminpass_again seen true" | debconf-set-selections
DEBIAN_FRONTEND=noninteractive # apt-get install -y --force-yes couchdb
ynh_install_extra_app_dependencies \
--repo="deb https://apache.jfrog.io/artifactory/couchdb-deb/ $(lsb_release -c -s) main" \
--key="https://couchdb.apache.org/repo/keys.asc" \
--package="couchdb"
#================================================= # upgrade couchdb config
# SPECIFIC UPGRADE ynh_script_progression --message="Updating couchdb configuration file..." --weight=1
#================================================= ynh_add_config --template="../conf/05-flohmarkt.ini" --destination="/opt/couchdb/etc/local.d/05-flohmarkt.ini"
# UPGRADING COUCHDB chown root:couchdb /opt/couchdb/etc/local.d/05-flohmarkt.ini
#================================================= chmod 640 /opt/couchdb/etc/local.d/05-flohmarkt.ini
if [ "$upgrade_type" == "UPGRADE_APP" ] # start couchdb to pick up changes
then ynh_script_progression --message="Starting couchdb..." --weight=1
ynh_script_progression --message="Upgrading CouchDB..." --weight=50 ynh_systemd_action --service_name=couchdb --action="start"
systemctl status couchdb
echo "\ # install upgrade for flohmarkt
couchdb couchdb/mode select standalone ynh_script_progression --message="Upgrading flohmarkt..." --weight=4
couchdb couchdb/mode seen true ynh_setup_source --dest_dir="$install_dir/$app/"
couchdb couchdb/bindaddress string 127.0.0.1
couchdb couchdb/bindaddress seen true
couchdb couchdb/cookie string $password
couchdb couchdb/adminpass password $password
couchdb couchdb/adminpass seen true
couchdb couchdb/adminpass_again password $password
couchdb couchdb/adminpass_again seen true" | debconf-set-selections
DEBIAN_FRONTEND=noninteractive # apt-get install -y --force-yes couchdb
ynh_install_extra_app_dependencies \ ynh_script_progression --message="Upgrading flohmarkt python dependencies..." --weight=5
--repo="deb https://apache.jfrog.io/artifactory/couchdb-deb/ $(lsb_release -c -s) main" \ # upgrade python environment / install new dependencies
--key="https://couchdb.apache.org/repo/keys.asc" \ (
--package="couchdb" set +o nounset
fi source "$install_dir/venv/bin/activate"
set -o nounset
set -x
$install_dir/venv/bin/python3 -m ensurepip
$install_dir/venv/bin/pip3 install -r "$install_dir/$app/requirements.txt"
)
#================================================= # upgrade flohmarkt.conf
# UPDATE A CONFIG FILE ynh_script_progression --message="Upgrading flohmarkt configuration..." --weight=1
#================================================= ynh_add_config --template="../conf/flohmarkt.conf" --destination="$install_dir/$app/flohmarkt.conf"
ynh_script_progression --message="Updating a configuration file..." --weight=1
ynh_add_config --template="../conf/05-flohmarkt.ini" --destination="$install_dir/etc/local.d/05-flohmarkt.ini" ynh_script_progression --message="Upgrading flohmarkt couchdb..." --weight=10
# run initialize_couchdb.py
(
set +o nounset
source "$install_dir/venv/bin/activate"
set -o nounset
cd "$install_dir/$app"
# 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
)
chmod 750 "$install_dir" # systemd service upgrade
chmod -R o-rwx "$install_dir" ynh_script_progression --message="Upgrading flohmarkt systemd service..." --weight=1
chown -R "$app:$app" "$install_dir" ynh_add_systemd_config
# INTEGRATE SERVICE IN YUNOHOST
ynh_script_progression --message="Integrating service in YunoHost..." --weight=2
yunohost service add $app --description="A decentral federated small advertisement platform" --log="/var/log/$app/$app.log"
#================================================= # upgrade logrotate
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
# Use logrotate to manage app-specific logfile(s) # Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append ynh_use_logrotate --non-append
#================================================= # upgrade nginx configuration
# INTEGRATE SERVICE IN YUNOHOST ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
#================================================= ynh_add_nginx_config
ynh_script_progression --message="Integrating service in YunoHost..." --weight=2
yunohost service add $app --description="A decentral federated small advertisement platform" --log="/var/log/$app/$app.log"
#=================================================
# UPGRADE FAIL2BAN # UPGRADE FAIL2BAN
#================================================= # ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=3
ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=3
# Create a dedicated Fail2Ban config # Create a dedicated Fail2Ban config
ynh_add_fail2ban_config --logpath="/var/log/couchdb/couchdb.log" --failregex="[warning] .*couch_httpd_auth: Authentication failed for user .+ from <HOST>" --max_retry=5 # ynh_add_fail2ban_config --logpath="/var/log/couchdb/couchdb.log" --failregex="[warning] .*couch_httpd_auth: Authentication failed for user .+ from <HOST>" --max_retry=5
#================================================= # start flohmarkt
# END OF SCRIPT ynh_script_progression --message="Starting flohmarkt..." --weight=3
#================================================= ynh_systemd_action --service_name=$app --action="start" --line_match="INFO: Application startup complete."
ynh_script_progression --message="Upgrade of $app completed" --last ynh_script_progression --message="Upgrade of $app completed" --last