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] 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