1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/pgadmin_ynh.git synced 2024-09-03 19:56:38 +02:00
pgadmin_ynh/scripts/restore

77 lines
2.6 KiB
Text
Raw Normal View History

2017-11-14 16:05:26 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
2017-11-14 16:05:26 +01:00
# IMPORT GENERIC HELPERS
source /usr/share/yunohost/helpers
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
# Import common cmd
source ../settings/scripts/experimental_helper.sh
2017-11-16 21:10:21 +01:00
source ../settings/scripts/_common.sh
2017-11-14 16:05:26 +01:00
# LOAD SETTINGS
2019-06-06 22:39:49 +02:00
ynh_script_progression --message="Loading settings..."
domain=$(ynh_app_setting_get --app $app --key domain)
path_url=$(ynh_app_setting_get --app $app --key path)
admin=$(ynh_app_setting_get --app $app --key admin)
final_path=$(ynh_app_setting_get --app $app --key final_path)
db_name=$(ynh_app_setting_get --app $app --key db_name)
db_user=$(ynh_app_setting_get --app $app --key db_user)
db_pwd=$(ynh_app_setting_get --app $app --key db_pwd)
2017-11-14 16:05:26 +01:00
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
2017-11-16 21:10:21 +01:00
# Install dependance
2019-06-06 22:39:49 +02:00
ynh_script_progression --message="Reinstalling dependencies..." --weight=5
ynh_install_app_dependencies $dependances
2017-11-14 16:05:26 +01:00
2017-11-16 21:10:21 +01:00
# Create user
2019-06-06 22:39:49 +02:00
ynh_script_progression --message="Recreating the dedicated system user..."
ynh_system_user_create --username $pgadmin_user --home_dir /var/lib/$app
2017-11-14 16:05:26 +01:00
2017-11-16 21:10:21 +01:00
# Restore all config and data
2019-06-06 22:39:49 +02:00
ynh_script_progression --message="Restoring files..." --weight=5
2017-11-16 21:10:21 +01:00
ynh_restore
2017-11-14 16:05:26 +01:00
2017-11-16 21:10:21 +01:00
# POPULATE THE DATABASE
2019-06-06 22:39:49 +02:00
ynh_script_progression --message="Reconfiguring Postgresql database..."
2017-11-16 21:10:21 +01:00
ynh_psql_test_if_first_run
2019-06-06 22:39:49 +02:00
ynh_psql_execute_as_root \
--sql "CREATE USER ${db_user} WITH PASSWORD '${db_pwd}' SUPERUSER CREATEDB CREATEROLE REPLICATION"
# Restore systemd configuration
ynh_script_progression --message="Reconfiguring application..."
systemctl daemon-reload
systemctl enable "uwsgi-app@$app.service"
2017-11-14 16:05:26 +01:00
#=================================================
# GENERIC FINALIZATION
#=================================================
2017-11-16 21:10:21 +01:00
# Set the permission
2019-06-11 22:27:54 +02:00
ynh_script_progression --message="Protecting directory..."
2017-11-16 21:10:21 +01:00
set_permission
2017-11-14 16:05:26 +01:00
2017-11-16 21:10:21 +01:00
# Restrict access to admin only
2019-06-11 22:27:54 +02:00
ynh_script_progression --message="Configuring permissions..."
2017-11-16 21:10:21 +01:00
yunohost app addaccess --users=$admin $app
2017-11-14 16:05:26 +01:00
2017-11-16 21:10:21 +01:00
# Configuration de logrotate
2019-06-06 22:39:49 +02:00
ynh_script_progression --message="Configuring log rotation..."
2019-10-01 21:31:45 +02:00
ynh_use_logrotate --logfile /var/log/pgadmin
2017-11-14 16:05:26 +01:00
2018-03-15 23:33:57 +01:00
# reload uwsgi and nginx
2019-06-11 22:27:54 +02:00
ynh_script_progression --message="Starting pgadmin services..." --weight=3
2019-06-06 22:39:49 +02:00
ynh_systemd_action --service_name "uwsgi-app@$app.service" \
--line_match "WSGI app 0 (mountpoint='$path_url') ready in [[:digit:]]* seconds on interpreter" --log_path "/var/log/uwsgi/$app/pgadmin.log"
2017-11-14 16:05:26 +01:00
systemctl reload nginx
2019-06-06 22:39:49 +02:00
ynh_script_progression --message="Restoration completed for $app" --last