[Synapse] Le service redémarre en boucle

J’ai arrêté le service synapse, fait un backup local et un backup via borg et puis supprimé l’application.

# systemctl stop synapse

# yunohost backup create -n manual-synapse --apps synapse

# yunohost backup create -n manual-borg-synapse --apps synapse --method borg

# yunohost app remove synapse

J’ai ensuite créé un sous-domaine dédié à Synapse ( synapse.mondomaine.be ), installé un certificat let’s encrypt dessus et j’ai ensuite réinstallé Synapse via la webadmin.

J’ai ajouté une entrée DNS pour rediriger vers mon nouveau sous-domaine :

_matrix._tcp.synapse.mondomaine.be. 3600    IN      SRV     10 0 8448 synapse.mondomaine.be.

Mon idée maintenant, c’est de restaurer les données sur cette nouvelle installation. Je pensais pouvoir faire quelque chose comme ça :

# yunohost backup restore manual-synapse --apps synaps

Sauf que ça me renvoie une erreur (“l’application existe déjà”). Ok. J’ai une instance de Synapse. Comment je restaure mes données dessus maintenant ? :woozy_face:

Je suis tombé sur ce post : Synapse backup/restore failed - #9 by ludovic

# cd /home/yunohost.backup/archives/

# tar -xvf manual-synapse.tar -C ../tmp/

# cd /home/yunohost.backup/tmp/apps/synapse/settings/scripts/

J’ai regardé s’il fallait modifier le script :

# vim restore

# chmod +x restore

# ./restore

Et voici le retour du script :

./restore: line 10: ../settings/scripts/_common.sh: No such file or directory
./restore: line 11: ../settings/scripts/experimental_helper.sh: No such file or directory
+ set +o xtrace
+ echo '! Helper used in legacy mode !'
+ set +x
+ echo '[....................] > Loading settings...'
/usr/share/yunohost/helpers.d/logging: line 38: $YNH_STDINFO: ambiguous redirect
+ set -o xtrace
+ app=synapse
+ ynh_script_progression '--message=Configuring system groups'
+ set +o xtrace
+ set +o xtrace
+ echo '! Helper used in legacy mode !'
+ set +x
+ echo '[....................] > Configuring system groups'
/usr/share/yunohost/helpers.d/logging: line 38: $YNH_STDINFO: ambiguous redirect
+ set -o xtrace
+ adduser synapse ssl-cert
The user `synapse' is already a member of `ssl-cert'.
+ adduser turnserver ssl-cert
The user `turnserver' is already a member of `ssl-cert'.
+ ynh_script_progression '--message=Fixing database type...' --weight=1
+ set +o xtrace
+ set +o xtrace
+ echo '! Helper used in legacy mode !'
+ set +x
+ echo '[....................] > Fixing database type...'
/usr/share/yunohost/helpers.d/logging: line 38: $YNH_STDINFO: ambiguous redirect
+ set -o xtrace
+ ynh_psql_execute_as_root '--sql=update pg_database set datcollate='\''C'\'', datctype='\''C'\'' where datname='\'''\'';'
+ local legacy_args=sd
+ args_array=(['s']='sql=' ['d']='database=')
+ local -A args_array
+ local sql
+ local database
+ ynh_handle_getopts_args '--sql=update pg_database set datcollate='\''C'\'', datctype='\''C'\'' where datname='\'''\'';'
+ set +o xtrace
+ database=
+ '[' -n '' ']'
++ cat /etc/yunohost/psql
+ ynh_psql_connect_as --user=postgres --password=blablabla
+ local legacy_args=upd
+ args_array=(['u']='user=' ['p']='password=' ['d']='database=')
+ local -A args_array
+ local user
+ local password
+ local database
+ ynh_handle_getopts_args --user=postgres --password=blablabla
+ set +o xtrace
+ database=
+ sudo --login --user=postgres PGUSER=postgres PGPASSWORD=blablabla psql ''
UPDATE 0
+ ynh_script_progression '--message=Restoring directory and configuration...' --weight=10
+ set +o xtrace
+ set +o xtrace
+ echo '! Helper used in legacy mode !'
+ set +x
+ echo '[++..................] > Restoring directory and configuration...'
/usr/share/yunohost/helpers.d/logging: line 38: $YNH_STDINFO: ambiguous redirect
+ set -o xtrace
+ cp -r ../backup/var/lib/matrix-synapse /var/lib/matrix-synapse
cp: cannot stat '../backup/var/lib/matrix-synapse': No such file or directory
+ cp -r ../backup/var/log/matrix-synapse /var/log/matrix-synapse
cp: cannot stat '../backup/var/log/matrix-synapse': No such file or directory
+ cp -r ../backup/etc/matrix-synapse /etc/matrix-synapse
cp: cannot stat '../backup/etc/matrix-synapse': No such file or directory
+ mkdir -p /etc/matrix-synapse/app-service
+ ynh_script_progression '--message=Check for source up to date...' --weight=5
+ set +o xtrace
+ set +o xtrace
+ echo '! Helper used in legacy mode !'
+ set +x
+ echo '[##+.................] > Check for source up to date...'
/usr/share/yunohost/helpers.d/logging: line 38: $YNH_STDINFO: ambiguous redirect
+ set -o xtrace
+ install_sources
./restore: line 55: install_sources: command not found
+ ynh_script_progression '--message=Reload Fail2Ban...' --weight=6
+ set +o xtrace
+ set +o xtrace
+ echo '! Helper used in legacy mode !'
+ set +x
+ echo '[###+................] > Reload Fail2Ban...'
/usr/share/yunohost/helpers.d/logging: line 38: $YNH_STDINFO: ambiguous redirect
+ set -o xtrace
+ ynh_systemd_action --action=restart --service_name=fail2ban
+ local legacy_args=nalpte
+ args_array=(['n']='service_name=' ['a']='action=' ['l']='line_match=' ['p']='log_path=' ['t']='timeout=' ['e']='length=')
+ local -A args_array
+ local service_name
+ local action
+ local line_match
+ local length
+ local log_path
+ local timeout
+ ynh_handle_getopts_args --action=restart --service_name=fail2ban
+ set +o xtrace
+ service_name=fail2ban
+ action=restart
+ line_match=
+ length=20
+ log_path=/var/log/fail2ban/fail2ban.log
+ timeout=300
+ '[' restart == stop ']'
+ [[ -n '' ]]
+ '[' restart == reload ']'
++ date --utc --rfc-3339=seconds
++ cut -d+ -f1
+ local 'time_start=2024-05-19 14:26:53 UTC'
+ systemctl restart fail2ban
+ [[ -n '' ]]
+ ynh_script_progression '--message=Restoring the PostgreSQL database...' --weight=13
+ set +o xtrace
+ set +o xtrace
+ echo '! Helper used in legacy mode !'
+ set +x
+ echo '[####++..............] > Restoring the PostgreSQL database...'
/usr/share/yunohost/helpers.d/logging: line 38: $YNH_STDINFO: ambiguous redirect
+ set -o xtrace
+ ynh_psql_execute_file_as_root --file=/dump.sql --database=
+ local legacy_args=fd
+ args_array=(['f']='file=' ['d']='database=')
+ local -A args_array
+ local file
+ local database
+ ynh_handle_getopts_args --file=/dump.sql --database=
+ set +o xtrace
+ database=
+ '[' -n '' ']'
++ cat /etc/yunohost/psql
+ ynh_psql_connect_as --user=postgres --password=blablabla
/usr/share/yunohost/helpers.d/postgresql: line 78: /dump.sql: No such file or directory
+ ynh_script_progression '--message=Enable systemd services' --weight=2
+ set +o xtrace
+ set +o xtrace
+ echo '! Helper used in legacy mode !'
+ set +x
+ echo '[######..............] > Enable systemd services'
/usr/share/yunohost/helpers.d/logging: line 38: $YNH_STDINFO: ambiguous redirect
+ set -o xtrace
+ systemctl enable synapse.service --quiet
+ systemctl enable synapse-coturn.service --quiet
+ yunohost service add synapse --log /var/log/matrix-synapse/homeserver.log --needs_exposed_ports --description 'Main matrix server service.'
usage: yunohost service add name [-h] [-d DESCRIPTION] [-l LOG [LOG ...]] [--test_status TEST_STATUS] [--test_conf TEST_CONF] [--needs_exposed_ports PORT [PORT ...]] [-n]
yunohost service add: error: argument --needs_exposed_ports: expected at least one argument
+ yunohost service add synapse-coturn --needs_exposed_ports --description 'Turn server for matrix server. Used for audio and video call.'
usage: yunohost service add name [-h] [-d DESCRIPTION] [-l LOG [LOG ...]] [--test_status TEST_STATUS] [--test_conf TEST_CONF] [--needs_exposed_ports PORT [PORT ...]] [-n]
yunohost service add: error: argument --needs_exposed_ports: expected at least one argument
+ ynh_script_progression '--message=Creating a dh file...' --weight=40
+ set +o xtrace
+ set +o xtrace
+ echo '! Helper used in legacy mode !'
+ set +x
+ echo '[######+++++++.......] > Creating a dh file...'
/usr/share/yunohost/helpers.d/logging: line 38: $YNH_STDINFO: ambiguous redirect
+ set -o xtrace
+ '[' '!' -e /etc/ssl/private/dh2048.pem ']'
+ ynh_script_progression '--message=Reconfiguring Coturn...' --weight=23
+ set +o xtrace
+ set +o xtrace
+ echo '! Helper used in legacy mode !'
+ set +x
+ echo '[#############++++...] > Reconfiguring Coturn...'
/usr/share/yunohost/helpers.d/logging: line 38: $YNH_STDINFO: ambiguous redirect
+ set -o xtrace
+ configure_coturn
./restore: line 108: configure_coturn: command not found
+ ynh_script_progression '--message=Configuring log rotation...'
+ set +o xtrace
+ set +o xtrace
+ echo '! Helper used in legacy mode !'
+ set +x
+ echo '[#################...] > Configuring log rotation...'
/usr/share/yunohost/helpers.d/logging: line 38: $YNH_STDINFO: ambiguous redirect
+ set -o xtrace
+ ynh_use_logrotate --logfile /var/log/matrix-synapse
+ all_args=('--logfile' '/var/log/matrix-synapse')
+ local all_args
++ seq 0 1
+ for I in $(seq 0 $(($# - 1)))
+ [[ --logfile == \-\-\n\o\n\-\a\p\p\e\n\d ]]
+ [[ --logfile == \-\-\n\o\n\a\p\p\e\n\d ]]
+ for I in $(seq 0 $(($# - 1)))
+ [[ /var/log/matrix-synapse == \-\-\n\o\n\-\a\p\p\e\n\d ]]
+ [[ /var/log/matrix-synapse == \-\-\n\o\n\a\p\p\e\n\d ]]
+ set -- --logfile /var/log/matrix-synapse
+ local legacy_args=lu
+ args_array=(['l']='logfile=' ['u']='specific_user=')
+ local -A args_array
+ local logfile
+ local specific_user
+ ynh_handle_getopts_args --logfile /var/log/matrix-synapse
+ set +o xtrace
+ logfile=/var/log/matrix-synapse
+ specific_user=
+ set -o noglob
+ [[ -z /var/log/matrix-synapse ]]
+ [[ /var/log/matrix-synapse != \l\o\g ]]
+ [[ /var/log/matrix-synapse != \t\x\t ]]
+ logfile='/var/log/matrix-synapse/*.log'
+ set +o noglob
+ for stuff in $logfile
++ dirname /var/log/matrix-synapse/homeserver.log
+ mkdir --parents /var/log/matrix-synapse
+ for stuff in $logfile
++ dirname /var/log/matrix-synapse/turnserver.log
+ mkdir --parents /var/log/matrix-synapse
+ local su_directive=
+ [[ -n '' ]]
++ mktemp
+ local tempconf=/tmp/tmp.paPnHDF0i7
+ cat
+ [[ true == \t\r\u\e ]]
+ cat /tmp/tmp.paPnHDF0i7
+ FIRST_CALL_TO_LOGROTATE=false
+ chmod 644 /etc/logrotate.d/synapse
+ mkdir -p /var/log/synapse
+ chmod 750 /var/log/synapse
+ ynh_script_progression '--message=Protecting directories...' --weight=3
+ set +o xtrace
+ set +o xtrace
+ echo '! Helper used in legacy mode !'
+ set +x
+ echo '[#################+..] > Protecting directories...'
/usr/share/yunohost/helpers.d/logging: line 38: $YNH_STDINFO: ambiguous redirect
+ set -o xtrace
+ set_permissions data
./restore: line 124: set_permissions: command not found
+ ynh_script_progression '--message=Restarting Synapse services...' --weight=7
+ set +o xtrace
+ set +o xtrace
+ echo '! Helper used in legacy mode !'
+ set +x
+ echo '[##################+.] > Restarting Synapse services...'
/usr/share/yunohost/helpers.d/logging: line 38: $YNH_STDINFO: ambiguous redirect
+ set -o xtrace
+ ynh_systemd_action --service_name=synapse-coturn.service --action=restart
+ local legacy_args=nalpte
+ args_array=(['n']='service_name=' ['a']='action=' ['l']='line_match=' ['p']='log_path=' ['t']='timeout=' ['e']='length=')
+ local -A args_array
+ local service_name
+ local action
+ local line_match
+ local length
+ local log_path
+ local timeout
+ ynh_handle_getopts_args --service_name=synapse-coturn.service --action=restart
+ set +o xtrace
+ service_name=synapse-coturn.service
+ action=restart
+ line_match=
+ length=20
+ log_path=/var/log/synapse-coturn.service/synapse-coturn.service.log
+ timeout=300
+ '[' restart == stop ']'
+ [[ -n '' ]]
+ '[' restart == reload ']'
++ date --utc --rfc-3339=seconds
++ cut -d+ -f1
+ local 'time_start=2024-05-19 14:27:04 UTC'
+ systemctl restart synapse-coturn.service
+ [[ -n '' ]]
+ ynh_systemd_action --service_name=synapse.service --action=restart '--line_match=Synapse now listening on TCP port ' --log_path=/var/log/matrix-synapse/homeserver.log --timeout=300
+ local legacy_args=nalpte
+ args_array=(['n']='service_name=' ['a']='action=' ['l']='line_match=' ['p']='log_path=' ['t']='timeout=' ['e']='length=')
+ local -A args_array
+ local service_name
+ local action
+ local line_match
+ local length
+ local log_path
+ local timeout
+ ynh_handle_getopts_args --service_name=synapse.service --action=restart '--line_match=Synapse now listening on TCP port ' --log_path=/var/log/matrix-synapse/homeserver.log --timeout=300
+ set +o xtrace
+ service_name=synapse.service
+ action=restart
+ line_match='Synapse now listening on TCP port '
+ length=20
+ log_path=/var/log/matrix-synapse/homeserver.log
+ timeout=300
+ '[' restart == stop ']'
+ [[ -n Synapse now listening on TCP port  ]]
++ mktemp
+ local templog=/tmp/tmp.WW9fPIqUj9
+ '[' /var/log/matrix-synapse/homeserver.log == systemd ']'
+ local pid_tail=483005
+ tail --follow=name --retry --lines=0 /var/log/matrix-synapse/homeserver.log
+ '[' restart == reload ']'
++ date --utc --rfc-3339=seconds
++ cut -d+ -f1
+ local 'time_start=2024-05-19 14:27:06 UTC'
+ systemctl restart synapse.service
+ [[ -n Synapse now listening on TCP port  ]]
+ set +x
+ echo 'The service synapse.service has correctly executed the action restart.'
/usr/share/yunohost/helpers.d/logging: line 38: $YNH_STDINFO: ambiguous redirect
+ break
+ set -x
+ '[' 12 -ge 3 ']'
+ echo ''

+ '[' 12 -eq 300 ']'
+ ynh_clean_check_starting
+ '[' -n 483005 ']'
+ kill -SIGTERM 483005
+ '[' -n /tmp/tmp.WW9fPIqUj9 ']'
+ ynh_secure_remove --file=/tmp/tmp.WW9fPIqUj9
+ local legacy_args=f
+ args_array=(['f']='file=')
+ local -A args_array
+ local file
+ ynh_handle_getopts_args --file=/tmp/tmp.WW9fPIqUj9
+ set +o xtrace
+ set +o xtrace
+ ynh_script_progression '--message=Reloading NGINX web server...'
+ set +o xtrace
+ set +o xtrace
+ echo '! Helper used in legacy mode !'
+ set +x
+ echo '[###################.] > Reloading NGINX web server...'
/usr/share/yunohost/helpers.d/logging: line 38: $YNH_STDINFO: ambiguous redirect
+ set -o xtrace
+ ynh_systemd_action --service_name=php-fpm --action=reload
+ local legacy_args=nalpte
+ args_array=(['n']='service_name=' ['a']='action=' ['l']='line_match=' ['p']='log_path=' ['t']='timeout=' ['e']='length=')
+ local -A args_array
+ local service_name
+ local action
+ local line_match
+ local length
+ local log_path
+ local timeout
+ ynh_handle_getopts_args --service_name=php-fpm --action=reload
+ set +o xtrace
+ service_name=php-fpm
+ action=reload
+ line_match=
+ length=20
+ log_path=/var/log/php-fpm/php-fpm.log
+ timeout=300
+ '[' reload == stop ']'
+ [[ -n '' ]]
+ '[' reload == reload ']'
+ action=reload-or-restart
++ date --utc --rfc-3339=seconds
++ cut -d+ -f1
+ local 'time_start=2024-05-19 14:27:29 UTC'
+ systemctl reload-or-restart php-fpm
Failed to reload-or-restart php-fpm.service: Unit php-fpm.service not found.
+ ynh_exec_err journalctl --quiet --no-hostname --no-pager --lines=20 --unit=php-fpm
+ [[ 6 -eq 1 ]]
++ journalctl --quiet --no-hostname --no-pager --lines=20 --unit=php-fpm
+ ynh_print_err --message=
+ local legacy_args=m
+ args_array=(['m']='message=')
+ local -A args_array
+ local message
+ ynh_handle_getopts_args --message=
+ set +o xtrace
+ ynh_print_log '[Error] '
+ echo -e '[Error] '
[Error] 
+ '[' -e /var/log/php-fpm/php-fpm.log ']'
+ ynh_clean_check_starting
+ '[' -n '' ']'
+ '[' -n '' ']'
+ return 1
+ ynh_systemd_action --service_name=nginx --action=reload
+ local legacy_args=nalpte
+ args_array=(['n']='service_name=' ['a']='action=' ['l']='line_match=' ['p']='log_path=' ['t']='timeout=' ['e']='length=')
+ local -A args_array
+ local service_name
+ local action
+ local line_match
+ local length
+ local log_path
+ local timeout
+ ynh_handle_getopts_args --service_name=nginx --action=reload
+ set +o xtrace
+ service_name=nginx
+ action=reload
+ line_match=
+ length=20
+ log_path=/var/log/nginx/nginx.log
+ timeout=300
+ '[' reload == stop ']'
+ [[ -n '' ]]
+ '[' reload == reload ']'
+ action=reload-or-restart
++ date --utc --rfc-3339=seconds
++ cut -d+ -f1
+ local 'time_start=2024-05-19 14:27:35 UTC'
+ systemctl reload-or-restart nginx
+ [[ -n '' ]]
+ ynh_script_progression '--message=Restoration completed for synapse' --last
+ set +o xtrace
+ set +o xtrace
+ echo '! Helper used in legacy mode !'
+ set +x
+ echo '[####################] > Restoration completed for synapse'
/usr/share/yunohost/helpers.d/logging: line 38: $YNH_STDINFO: ambiguous redirect
+ set -o xtrace

Le service tourne. Des données ont été restaurées. Sauf que… La nouvelle configuration liée au sous-domaine (synapse.mondomaine.be) a été écrasée je suppose. Donc il faut que je répare ça…


Finalement, j’ai à nouveau supprimé synapse et réinstallé pour pouvoir analyser où est géré le sous-domaine dans la configuration avant de tout écraser en restaurant le backup.

# cd /etc/matrix-synapse/

# grep "synapse.mondomaine" *
grep: app-service: Is a directory
grep: conf.d: Is a directory
coturn.conf:realm=synapse.mondomaine.be
coturn.conf:cert=/etc/yunohost/certs/synapse.mondomaine.be/crt.pem
coturn.conf:pkey=/etc/yunohost/certs/synapse.mondomaine.be/key.pem
homeserver.yaml:public_baseurl: https://synapse.mondomaine.be/
homeserver.yaml:tls_certificate_path: "/etc/yunohost/certs/synapse.mondomaine.be/crt.pem"
homeserver.yaml:tls_private_key_path: "/etc/yunohost/certs/synapse.mondomaine.be/key.pem"
homeserver.yaml:turn_uris: [ "turns:synapse.mondomaine.be:5349", "turns:synapse.mondomaine.be:5350" ]
homeserver.yaml:  server_url: "https://synapse.mondomaine.be/_matrix/cas_server.php"
homeserver.yaml:      - synapse.mondomaine.be
homeserver.yaml:  smtp_host: "synapse.mondomaine.be"
homeserver.yaml:  notif_from: "Your Friendly %(app)s Home Server <synapse@synapse.mondomaine.be>"

Et là, je réalise qu’il y a aussi surement un gros paquet de choses dans la base de données qui pointe vers le sous-domaine ? :smiling_face_with_tear:


Finalement, j’ai à nouveau supprimé synapse et restauré depuis le backup :

# yunohost backup restore manual-synapse --apps synapse

Retour au point de départ. :face_exhaling: