From 331fcce8c5989722106d4e8a034709f362a7c065 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Fri, 16 Feb 2018 09:43:55 +0530 Subject: [PATCH 1/4] conf: use a Type=notify systemd service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Starting from Mattermost 4.8, the server process sends a systemd notification when it is ready to accept network connections. Thus we don't need to explicitely wait for the port to be open in the service. As a bonus, by removing the hack, we don't need to replace `__PORT__` in the service anymore–which means the associated script helper can be removed too. --- conf/systemd.service | 8 +------- scripts/_common.sh | 17 ----------------- scripts/install | 3 +-- scripts/upgrade | 3 +-- 4 files changed, 3 insertions(+), 28 deletions(-) delete mode 100644 scripts/_common.sh diff --git a/conf/systemd.service b/conf/systemd.service index 7a7977f..7b2b574 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -5,14 +5,8 @@ After=mysql.service Requires=mysql.service [Service] -Type=simple +Type=notify ExecStart=__FINALPATH__/bin/platform -# HACK: Wait for Mattermost port to be open before declaring the service to be launched successfully. -# This avoids to report the service as launched even when it crashes a few milliseconds after start. -# -# TODO: improve mattermost to send a STARTED notification, and -# switch the service to 'Type=notify' instead. -ExecStartPost=/usr/bin/timeout 10 /bin/sh -c 'while ! nc -z localhost __PORT__; do sleep 0.2; done' Restart=always RestartSec=10 WorkingDirectory=__FINALPATH__ diff --git a/scripts/_common.sh b/scripts/_common.sh deleted file mode 100644 index 02b43dc..0000000 --- a/scripts/_common.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -# Add a systemd configuration using ynh_add_systemd_config, -# by replacing __PORT__ with the $port variable value. -mattermost_add_systemd_config () { - local config_path="../conf" - - # Replace variables in the systemd template config file - sed -i'.template' "s/__PORT__/$port/g" "$config_path/systemd.service" - - # Create a dedicated systemd config - ynh_add_systemd_config - - # Restore the original configuration template - rm "$config_path/systemd.service" - mv "$config_path/systemd.service.template" "$config_path/systemd.service" -} diff --git a/scripts/install b/scripts/install index e1f29bf..621960d 100644 --- a/scripts/install +++ b/scripts/install @@ -6,7 +6,6 @@ # IMPORT GENERIC HELPERS #================================================= -source _common.sh source /usr/share/yunohost/helpers #================================================= @@ -168,7 +167,7 @@ ynh_add_nginx_config # SYSTEMD CONFIGURATION #================================================= -mattermost_add_systemd_config +ynh_add_systemd_config #================================================= # ADVERTISE SERVICE IN ADMIN PANEL diff --git a/scripts/upgrade b/scripts/upgrade index 332de9b..965f1f8 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -6,7 +6,6 @@ # IMPORT GENERIC HELPERS #================================================= -source _common.sh source /usr/share/yunohost/helpers #================================================= @@ -132,7 +131,7 @@ ynh_add_nginx_config # SYSTEMD CONFIGURATION #================================================= -mattermost_add_systemd_config +ynh_add_systemd_config #================================================= # ADVERTISE SERVICE IN ADMIN PANEL From 397793f407170d229c8c051e0c2e5f5861a07eb1 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Fri, 16 Feb 2018 09:45:53 +0530 Subject: [PATCH 2/4] conf: make the start timeout explicit This is the default value of systemd, made explicit. If startup takes longer than that, the process will be killed. --- conf/systemd.service | 1 + 1 file changed, 1 insertion(+) diff --git a/conf/systemd.service b/conf/systemd.service index 7b2b574..b32afd3 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -7,6 +7,7 @@ Requires=mysql.service [Service] Type=notify ExecStart=__FINALPATH__/bin/platform +TimeoutStartSec=90 Restart=always RestartSec=10 WorkingDirectory=__FINALPATH__ From 1404063a5cd61030b3126f8ce787cb27b5a94602 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Fri, 16 Feb 2018 09:46:01 +0530 Subject: [PATCH 3/4] conf: add file overwrite warning --- conf/systemd.service | 3 +++ 1 file changed, 3 insertions(+) diff --git a/conf/systemd.service b/conf/systemd.service index b32afd3..55ea561 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -1,3 +1,6 @@ +# This file is managed by the Yunohost Mattermost package, +# and will be overwritten on upgrade. + [Unit] Description=Mattermost After=network.target From d10c3cf7b34bafb9360d531a8255844ee1cc86fd Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Thu, 1 Mar 2018 18:06:55 +0530 Subject: [PATCH 4/4] conf: increase systemd start timeout This allows for time to execute database migrations, and is in line with the official Mattermost docs. --- conf/systemd.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/systemd.service b/conf/systemd.service index 55ea561..2bbde55 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -10,7 +10,7 @@ Requires=mysql.service [Service] Type=notify ExecStart=__FINALPATH__/bin/platform -TimeoutStartSec=90 +TimeoutStartSec=3600 Restart=always RestartSec=10 WorkingDirectory=__FINALPATH__