1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mattermost_ynh.git synced 2024-09-03 19:36:29 +02:00

Merge pull request #89 from YunoHost-Apps/more-package-checks

Support multi-instances
This commit is contained in:
Pierre de La Morinerie 2018-01-31 11:53:41 +05:30 committed by GitHub
commit 4f3040a486
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 124 additions and 65 deletions

View file

@ -2,20 +2,22 @@
; Manifest ; Manifest
domain="ynhtests.local" (DOMAIN) domain="ynhtests.local" (DOMAIN)
path="" (PATH) path="" (PATH)
user="admin" (USER)
language="fr" language="fr"
is_public=1 (PUBLIC|public=1|private=0) is_public=1 (PUBLIC|public=1|private=0)
password="alpine" (PASSWORD) password="alpine"
; Checks ; Checks
pkg_linter=1 pkg_linter=1
setup_root=1 setup_root=1
setup_private=0 setup_private=1
setup_public=1 setup_public=1
upgrade=1 upgrade=1
backup_restore=1 backup_restore=1
multi_instance=0 multi_instance=1
port_already_use=0 (XXXX) port_already_use=1 (8085)
# Checks not supported yet
change_url=0 change_url=0
# Tests not applicable # Checks not applicable
setup_sub_dir=0 setup_sub_dir=0
setup_nourl=0 setup_nourl=0
incorrect_path=0 incorrect_path=0

View file

@ -12,7 +12,7 @@ location ~ /api/v[0-9]+/(users/)?websocket$ {
proxy_buffers 256 16k; proxy_buffers 256 16k;
proxy_buffer_size 16k; proxy_buffer_size 16k;
proxy_read_timeout 600s; proxy_read_timeout 600s;
proxy_pass http://127.0.0.1:8065; proxy_pass http://127.0.0.1:__PORT__;
} }
location / { location / {
@ -33,7 +33,7 @@ location / {
#proxy_cache_min_uses 2; #proxy_cache_min_uses 2;
#proxy_cache_use_stale timeout; #proxy_cache_use_stale timeout;
#proxy_cache_lock on; #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 # Yunohost addition: redirect HTTP to HTTPS
if ($scheme = http) { if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent; rewrite ^ https://$server_name$request_uri? permanent;

View file

@ -12,7 +12,7 @@ ExecStart=__FINALPATH__/bin/platform
# #
# TODO: improve mattermost to send a STARTED notification, and # TODO: improve mattermost to send a STARTED notification, and
# switch the service to 'Type=notify' instead. # 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 Restart=always
RestartSec=10 RestartSec=10
WorkingDirectory=__FINALPATH__ WorkingDirectory=__FINALPATH__

View file

@ -13,7 +13,7 @@
"name": "pmorinerie", "name": "pmorinerie",
"email": "kemenaran@gmail.com" "email": "kemenaran@gmail.com"
}, },
"multi_instance": false, "multi_instance": true,
"services": [ "services": [
"nginx" "nginx"
], ],
@ -32,13 +32,13 @@
"example": "domain.org" "example": "domain.org"
}, },
{ {
"name": "public_site", "name": "is_public",
"type": "boolean",
"ask": { "ask": {
"en": "Can guest users access this chat?", "en": "Can guest users access this chat?",
"fr": "Les utilisateurs non-enregistrés peuvent-ils accéder à ce chat ?" "fr": "Les utilisateurs non-enregistrés peuvent-ils accéder à ce chat ?"
}, },
"choices": ["Yes", "No"], "default": true
"default": "Yes"
}, },
{ {
"name": "analytics", "name": "analytics",

17
scripts/_common.sh Normal file
View 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"
}

View file

@ -6,6 +6,7 @@
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -21,7 +22,7 @@ ynh_abort_if_errors
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$YNH_APP_ARG_DOMAIN domain=$YNH_APP_ARG_DOMAIN
is_public=$YNH_APP_ARG_PUBLIC_SITE is_public=$YNH_APP_ARG_IS_PUBLIC
analytics=$YNH_APP_ARG_ANALYTICS analytics=$YNH_APP_ARG_ANALYTICS
path_url="/" path_url="/"
@ -55,15 +56,28 @@ then
script_die "Mattermost requires MySQL 5.6 or higher, or MariaDB 10 or higher." script_die "Mattermost requires MySQL 5.6 or higher, or MariaDB 10 or higher."
fi fi
#=================================================
# FIND AN AVAILABLE PATH
#=================================================
# Normalize the url path syntax # Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url) path_url=$(ynh_normalize_url_path $path_url)
# Check web path availability # Check web path availability
ynh_webpath_available $domain $path_url ynh_webpath_available "$domain" "$path_url"
# Register (book) web path # Register (book) web path
ynh_webpath_register $app $domain $path_url ynh_webpath_register "$app" "$domain" "$path_url"
# Store setting # Store setting
ynh_app_setting_set "$app" domain "$domain" 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 # SET UP INSTALLATION VARIABLES
#================================================= #=================================================
@ -77,19 +91,20 @@ logs_path="/var/log/$app"
# CREATE A MYSQL DATABASE # CREATE A MYSQL DATABASE
#================================================= #=================================================
db_name="mattermost" db_name="$app"
db_user="mmuser" db_user="mmuser"
db_password=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p') db_password=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p')
ynh_mysql_create_db $db_name $db_user $db_password ynh_mysql_create_db "$db_name" "$db_user" "$db_password"
ynh_app_setting_set mattermost mysqlpwd "$db_password" ynh_app_setting_set "$app" mysqlpwd "$db_password"
#================================================= #=================================================
# CREATE USER FOR EMAIL NOTIFICATIONS # CREATE USER FOR EMAIL NOTIFICATIONS
#================================================= #=================================================
smtp_password=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p') mattermost_user="$app"
sudo useradd -M --shell /bin/false -p $(openssl passwd -1 "$smtp_password") "mattermost" mattermost_user_password=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p')
ynh_app_setting_set mattermost smtppwd "$smtp_password" sudo useradd -M --shell /bin/false -p $(openssl passwd -1 "$mattermost_user_password") "$mattermost_user"
ynh_app_setting_set "$app" smtppwd "$mattermost_user_password"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
@ -107,6 +122,7 @@ sudo mkdir -p "$logs_path"
# Configure Service Settings # Configure Service Settings
sudo sed -i "s|\"SiteURL\": \"\"|\"SiteURL\": \"https://${domain}${path_url}\"|g" $final_path/config/config.json 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 # Configure the database connection
db_connection_url="${db_user}:${db_password}@tcp(127.0.0.1:3306)/${db_name}?charset=utf8mb4,utf8" 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 sudo sed -i "s|\"DataSource\": \".*\"|\"DataSource\": \"${db_connection_url}\"|g" $final_path/config/config.json
@ -116,8 +132,8 @@ sudo sed -i "s|\"Directory\": \"./data/\"|\"Directory\": \"${data_path}/\"|g"
sudo sed -i "s|\"SendEmailNotifications\": false|\"SendEmailNotifications\": true|g" $final_path/config/config.json sudo sed -i "s|\"SendEmailNotifications\": false|\"SendEmailNotifications\": true|g" $final_path/config/config.json
sudo sed -i "s|\"FeedbackName\": \"\"|\"FeedbackName\": \"Mattermost notification\"|g" $final_path/config/config.json sudo sed -i "s|\"FeedbackName\": \"\"|\"FeedbackName\": \"Mattermost notification\"|g" $final_path/config/config.json
sudo sed -i "s|\"FeedbackEmail\": \"\"|\"FeedbackEmail\": \"no-reply@${domain}\"|g" $final_path/config/config.json sudo sed -i "s|\"FeedbackEmail\": \"\"|\"FeedbackEmail\": \"no-reply@${domain}\"|g" $final_path/config/config.json
sudo sed -i "s|\"SMTPUsername\": \"\"|\"SMTPUsername\": \"mattermost\"|g" $final_path/config/config.json sudo sed -i "s|\"SMTPUsername\": \"\"|\"SMTPUsername\": \"${mattermost_user}\"|g" $final_path/config/config.json
sudo sed -i "s|\"SMTPPassword\": \"\"|\"SMTPPassword\": \"${smtp_password}\"|g" $final_path/config/config.json sudo sed -i "s|\"SMTPPassword\": \"\"|\"SMTPPassword\": \"${mattermost_user_password}\"|g" $final_path/config/config.json
sudo sed -i "s|\"SMTPServer\": \"\"|\"SMTPServer\": \"localhost\"|g" $final_path/config/config.json sudo sed -i "s|\"SMTPServer\": \"\"|\"SMTPServer\": \"localhost\"|g" $final_path/config/config.json
sudo sed -i "s|\"SMTPPort\": \"\"|\"SMTPPort\": \"25\"|g" $final_path/config/config.json sudo sed -i "s|\"SMTPPort\": \"\"|\"SMTPPort\": \"25\"|g" $final_path/config/config.json
# Disable Mattermost debug console by default # Disable Mattermost debug console by default
@ -134,23 +150,21 @@ ynh_app_setting_set "$app" analytics "$analytics"
# SECURE FILES AND DIRECTORIES # SECURE FILES AND DIRECTORIES
#================================================= #=================================================
sudo chown -R mattermost:www-data "$final_path" sudo chown -R "$mattermost_user:www-data" "$final_path"
sudo chown -R mattermost:www-data "$data_path" sudo chown -R "$mattermost_user:www-data" "$data_path"
sudo chown -R mattermost:adm "$logs_path" sudo chown -R "$mattermost_user:adm" "$logs_path"
#================================================= #=================================================
# NGINX CONFIGURATION # NGINX CONFIGURATION
#================================================= #=================================================
# Copy conf/nginx.conf to the correct location
ynh_add_nginx_config ynh_add_nginx_config
#================================================= #=================================================
# SYSTEMD CONFIGURATION # SYSTEMD CONFIGURATION
#================================================= #=================================================
# Create a dedicated systemd config mattermost_add_systemd_config
ynh_add_systemd_config
#================================================= #=================================================
# ADVERTISE SERVICE IN ADMIN PANEL # ADVERTISE SERVICE IN ADMIN PANEL
@ -163,11 +177,11 @@ sudo yunohost service add "$app" --log "$logs_path/mattermost.log"
#================================================= #=================================================
ynh_app_setting_set "$app" is_public "$is_public" ynh_app_setting_set "$app" is_public "$is_public"
if [ "$is_public" = "Yes" ];
then if [[ $is_public == "1" ]]; then
# Make the app accessible to the public
ynh_app_setting_set "$app" unprotected_uris "/" ynh_app_setting_set "$app" unprotected_uris "/"
fi fi
sudo yunohost app ssowatconf
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
@ -179,4 +193,4 @@ sudo systemctl reload nginx
# START SERVER # START SERVER
#================================================= #=================================================
sudo systemctl start mattermost sudo systemctl start "$app"

View file

@ -14,9 +14,10 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get mattermost domain) domain=$(ynh_app_setting_get $app domain)
db_name="mattermost" db_name="$app"
db_user="mmuser" db_user="mmuser"
mattermost_user="$app"
final_path="/var/www/$app" final_path="/var/www/$app"
data_path="/home/yunohost.app/$app" data_path="/home/yunohost.app/$app"
logs_path="/var/log/$app" logs_path="/var/log/$app"
@ -76,4 +77,4 @@ sudo rm -rf "$logs_path"
# REMOVE DEDICATED USER # REMOVE DEDICATED USER
#================================================= #=================================================
ynh_system_user_delete "$app" ynh_system_user_delete "$mattermost_user"

View file

@ -27,6 +27,7 @@ data_path="/home/yunohost.app/$app"
logs_path="/var/log/$app" logs_path="/var/log/$app"
db_name="$app" db_name="$app"
db_user="mmuser" db_user="mmuser"
mattermost_user="$app"
#================================================= #=================================================
# CHECK IF THE APP CAN BE RESTORED # CHECK IF THE APP CAN BE RESTORED
@ -62,18 +63,18 @@ ynh_restore_file "$data_path"
#================================================= #=================================================
db_pwd=$(ynh_app_setting_get $app mysqlpwd) db_pwd=$(ynh_app_setting_get $app mysqlpwd)
ynh_mysql_setup_db $db_user $db_name $db_pwd ynh_mysql_setup_db "$db_user" "$db_name" "$db_pwd"
ynh_mysql_connect_as $db_user $db_pwd $db_name < ./db.sql ynh_mysql_connect_as "$db_user" "$db_pwd" "$db_name" < ./db.sql
#================================================= #=================================================
# RECREATE THE DEDICATED USER # RECREATE THE DEDICATED USER
#================================================= #=================================================
# Create the dedicated user (if not existing) # Create the dedicated user (if not existing)
smtp_user="$app" mattermost_user="$app"
if ! ynh_system_user_exists "$smtp_user"; then if ! ynh_system_user_exists "$mattermost_user"; then
smtp_password=$(ynh_app_setting_get $app smtp_password) mattermost_user_password=$(ynh_app_setting_get $app smtppwd)
useradd -M --shell /bin/false -p $(openssl passwd -1 "$smtp_password") "$smtp_user" useradd -M --shell /bin/false -p $(openssl passwd -1 "$mattermost_user_password") "$mattermost_user"
fi fi
#================================================= #=================================================
@ -81,21 +82,24 @@ fi
#================================================= #=================================================
# Restore permissions on app files # Restore permissions on app files
sudo chown -R mattermost:www-data "$final_path" sudo chown -R "$mattermost_user:www-data" "$final_path"
mkdir -p "$data_path" mkdir -p "$data_path"
sudo chown -R mattermost:www-data "$data_path" sudo chown -R "$mattermost_user:www-data" "$data_path"
mkdir -p "$logs_path" mkdir -p "$logs_path"
sudo chown -R mattermost:adm "$logs_path" sudo chown -R "$mattermost_user:adm" "$logs_path"
#================================================= #=================================================
# RESTORE SSOWAT # RESTORE SSOWAT
#================================================= #=================================================
if [ "$is_public" = "Yes" ]; if [[ $is_public == "1" ]]; then
then # Make the app accessible to the public
ynh_app_setting_set "$app" unprotected_uris "/" ynh_app_setting_set "$app" unprotected_uris "/"
else
# Remove the public access
ynh_app_setting_delete "$app" skipped_uris
fi fi
#================================================= #=================================================

View file

@ -6,6 +6,7 @@
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
@ -20,8 +21,10 @@ ynh_abort_if_errors
#================================================= #=================================================
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get mattermost domain) domain=$(ynh_app_setting_get $app domain)
is_public=$(ynh_app_setting_get mattermost is_public) is_public=$(ynh_app_setting_get $app is_public)
port=$(ynh_app_setting_get $app port)
mattermost_user="$app"
root_path="$(pwd)/.." root_path="$(pwd)/.."
final_path="/var/www/$app" final_path="/var/www/$app"
@ -57,7 +60,7 @@ if $(sudo systemctl -q is-active "$app"); then
sudo systemctl stop "$app" sudo systemctl stop "$app"
fi 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 if [ -f "/etc/supervisor/conf.d/${app}.conf" ]; then
sudo supervisorctl stop "$app" sudo supervisorctl stop "$app"
sudo rm -f "/etc/supervisor/conf.d/${app}.conf" sudo rm -f "/etc/supervisor/conf.d/${app}.conf"
@ -72,6 +75,24 @@ backup_config_file="/tmp/config.json"
sudo cp -f "$config_file" "$backup_config_file" sudo cp -f "$config_file" "$backup_config_file"
#=================================================
# MIGRATE SETTINGS FROM PREVIOUS VERSIONS
#=================================================
# Convert is_public from "Yes"/"No" to 1 / 0
if [[ $is_public == "Yes" ]]; then
is_public=1
elif [[ $is_public == "No" ]]; then
is_public=0
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 # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
@ -95,7 +116,7 @@ ynh_add_nginx_config
# SYSTEMD CONFIGURATION # SYSTEMD CONFIGURATION
#================================================= #=================================================
ynh_add_systemd_config mattermost_add_systemd_config
#================================================= #=================================================
# ADVERTISE SERVICE IN ADMIN PANEL # ADVERTISE SERVICE IN ADMIN PANEL
@ -123,9 +144,9 @@ fi
# RESTORE FILE PERMISSIONS # RESTORE FILE PERMISSIONS
#================================================= #=================================================
sudo chown -R mattermost:www-data "$final_path" sudo chown -R "$mattermost_user:www-data" "$final_path"
sudo chown -R mattermost:www-data "$data_path" sudo chown -R "$mattermost_user:www-data" "$data_path"
sudo chown -R mattermost:adm "$logs_path" sudo chown -R "$mattermost_user:adm" "$logs_path"
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX