Protéger les données persistantes à la mise à jour
This commit is contained in:
parent
a2e827a11f
commit
a5d0930028
5 changed files with 67 additions and 3 deletions
|
|
@ -65,6 +65,12 @@ prepare_persistent_paths() {
|
|||
ln -s "$data_dir/storage" "$install_dir/storage"
|
||||
ln -s "$data_dir/media" "$install_dir/public/media"
|
||||
|
||||
repair_and_verify_permissions
|
||||
}
|
||||
|
||||
repair_and_verify_permissions() {
|
||||
ynh_print_info "Checking Globinours persistent-data permissions..."
|
||||
|
||||
chown -R "$app:www-data" "$install_dir"
|
||||
chown -R "$app:$app" "$data_dir"
|
||||
chmod -R u=rwX,g=rX,o= "$install_dir"
|
||||
|
|
@ -74,4 +80,47 @@ prepare_persistent_paths() {
|
|||
chmod 0710 "$data_dir"
|
||||
chown -R "$app:www-data" "$data_dir/media"
|
||||
chmod -R u=rwX,g=rX,o= "$data_dir/media"
|
||||
|
||||
if ! ynh_exec_as_app test -r "$data_dir" || ! ynh_exec_as_app test -w "$data_dir"; then
|
||||
ynh_die --message="The Globinours system user cannot read and write its persistent data directory."
|
||||
fi
|
||||
if ! runuser -u www-data -- test -x "$data_dir" || ! runuser -u www-data -- test -r "$data_dir/media"; then
|
||||
ynh_die --message="Nginx cannot access the Globinours public media directory."
|
||||
fi
|
||||
if [[ -f "$data_dir/refuge.sqlite" ]]; then
|
||||
local integrity_check
|
||||
integrity_check="$(ynh_exec_as_app sqlite3 "$data_dir/refuge.sqlite" "PRAGMA quick_check;")"
|
||||
if [[ "$integrity_check" != "ok" ]]; then
|
||||
ynh_die --message="The Globinours database failed its integrity check."
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
inventory_persistent_data() {
|
||||
local inventory_file="$1"
|
||||
|
||||
: > "$inventory_file"
|
||||
if [[ -f "$data_dir/refuge.sqlite" ]]; then
|
||||
printf '%s\n' "refuge.sqlite" >> "$inventory_file"
|
||||
fi
|
||||
for persistent_subdir in association grants medical-documents private-media media; do
|
||||
if [[ -d "$data_dir/$persistent_subdir" ]]; then
|
||||
find "$data_dir/$persistent_subdir" -type f -printf '%P\n' |
|
||||
sed "s#^#$persistent_subdir/#" >> "$inventory_file"
|
||||
fi
|
||||
done
|
||||
sort -u -o "$inventory_file" "$inventory_file"
|
||||
}
|
||||
|
||||
verify_persistent_inventory() {
|
||||
local inventory_file="$1"
|
||||
local missing_file
|
||||
|
||||
while IFS= read -r persistent_file; do
|
||||
[[ -z "$persistent_file" ]] && continue
|
||||
if [[ ! -f "$data_dir/$persistent_file" ]]; then
|
||||
missing_file="$persistent_file"
|
||||
ynh_die --message="Persistent data disappeared during the operation: $missing_file"
|
||||
fi
|
||||
done < "$inventory_file"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ done
|
|||
prepare_persistent_paths
|
||||
install_yunohost_logo
|
||||
ynh_exec_as_app php "$install_dir/scripts/migrate.php"
|
||||
repair_and_verify_permissions
|
||||
|
||||
ynh_systemctl --service="php$php_version-fpm" --action=reload
|
||||
ynh_systemctl --service=nginx --action=reload
|
||||
|
|
|
|||
|
|
@ -24,12 +24,17 @@ fi
|
|||
|
||||
migrate_legacy_data
|
||||
|
||||
data_inventory="$(mktemp)"
|
||||
data_guard="$data_dir/.globinours-upgrade-guard"
|
||||
inventory_persistent_data "$data_inventory"
|
||||
touch "$data_guard"
|
||||
|
||||
#=================================================
|
||||
# ENABLE MAINTENANCE MODE
|
||||
#=================================================
|
||||
|
||||
touch "$data_dir/storage/maintenance.flag"
|
||||
trap 'rm -f "$data_dir/storage/maintenance.flag"' EXIT
|
||||
trap 'rm -f "$data_dir/storage/maintenance.flag" "$data_guard" "$data_inventory"' EXIT
|
||||
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
|
|
@ -56,7 +61,13 @@ ynh_config_add_phpfpm
|
|||
ynh_config_add_nginx
|
||||
ynh_exec_as_app php "$install_dir/scripts/migrate.php"
|
||||
|
||||
rm -f "$data_dir/storage/maintenance.flag"
|
||||
if [[ ! -f "$data_guard" ]]; then
|
||||
ynh_die --message="The persistent data directory was replaced during the upgrade."
|
||||
fi
|
||||
verify_persistent_inventory "$data_inventory"
|
||||
repair_and_verify_permissions
|
||||
|
||||
rm -f "$data_dir/storage/maintenance.flag" "$data_guard" "$data_inventory"
|
||||
trap - EXIT
|
||||
|
||||
ynh_systemctl --service="php$php_version-fpm" --action=reload
|
||||
|
|
|
|||
Loading…
Reference in a new issue