restore 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/bash
  2. source ../settings/scripts/_common.sh
  3. source /usr/share/yunohost/helpers
  4. # restore couchdb directory
  5. ynh_script_progression --message="Restoring couchdb directory..." --weight=1
  6. ynh_restore_file --origin_path="/var/lib/couchdb"
  7. # reinstall couchdb
  8. ynh_script_progression --message="Reinstalling couchdb..." --weight=40
  9. echo "\
  10. couchdb couchdb/mode select standalone
  11. couchdb couchdb/mode seen true
  12. couchdb couchdb/bindaddress string 127.0.0.1
  13. couchdb couchdb/bindaddress seen true
  14. couchdb couchdb/cookie string $couchdb_magic_cookie
  15. couchdb couchdb/adminpass password $password_couchdb_admin
  16. couchdb couchdb/adminpass seen true
  17. couchdb couchdb/adminpass_again password $password_couchdb_admin
  18. couchdb couchdb/adminpass_again seen true" | debconf-set-selections
  19. DEBIAN_FRONTEND=noninteractive # apt-get install -y --force-yes couchdb
  20. ynh_install_extra_app_dependencies \
  21. --repo="deb https://apache.jfrog.io/artifactory/couchdb-deb/ $(lsb_release -c -s) main" \
  22. --key="https://couchdb.apache.org/repo/keys.asc" \
  23. --package="couchdb"
  24. # stop couchdb
  25. systemctl stop couchdb
  26. # add couchdb configuration
  27. ynh_script_progression --message="Adding a configuration file..." --weight=2
  28. ynh_restore_file --origin_path="/opt/couchdb/etc/local.d/05-flohmarkt.ini"
  29. chown root:couchdb /opt/couchdb/etc/local.d/05-flohmarkt.ini
  30. chmod 640 /opt/couchdb/etc/local.d/05-flohmarkt.ini
  31. # start couchdb
  32. systemctl start couchdb
  33. systemctl status couchdb
  34. # RESTORE THE APP MAIN DIR
  35. ynh_script_progression --message="Restoring the app main directory..." --weight=10
  36. ynh_restore_file --origin_path="$install_dir"
  37. # RESTORE THE DATA DIRECTORY
  38. ynh_script_progression --message="Restoring the data directory..." --weight=1
  39. ynh_restore_file --origin_path="$data_dir" --not_mandatory
  40. mkdir -p $data_dir
  41. # restore logfiles
  42. # independent of the question whether one wants the logfiles in a backup (as you can
  43. # see I decided I wanted them for the time being) it is important to create the log
  44. # directory and file so that the systemd.service can redirect STDOUT to the file.
  45. # If the logfile(or maybe just -directory?) is missing the service will not start
  46. # on a fresh install, because directory and/or file do not exist.
  47. ynh_script_progression --message="Restoring log directory and logfiles..." --weight=1
  48. ynh_restore_file --origin_path="/var/log/$app" --not_mandatory
  49. mkdir -p -m755 "/var/log/$app"
  50. touch "/var/log/$app/$app"
  51. # logfile contains possibly the secret setup URL
  52. chmod 640 "/var/log/$app/$app"
  53. # RESTORE FAIL2BAN CONFIGURATION
  54. ynh_script_progression --message="Restoring the Fail2Ban configuration..." --weight=2
  55. ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf"
  56. ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf"
  57. ynh_systemd_action --action=restart --service_name=fail2ban
  58. # RESTORE THE NGINX CONFIGURATION
  59. ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1
  60. ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
  61. # RESTORE THE LOGROTATE CONFIGURATION
  62. ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1
  63. ynh_restore_file --origin_path="/etc/logrotate.d/$app"
  64. # add some debugging to find #21
  65. ls -lR /var/lib/couchdb /opt/couchdb/etc $install_dir /var/log/couchdb/couchdb.log \
  66. /var/log/$app/$app.log $data_dir /etc/nginx/conf.d/$domain.d/$app.conf || true
  67. cat $install_dir/$app/flohmarkt.conf /opt/couchdb/etc/local.d/05-flohmarkt.ini
  68. tail -n50 /var/log/couchdb/couchdb.log /var/log/$app/$app.log || true
  69. # restore flohmarkt systemd service and integrate service into yunohost
  70. ynh_script_progression --message="Restoring flohmarkt.service and integrating service into YunoHost..." --weight=1
  71. ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
  72. ynh_systemd_action --action=enable
  73. yunohost service add $app --description="A decentral federated small advertisement platform" --log="/var/log/$app/$app.log"
  74. ynh_systemd_action --action=start --line_match="INFO: Application startup complete."
  75. # add some debugging to find #21
  76. systemctl status flohmarkt
  77. systemctl status couchdb
  78. # RELOAD NGINX
  79. ynh_script_progression --message="Reloading NGINX web server..." --weight=1
  80. ynh_systemd_action --service_name=nginx --action=reload
  81. # add some debugging to find #21
  82. ps axuf
  83. netstat -pnlt
  84. cat /etc/nginx/conf.d/$domain.d/$app.conf
  85. curl -D - "http://admin:$password_couchdb_admin@127.0.0.1:5984" || true
  86. curl -D - "http://flohmarkt:$password_couchdb_flohmarkt@127.0.0.1:5984" || true
  87. curl -D - "http://127.0.0.1:8000" || true
  88. curl -D - "http://$domain" || true
  89. curl -kD - "https://$domain" || true
  90. ynh_script_progression --message="Restoration completed for $app" --last