1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/synapse_ynh.git synced 2024-09-03 20:26:38 +02:00

Standardize unit name

This is in prevision for multiple services linked to the same app, so we can have something like $app-coturn, $app-slide-proxy, ...
This commit is contained in:
Josué Tille 2024-02-06 20:42:00 +01:00
parent 60324a8f59
commit b2e2341ff1
No known key found for this signature in database
GPG key ID: 5F259226AD51F2F5
13 changed files with 70 additions and 46 deletions

View file

@ -90,20 +90,20 @@ If you have a dynamic IP address, you also might need to update this config auto
#### OpenVPN #### OpenVPN
In case of you have an OpenVPN server you might want than `coturn-synapse` restart when the VPN restart. To do this create a file named `/usr/local/bin/openvpn_up_script.sh` with this content: In case of you have an OpenVPN server you might want than `synapse-coturn` restart when the VPN restart. To do this create a file named `/usr/local/bin/openvpn_up_script.sh` with this content:
``` ```
#!/bin/bash #!/bin/bash
( (
sleep 5 sleep 5
sudo systemctl restart coturn-synapse.service sudo systemctl restart synapse-coturn.service
) & ) &
exit 0 exit 0
``` ```
Add this line in you sudo config file `/etc/sudoers` Add this line in you sudo config file `/etc/sudoers`
``` ```
openvpn ALL=(ALL) NOPASSWD: /bin/systemctl restart coturn-synapse.service openvpn ALL=(ALL) NOPASSWD: /bin/systemctl restart synapse-coturn.service
``` ```
And add this line in your OpenVPN config file And add this line in your OpenVPN config file

View file

@ -90,20 +90,20 @@ If you have a dynamic IP address, you also might need to update this config auto
#### OpenVPN #### OpenVPN
In case of you have an OpenVPN server you might want than `coturn-synapse` restart when the VPN restart. To do this create a file named `/usr/local/bin/openvpn_up_script.sh` with this content: In case of you have an OpenVPN server you might want than `synapse-coturn` restart when the VPN restart. To do this create a file named `/usr/local/bin/openvpn_up_script.sh` with this content:
``` ```
#!/bin/bash #!/bin/bash
( (
sleep 5 sleep 5
sudo systemctl restart coturn-synapse.service sudo systemctl restart synapse-coturn.service
) & ) &
exit 0 exit 0
``` ```
Add this line in you sudo config file `/etc/sudoers` Add this line in you sudo config file `/etc/sudoers`
``` ```
openvpn ALL=(ALL) NOPASSWD: /bin/systemctl restart coturn-synapse.service openvpn ALL=(ALL) NOPASSWD: /bin/systemctl restart synapse-coturn.service
``` ```
And add this line in your OpenVPN config file And add this line in your OpenVPN config file

View file

@ -39,7 +39,7 @@ https://federationtester.matrix.org/ can be used to easily debug federation issu
### Turnserver ### Turnserver
For Voip and video conferencing a turnserver is also installed (and configured). The turnserver listens on two UDP and TCP ports. You can get them with these commands: For Voip and video conferencing a turnserver is also installed (and configured). The turnserver listens on two UDP and TCP ports. You can get them with these commands:
``` ```bash
yunohost app setting synapse port_turnserver_tls yunohost app setting synapse port_turnserver_tls
yunohost app setting synapse port_turnserver_alt_tls yunohost app setting synapse port_turnserver_alt_tls
@ -48,7 +48,7 @@ The turnserver will also choose a port dynamically when a new call starts. The r
For some security reason the ports range (49153 - 49193) isn't automatically open by default. If you want to use the synapse server for voip or conferencing you will need to open this port range manually. To do this just run this command: For some security reason the ports range (49153 - 49193) isn't automatically open by default. If you want to use the synapse server for voip or conferencing you will need to open this port range manually. To do this just run this command:
``` ```bash
yunohost firewall allow Both 49153:49193 yunohost firewall allow Both 49153:49193
``` ```
@ -64,20 +64,20 @@ If you have a dynamic IP address, you also might need to update this config auto
#### OpenVPN #### OpenVPN
In case of you have an OpenVPN server you might want than `coturn-synapse` restart when the VPN restart. To do this create a file named `/usr/local/bin/openvpn_up_script.sh` with this content: In case of you have an OpenVPN server you might want than `synapse-coturn` restart when the VPN restart. To do this create a file named `/usr/local/bin/openvpn_up_script.sh` with this content:
``` ```bash
#!/bin/bash #!/bin/bash
( (
sleep 5 sleep 5
sudo systemctl restart coturn-synapse.service sudo systemctl restart synapse-coturn.service
) & ) &
exit 0 exit 0
``` ```
Add this line in you sudo config file `/etc/sudoers` Add this line in you sudo config file `/etc/sudoers`
``` ```
openvpn ALL=(ALL) NOPASSWD: /bin/systemctl restart coturn-synapse.service openvpn ALL=(ALL) NOPASSWD: /bin/systemctl restart synapse-coturn.service
``` ```
And add this line in your OpenVPN config file And add this line in your OpenVPN config file

View file

@ -14,8 +14,8 @@ source /usr/share/yunohost/helpers
# MANAGE SCRIPT FAILURE # MANAGE SCRIPT FAILURE
#================================================= #=================================================
if [[ ! "$(systemctl status matrix-$app.service)" =~ "Active: inactive (dead)" ]]; then if [[ ! "$(systemctl status $app.service)" =~ "Active: inactive (dead)" ]]; then
ynh_print_warn --message="It's hightly recommended to make your backup when the service is stopped. Please stop $app service with this command before to run the backup 'systemctl stop matrix-$app.service'" ynh_print_warn --message="It's hightly recommended to make your backup when the service is stopped. Please stop $app service with this command before to run the backup 'systemctl stop $app.service'"
fi fi
#================================================= #=================================================
@ -71,9 +71,9 @@ ynh_backup --src_path="/etc/matrix-$app"
#================================================= #=================================================
ynh_backup --src_path="/etc/default/matrix-$app" ynh_backup --src_path="/etc/default/matrix-$app"
ynh_backup --src_path="/etc/systemd/system/matrix-$app.service" ynh_backup --src_path="/etc/systemd/system/$app.service"
ynh_backup --src_path="/etc/default/coturn-$app" ynh_backup --src_path="/etc/default/coturn-$app"
ynh_backup --src_path="/etc/systemd/system/coturn-$app.service" ynh_backup --src_path="/etc/systemd/system/$app-coturn.service"
#================================================= #=================================================
# BACKUP SYNAPSE DATA # BACKUP SYNAPSE DATA

View file

@ -19,7 +19,7 @@ then
fi fi
# We stop the service # We stop the service
ynh_systemd_action --service_name=matrix-$app.service --action=stop ynh_systemd_action --service_name=$app.service.service --action=stop
#================================================= #=================================================
# STANDARD MODIFICATIONS # STANDARD MODIFICATIONS
@ -52,7 +52,7 @@ set_permissions
#================================================= #=================================================
ynh_script_progression --message="Restarting Synapse services..." --weight=5 ynh_script_progression --message="Restarting Synapse services..." --weight=5
ynh_systemd_action --service_name=coturn-$app.service --action=restart ynh_systemd_action --service_name=$app-coturn.service --action=restart
ynh_systemd_action --service_name=matrix-$app --action=restart --line_match="Synapse now listening on TCP port $port_synapse_tls" --log_path="/var/log/matrix-$app/homeserver.log" --timeout=300 ynh_systemd_action --service_name=$app.service --action=restart --line_match="Synapse now listening on TCP port $port_synapse_tls" --log_path="/var/log/matrix-$app/homeserver.log" --timeout=300
ynh_script_progression --message="Change of URL completed for $app" --last ynh_script_progression --message="Change of URL completed for $app" --last

View file

@ -201,10 +201,10 @@ ynh_script_progression --message="Configuring a systemd service..." --weight=2
# Create systemd service for synapse and turnserver # Create systemd service for synapse and turnserver
cp ../conf/default_matrix-synapse /etc/default/matrix-$app cp ../conf/default_matrix-synapse /etc/default/matrix-$app
ynh_add_systemd_config --service=matrix-$app --template=matrix-synapse.service ynh_add_systemd_config --service=matrix-$app --template=synapse.service
cp ../conf/default_coturn /etc/default/coturn-$app cp ../conf/default_coturn /etc/default/coturn-$app
ynh_add_systemd_config --service=coturn-$app --template=coturn-synapse.service ynh_add_systemd_config --service=$app-coturn --template=synapse-coturn.service
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
@ -287,16 +287,16 @@ set_permissions
# ADVERTISE SERVICE IN ADMIN PANEL # ADVERTISE SERVICE IN ADMIN PANEL
#================================================= #=================================================
yunohost service add matrix-$app --log "/var/log/matrix-$app/homeserver.log" --needs_exposed_ports $port_synapse_tls yunohost service add $app --log "/var/log/matrix-$app/homeserver.log" --needs_exposed_ports $port_synapse_tls
yunohost service add coturn-$app --needs_exposed_ports $port_turnserver_tls yunohost service add $app-coturn --needs_exposed_ports $port_turnserver_tls
#================================================= #=================================================
# RELOAD SERVICES # RELOAD SERVICES
#================================================= #=================================================
ynh_script_progression --message="Restarting Synapse services..." --weight=11 ynh_script_progression --message="Restarting Synapse services..." --weight=11
ynh_systemd_action --service_name=coturn-$app.service --action=restart ynh_systemd_action --service_name=$app-coturn.service --action=restart
ynh_systemd_action --service_name=matrix-$app --action=restart --line_match="Synapse now listening on TCP port $port_synapse_tls" --log_path="/var/log/matrix-$app/homeserver.log" --timeout=300 ynh_systemd_action --service_name=$app.service --action=restart --line_match="Synapse now listening on TCP port $port_synapse_tls" --log_path="/var/log/matrix-$app/homeserver.log" --timeout=300
#================================================= #=================================================
# SETUP FAIL2BAN # SETUP FAIL2BAN

View file

@ -17,14 +17,14 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# Remove a service from the admin panel, added by `yunohost service add` # Remove a service from the admin panel, added by `yunohost service add`
if yunohost service status matrix-$app >/dev/null 2>&1 if yunohost service status $app >/dev/null 2>&1
then then
yunohost service remove matrix-$app yunohost service remove $app
fi fi
if yunohost service status coturn-$app >/dev/null 2>&1 if yunohost service status $app-coturn >/dev/null 2>&1
then then
yunohost service remove coturn-$app yunohost service remove $app-coturn
fi fi
#================================================= #=================================================
@ -32,8 +32,8 @@ fi
#================================================= #=================================================
ynh_script_progression --message="Stopping and removing the systemd service" --weight=2 ynh_script_progression --message="Stopping and removing the systemd service" --weight=2
ynh_remove_systemd_config --service=matrix-$app ynh_remove_systemd_config --service=$app
ynh_remove_systemd_config --service=coturn-$app ynh_remove_systemd_config --service=$app-coturn
#================================================= #=================================================
# REMOVE APP MAIN DIR # REMOVE APP MAIN DIR

View file

@ -67,15 +67,15 @@ ynh_psql_execute_file_as_root --file="${YNH_CWD}/dump.sql" --database="$synapse_
ynh_script_progression --message="Enable systemd services" --weight=2 ynh_script_progression --message="Enable systemd services" --weight=2
# systemctl daemon-reload # systemctl daemon-reload
systemctl enable matrix-$app.service --quiet systemctl enable $app.service --quiet
systemctl enable coturn-$app.service --quiet systemctl enable $app-coturn.service --quiet
#================================================= #=================================================
# ADVERTISE SERVICE IN ADMIN PANEL # ADVERTISE SERVICE IN ADMIN PANEL
#================================================= #=================================================
yunohost service add matrix-$app --log "/var/log/matrix-$app/homeserver.log" --needs_exposed_ports $port_synapse_tls yunohost service add $app --log "/var/log/matrix-$app/homeserver.log" --needs_exposed_ports $port_synapse_tls
yunohost service add coturn-$app --needs_exposed_ports $port_turnserver_tls yunohost service add $app-coturn --needs_exposed_ports $port_turnserver_tls
#================================================= #=================================================
# CREATE A DH FILE # CREATE A DH FILE
@ -121,8 +121,8 @@ set_permissions
#================================================= #=================================================
ynh_script_progression --message="Restarting Synapse services..." --weight=7 ynh_script_progression --message="Restarting Synapse services..." --weight=7
ynh_systemd_action --service_name=coturn-$app.service --action=restart ynh_systemd_action --service_name=$app-coturn.service --action=restart
ynh_systemd_action --service_name=matrix-$app --action=restart --line_match="Synapse now listening on TCP port $port_synapse_tls" --log_path="/var/log/matrix-$app/homeserver.log" --timeout=300 ynh_systemd_action --service_name=$app.service --action=restart --line_match="Synapse now listening on TCP port $port_synapse_tls" --log_path="/var/log/matrix-$app/homeserver.log" --timeout=300
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION

View file

@ -220,8 +220,32 @@ if [ -z $synapse_user_app_pwd ]; then
yunohost user create $app -F "Synapse Application" -d $domain -p "$synapse_user_app_pwd" yunohost user create $app -F "Synapse Application" -d $domain -p "$synapse_user_app_pwd"
fi fi
#=================================================
# MIGRATION 7 : STANDARDIZE SYSTEMD UNIT
#=================================================
if [ ! -e /etc/systemd/system/matrix-$app.service ]
then
ynh_script_progression --message="Migrating systemd unit to standard name..."
systemctl stop matrix-$app.service
systemctl stop synapse-coturn.service
yunohost service remove matrix-$app
yunohost service remove coturn-$app
ynh_secure_remove --file=/etc/systemd/system/matrix-$app.service
ynh_secure_remove --file=/etc/systemd/system/coturn-$app.service
touch /etc/systemd/system/$app.service
fi
#=================================================
# STOP SERVICES
#=================================================
# We stop the service # We stop the service
ynh_systemd_action --service_name=matrix-$app.service --action=stop ynh_systemd_action --service_name=$app.service --action=stop
#================================================= #=================================================
# MIGRATION 6 : Migrate data directory # MIGRATION 6 : Migrate data directory
@ -410,8 +434,8 @@ fi
# ADVERTISE SERVICE IN ADMIN PANEL # ADVERTISE SERVICE IN ADMIN PANEL
#================================================= #=================================================
yunohost service add matrix-$app --log "/var/log/matrix-$app/homeserver.log" --needs_exposed_ports $port_synapse_tls yunohost service add $app --log "/var/log/matrix-$app/homeserver.log" --needs_exposed_ports $port_synapse_tls
yunohost service add coturn-$app --needs_exposed_ports $port_turnserver_tls yunohost service add $app-coturn --needs_exposed_ports $port_turnserver_tls
#================================================= #=================================================
# UPDATE SYSTEMD # UPDATE SYSTEMD
@ -420,10 +444,10 @@ ynh_script_progression --message="Upgrading systemd configuration..." --weight=3
# Create systemd service for synapse and turnserver # Create systemd service for synapse and turnserver
cp ../conf/default_matrix-synapse /etc/default/matrix-$app cp ../conf/default_matrix-synapse /etc/default/matrix-$app
ynh_add_systemd_config --service=matrix-$app --template=matrix-synapse.service ynh_add_systemd_config --service=$app --template=synapse.service
cp ../conf/default_coturn /etc/default/coturn-$app cp ../conf/default_coturn /etc/default/coturn-$app
ynh_add_systemd_config --service=coturn-$app --template=coturn-synapse.service ynh_add_systemd_config --service=$app-coturn --template=synapse-coturn.service
#================================================= #=================================================
# UPGRADE FAIL2BAN # UPGRADE FAIL2BAN
@ -474,8 +498,8 @@ ynh_replace_string __DOMAIN__ $domain ../hooks/post_cert_update
#================================================= #=================================================
ynh_script_progression --message="Restarting Synapse services..." --weight=5 ynh_script_progression --message="Restarting Synapse services..." --weight=5
ynh_systemd_action --service_name=coturn-$app.service --action=restart ynh_systemd_action --service_name=$app-coturn.service --action=restart
ynh_systemd_action --service_name=matrix-$app --action=restart --line_match="Synapse now listening on TCP port $port_synapse_tls" --log_path="/var/log/matrix-$app/homeserver.log" --timeout=300 ynh_systemd_action --service_name=$app.service --action=restart --line_match="Synapse now listening on TCP port $port_synapse_tls" --log_path="/var/log/matrix-$app/homeserver.log" --timeout=300
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT

View file

@ -27,7 +27,7 @@ setfacl -R -m user:turnserver:rX /etc/matrix-$app_instance
if [ "$old_config_line" != "$new_config_line" ] if [ "$old_config_line" != "$new_config_line" ]
then then
systemctl restart coturn-$app_instance.service systemctl restart $app_instance-coturn.service
fi fi
exit 0 exit 0

View file

@ -21,7 +21,7 @@ chown matrix-$app /etc/matrix-$app/app-service/*
chmod 600 $service_config_file chmod 600 $service_config_file
chmod 600 /etc/matrix-$app/app-service/* chmod 600 /etc/matrix-$app/app-service/*
systemctl restart matrix-$app systemctl restart $app.service
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
rm /tmp/app_service_backup.yaml rm /tmp/app_service_backup.yaml