mirror of
https://github.com/YunoHost-Apps/mattermost_ynh.git
synced 2024-09-03 19:36:29 +02:00
scripts: handle port in use
This commit is contained in:
parent
aa7721322d
commit
0918978e92
6 changed files with 51 additions and 13 deletions
|
@ -6,7 +6,6 @@
|
|||
language="fr"
|
||||
is_public=1 (PUBLIC|public=1|private=0)
|
||||
password="alpine"
|
||||
port="8065" (PORT)
|
||||
; Checks
|
||||
pkg_linter=1
|
||||
setup_root=1
|
||||
|
@ -15,9 +14,10 @@
|
|||
upgrade=1
|
||||
backup_restore=1
|
||||
multi_instance=0
|
||||
port_already_use=0 (XXXX)
|
||||
port_already_use=1 (8085)
|
||||
# Checks not supported yet
|
||||
change_url=0
|
||||
# Tests not applicable
|
||||
# Checks not applicable
|
||||
setup_sub_dir=0
|
||||
setup_nourl=0
|
||||
incorrect_path=0
|
||||
|
|
|
@ -12,7 +12,7 @@ location ~ /api/v[0-9]+/(users/)?websocket$ {
|
|||
proxy_buffers 256 16k;
|
||||
proxy_buffer_size 16k;
|
||||
proxy_read_timeout 600s;
|
||||
proxy_pass http://127.0.0.1:8065;
|
||||
proxy_pass http://127.0.0.1:__PORT__;
|
||||
}
|
||||
|
||||
location / {
|
||||
|
@ -33,7 +33,7 @@ location / {
|
|||
#proxy_cache_min_uses 2;
|
||||
#proxy_cache_use_stale timeout;
|
||||
#proxy_cache_lock on;
|
||||
proxy_pass http://127.0.0.1:8065;
|
||||
proxy_pass http://127.0.0.1:__PORT__;
|
||||
# Yunohost addition: redirect HTTP to HTTPS
|
||||
if ($scheme = http) {
|
||||
rewrite ^ https://$server_name$request_uri? permanent;
|
||||
|
|
|
@ -12,7 +12,7 @@ ExecStart=__FINALPATH__/bin/platform
|
|||
#
|
||||
# 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 8065; do sleep 0.2; done'
|
||||
ExecStartPost=/usr/bin/timeout 10 /bin/sh -c 'while ! nc -z localhost __PORT__; do sleep 0.2; done'
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
WorkingDirectory=__FINALPATH__
|
||||
|
|
17
scripts/_common.sh
Normal file
17
scripts/_common.sh
Normal file
|
@ -0,0 +1,17 @@
|
|||
#!/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"
|
||||
}
|
|
@ -6,6 +6,7 @@
|
|||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
|
@ -55,15 +56,28 @@ then
|
|||
script_die "Mattermost requires MySQL 5.6 or higher, or MariaDB 10 or higher."
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# FIND AN AVAILABLE PATH
|
||||
#=================================================
|
||||
|
||||
# Normalize the url path syntax
|
||||
path_url=$(ynh_normalize_url_path $path_url)
|
||||
# Check web path availability
|
||||
ynh_webpath_available $domain $path_url
|
||||
ynh_webpath_available "$domain" "$path_url"
|
||||
# Register (book) web path
|
||||
ynh_webpath_register $app $domain $path_url
|
||||
ynh_webpath_register "$app" "$domain" "$path_url"
|
||||
# Store setting
|
||||
ynh_app_setting_set "$app" domain "$domain"
|
||||
|
||||
#=================================================
|
||||
# FIND AN AVAILABLE PORT
|
||||
#=================================================
|
||||
|
||||
# Find an available port
|
||||
port=$(ynh_find_port 8065)
|
||||
# Store setting
|
||||
ynh_app_setting_set "$app" port "$port"
|
||||
|
||||
#=================================================
|
||||
# SET UP INSTALLATION VARIABLES
|
||||
#=================================================
|
||||
|
@ -107,6 +121,7 @@ sudo mkdir -p "$logs_path"
|
|||
|
||||
# Configure Service Settings
|
||||
sudo sed -i "s|\"SiteURL\": \"\"|\"SiteURL\": \"https://${domain}${path_url}\"|g" $final_path/config/config.json
|
||||
sudo sed -i "s|\"ListenAddress\": \".*\"|\"ListenAddress\": \"127.0.0.1:${port}\"|g" $final_path/config/config.json
|
||||
# Configure the database connection
|
||||
db_connection_url="${db_user}:${db_password}@tcp(127.0.0.1:3306)/${db_name}?charset=utf8mb4,utf8"
|
||||
sudo sed -i "s|\"DataSource\": \".*\"|\"DataSource\": \"${db_connection_url}\"|g" $final_path/config/config.json
|
||||
|
@ -142,15 +157,13 @@ sudo chown -R mattermost:adm "$logs_path"
|
|||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Copy conf/nginx.conf to the correct location
|
||||
ynh_add_nginx_config
|
||||
|
||||
#=================================================
|
||||
# SYSTEMD CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Create a dedicated systemd config
|
||||
ynh_add_systemd_config
|
||||
mattermost_add_systemd_config
|
||||
|
||||
#=================================================
|
||||
# ADVERTISE SERVICE IN ADMIN PANEL
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
|
@ -22,6 +23,7 @@ ynh_abort_if_errors
|
|||
app=$YNH_APP_INSTANCE_NAME
|
||||
domain=$(ynh_app_setting_get mattermost domain)
|
||||
is_public=$(ynh_app_setting_get mattermost is_public)
|
||||
port=$(ynh_app_setting_get mattermost port)
|
||||
|
||||
root_path="$(pwd)/.."
|
||||
final_path="/var/www/$app"
|
||||
|
@ -57,7 +59,7 @@ if $(sudo systemctl -q is-active "$app"); then
|
|||
sudo systemctl stop "$app"
|
||||
fi
|
||||
|
||||
# Legacy, for older versions of this app which used supervisor
|
||||
# Legacy, for previous versions of this app which used supervisor
|
||||
if [ -f "/etc/supervisor/conf.d/${app}.conf" ]; then
|
||||
sudo supervisorctl stop "$app"
|
||||
sudo rm -f "/etc/supervisor/conf.d/${app}.conf"
|
||||
|
@ -84,6 +86,12 @@ elif [[ $is_public == "No" ]]; then
|
|||
fi
|
||||
ynh_app_setting_set "$app" is_public "$is_public"
|
||||
|
||||
# Save the port used if not present
|
||||
if ! [[ "$port" ]]; then
|
||||
port=8065
|
||||
ynh_app_setting_set "$app" port "$port"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
|
@ -107,7 +115,7 @@ ynh_add_nginx_config
|
|||
# SYSTEMD CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_add_systemd_config
|
||||
mattermost_add_systemd_config
|
||||
|
||||
#=================================================
|
||||
# ADVERTISE SERVICE IN ADMIN PANEL
|
||||
|
|
Loading…
Add table
Reference in a new issue