From 83845d69ed334eb6ba52c5170bad82928b1e754c Mon Sep 17 00:00:00 2001 From: nin_o_0 Date: Sat, 18 Oct 2025 20:37:52 +0200 Subject: [PATCH] Update update_synapse_for_appservice.sh improve app service error handling for successful run --- sources/update_synapse_for_appservice.sh | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/sources/update_synapse_for_appservice.sh b/sources/update_synapse_for_appservice.sh index d920fb91..71fb68ad 100644 --- a/sources/update_synapse_for_appservice.sh +++ b/sources/update_synapse_for_appservice.sh @@ -1,14 +1,11 @@ #!/bin/bash - set -eu - app=__APP__ YNH_HELPERS_VERSION=2.1 YNH_APP_ACTION='' YNH_STDINFO=/dev/stdout source /usr/share/yunohost/helpers -port_synapse_tls=$(ynh_app_setting_get --key=port_synapse_tls) service_config_file="/etc/matrix-$app/conf.d/app_service.yaml" backup_app_service=$(mktemp) @@ -17,11 +14,9 @@ cp "$service_config_file" "$backup_app_service" if [ -n "$(ls "/etc/matrix-$app/app-service/")" ]; then echo "app_service_config_files:" > "$service_config_file" - for f in "/etc/matrix-$app/app-service/"*; do echo " - $f" >> "$service_config_file" done - chown "$app" "/etc/matrix-$app/app-service/"* chmod 600 "/etc/matrix-$app/app-service/"* else @@ -31,18 +26,23 @@ chown "$app" "$service_config_file" chmod 600 "$service_config_file" set +e -ynh_systemctl --service="$app".service --action=restart --wait_until="Synapse now listening on TCP port $port_synapse_tls" --log_path="/var/log/matrix-$app/homeserver.log" --timeout=300 +ynh_systemctl --service="$app" --action=restart --log_path=systemd res=$? set -e -set +x -if [ $res -eq 0 ]; then - rm "$backup_app_service" - exit 0 -else +# Wait a moment and verify service is actually running +sleep 5 +if ! systemctl is-active --quiet "$app"; then echo "Failed to restart synapse with the new config file. Restore the old config file !!" cp "$backup_app_service" "$service_config_file" rm "$backup_app_service" - ynh_systemctl --service="$app".service --action=restart --wait_until="Synapse now listening on TCP port $port_synapse_tls" --log_path="/var/log/matrix-$app/homeserver.log" --timeout=300 - exit 1 + ynh_systemctl --service="$app" --action=restart --log_path=systemd + sleep 5 + if ! systemctl is-active --quiet "$app"; then + echo "ERROR: Synapse failed to start even after restoring config!" + exit 1 + fi fi + +rm "$backup_app_service" +exit 0