upgrade 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/bin/bash
  2. source _common.sh
  3. source /usr/share/yunohost/helpers
  4. # UPGRADE_PACKAGE if only the YunoHost package has changed
  5. # UPGRADE_APP if the upstream app version has changed
  6. # DOWNGRADE
  7. # UPGRADE_SAME
  8. upgrade_type=$(ynh_check_app_version_changed)
  9. ynh_script_progression --message="Stopping flohmarkt and CouchDB..." --weight=5
  10. # stop flohmarkt
  11. ynh_systemd_action --service_name=$app --action="stop"
  12. # stop couchdb
  13. ynh_systemd_action --service_name=couchdb --action="stop"
  14. # upgrade couchdb
  15. ynh_script_progression --message="Upgrading CouchDB..." --weight=50
  16. echo "\
  17. couchdb couchdb/mode select standalone
  18. couchdb couchdb/mode seen true
  19. couchdb couchdb/bindaddress string 127.0.0.1
  20. couchdb couchdb/bindaddress seen true
  21. couchdb couchdb/cookie string $password
  22. couchdb couchdb/adminpass password $password
  23. couchdb couchdb/adminpass seen true
  24. couchdb couchdb/adminpass_again password $password
  25. couchdb couchdb/adminpass_again seen true" | debconf-set-selections
  26. DEBIAN_FRONTEND=noninteractive # apt-get install -y --force-yes couchdb
  27. ynh_install_extra_app_dependencies \
  28. --repo="deb https://apache.jfrog.io/artifactory/couchdb-deb/ $(lsb_release -c -s) main" \
  29. --key="https://couchdb.apache.org/repo/keys.asc" \
  30. --package="couchdb"
  31. # upgrade couchdb config
  32. ynh_script_progression --message="Updating couchdb configuration file..." --weight=1
  33. ynh_add_config --template="../conf/05-flohmarkt.ini" --destination="/opt/couchdb/etc/local.d/05-flohmarkt.ini"
  34. chown root:couchdb /opt/couchdb/etc/local.d/05-flohmarkt.ini
  35. chmod 640 /opt/couchdb/etc/local.d/05-flohmarkt.ini
  36. # start couchdb to pick up changes
  37. ynh_script_progression --message="Starting couchdb..." --weight=1
  38. ynh_systemd_action --service_name=couchdb --action="start"
  39. systemctl status couchdb
  40. # install upgrade for flohmarkt
  41. ynh_script_progression --message="Upgrading flohmarkt..." --weight=4
  42. ynh_setup_source --dest_dir="$install_dir/$app/"
  43. ynh_script_progression --message="Upgrading flohmarkt python dependencies..." --weight=5
  44. # upgrade python environment / install new dependencies
  45. (
  46. set +o nounset
  47. source "$install_dir/venv/bin/activate"
  48. set -o nounset
  49. set -x
  50. $install_dir/venv/bin/python3 -m ensurepip
  51. $install_dir/venv/bin/pip3 install -r "$install_dir/$app/requirements.txt"
  52. )
  53. # upgrade flohmarkt.conf
  54. ynh_script_progression --message="Upgrading flohmarkt configuration..." --weight=1
  55. ynh_add_config --template="../conf/flohmarkt.conf" --destination="$install_dir/$app/flohmarkt.conf"
  56. ynh_script_progression --message="Upgrading flohmarkt couchdb..." --weight=10
  57. # run initialize_couchdb.py
  58. (
  59. set +o nounset
  60. source "$install_dir/venv/bin/activate"
  61. set -o nounset
  62. cd "$install_dir/$app"
  63. # initialize_couchdb seems to re-try on connect problems endlessly blocking the yunohost api
  64. # give it 45 seconds to finish and then fail
  65. # https://codeberg.org/ChriChri/flohmarkt_ynh/issues/13
  66. timeout 45 python3 initialize_couchdb.py $password_couchdb_admin $password_couchdb_flohmarkt
  67. )
  68. # systemd service upgrade
  69. ynh_script_progression --message="Upgrading flohmarkt systemd service..." --weight=1
  70. ynh_add_systemd_config
  71. # INTEGRATE SERVICE IN YUNOHOST
  72. ynh_script_progression --message="Integrating service in YunoHost..." --weight=2
  73. yunohost service add $app --description="A decentral federated small advertisement platform" --log="/var/log/$app/$app.log"
  74. # upgrade logrotate
  75. ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
  76. # Use logrotate to manage app-specific logfile(s)
  77. ynh_use_logrotate --non-append
  78. # upgrade nginx configuration
  79. ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
  80. ynh_add_nginx_config
  81. # UPGRADE FAIL2BAN
  82. # ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=3
  83. # Create a dedicated Fail2Ban config
  84. # ynh_add_fail2ban_config --logpath="/var/log/couchdb/couchdb.log" --failregex="[warning] .*couch_httpd_auth: Authentication failed for user .+ from <HOST>" --max_retry=5
  85. # start flohmarkt
  86. ynh_script_progression --message="Starting flohmarkt..." --weight=3
  87. ynh_systemd_action --service_name=$app --action="start" --line_match="INFO: Application startup complete."
  88. ynh_script_progression --message="Upgrade of $app completed" --last